Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "TypeLocBuilder.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 24 | #include "clang/AST/Stmt.h" |
| 25 | #include "clang/AST/StmtCXX.h" |
| 26 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/StmtOpenMP.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Designator.h" |
| 30 | #include "clang/Sema/Lookup.h" |
| 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/ParsedTemplate.h" |
| 33 | #include "clang/Sema/ScopeInfo.h" |
| 34 | #include "clang/Sema/SemaDiagnostic.h" |
| 35 | #include "clang/Sema/SemaInternal.h" |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/ArrayRef.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 38 | #include <algorithm> |
| 39 | |
| 40 | namespace clang { |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 41 | using namespace sema; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 43 | /// \brief A semantic tree transformation that allows one to transform one |
| 44 | /// abstract syntax tree into another. |
| 45 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 46 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 47 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 48 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// instantiation is implemented as a tree transformation where the |
| 50 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 51 | /// template arguments for their corresponding template parameters; a similar |
| 52 | /// transformation is performed for non-type template parameters and |
| 53 | /// template template parameters. |
| 54 | /// |
| 55 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 57 | /// override any of the transformation or rebuild operators by providing an |
| 58 | /// operation with the same signature as the default implementation. The |
| 59 | /// overridding function should not be virtual. |
| 60 | /// |
| 61 | /// Semantic tree transformations are split into two stages, either of which |
| 62 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 63 | /// or the parts of an AST node using the various transformation functions, |
| 64 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 65 | /// node of the appropriate kind from the pieces. The default transformation |
| 66 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 67 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 68 | /// were changed by the transformation, invokes the rebuild operation to create |
| 69 | /// a new AST node. |
| 70 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 72 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 9151c11 | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 73 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 75 | /// new implementations. |
| 76 | /// |
| 77 | /// For more fine-grained transformations, subclasses can replace any of the |
| 78 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 79 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 80 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 83 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 84 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 85 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 86 | /// be able to use more efficient rebuild steps. |
| 87 | /// |
| 88 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 90 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 91 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 92 | /// default locations and entity names used for type-checking |
| 93 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 94 | template<typename Derived> |
| 95 | class TreeTransform { |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 96 | /// \brief Private RAII object that helps us forget and then re-remember |
| 97 | /// the template argument corresponding to a partially-substituted parameter |
| 98 | /// pack. |
| 99 | class ForgetPartiallySubstitutedPackRAII { |
| 100 | Derived &Self; |
| 101 | TemplateArgument Old; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 103 | public: |
| 104 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 105 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 106 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 108 | ~ForgetPartiallySubstitutedPackRAII() { |
| 109 | Self.RememberPartiallySubstitutedPack(Old); |
| 110 | } |
| 111 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | protected: |
| 114 | Sema &SemaRef; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 116 | /// \brief The set of local declarations that have been transformed, for |
| 117 | /// cases where we are forced to build new declarations within the transformer |
| 118 | /// rather than in the subclass (e.g., lambda closure types). |
| 119 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 120 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | public: |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 123 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 125 | /// \brief Retrieves a reference to the derived class. |
| 126 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 127 | |
| 128 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | const Derived &getDerived() const { |
| 130 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 131 | } |
| 132 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 133 | static inline ExprResult Owned(Expr *E) { return E; } |
| 134 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 136 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 137 | /// this tree transform. |
| 138 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 140 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 141 | /// if none of the children have changed. |
| 142 | /// |
| 143 | /// Subclasses may override this function to specify when the transformation |
| 144 | /// should rebuild all AST nodes. |
| 145 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 147 | /// \brief Returns the location of the entity being transformed, if that |
| 148 | /// information was not available elsewhere in the AST. |
| 149 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 151 | /// provide an alternative implementation that provides better location |
| 152 | /// information. |
| 153 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 155 | /// \brief Returns the name of the entity being transformed, if that |
| 156 | /// information was not available elsewhere in the AST. |
| 157 | /// |
| 158 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 159 | /// implementation with a more precise name. |
| 160 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 161 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 162 | /// \brief Sets the "base" location and entity when that |
| 163 | /// information is known based on another transformation. |
| 164 | /// |
| 165 | /// By default, the source location and entity are ignored. Subclasses can |
| 166 | /// override this function to provide a customized implementation. |
| 167 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 169 | /// \brief RAII object that temporarily sets the base location and entity |
| 170 | /// used for reporting diagnostics in types. |
| 171 | class TemporaryBase { |
| 172 | TreeTransform &Self; |
| 173 | SourceLocation OldLocation; |
| 174 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 176 | public: |
| 177 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 179 | OldLocation = Self.getDerived().getBaseLocation(); |
| 180 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 181 | |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 182 | if (Location.isValid()) |
| 183 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 186 | ~TemporaryBase() { |
| 187 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 188 | } |
| 189 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 190 | |
| 191 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// transformed. |
| 193 | /// |
| 194 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 196 | /// not change. For example, template instantiation need not traverse |
| 197 | /// non-dependent types. |
| 198 | bool AlreadyTransformed(QualType T) { |
| 199 | return T.isNull(); |
| 200 | } |
| 201 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 202 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 203 | /// because it is a default argument. |
| 204 | /// |
| 205 | /// Subclasses can provide an alternative implementation of this routine to |
| 206 | /// determine which kinds of call arguments get dropped. By default, |
| 207 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 208 | bool DropCallArgument(Expr *E) { |
| 209 | return E->isDefaultArgument(); |
| 210 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 212 | /// \brief Determine whether we should expand a pack expansion with the |
| 213 | /// given set of parameter packs into separate arguments by repeatedly |
| 214 | /// transforming the pattern. |
| 215 | /// |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 216 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 217 | /// Subclasses can override this routine to provide different behavior. |
| 218 | /// |
| 219 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 220 | /// pack expansion. |
| 221 | /// |
| 222 | /// \param PatternRange The source range that covers the entire pattern of |
| 223 | /// the pack expansion. |
| 224 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 225 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 226 | /// pattern. |
| 227 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 228 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 229 | /// expand the corresponding pack expansions into separate arguments. When |
| 230 | /// set, \c NumExpansions must also be set. |
| 231 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 232 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 233 | /// pack expansion after all of the expanded arguments. This is used |
| 234 | /// when extending explicitly-specified template argument packs per |
| 235 | /// C++0x [temp.arg.explicit]p9. |
| 236 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 237 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 238 | /// the expanded form of the corresponding pack expansion. This is both an |
| 239 | /// input and an output parameter, which can be set by the caller if the |
| 240 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 241 | /// and will be set by the callee when the number of expansions is known. |
| 242 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 243 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 244 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 245 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 246 | /// are to be instantiated with arguments of different lengths), false |
| 247 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 248 | /// must be set. |
| 249 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 250 | SourceRange PatternRange, |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 251 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 253 | bool &RetainExpansion, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 254 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 255 | ShouldExpand = false; |
| 256 | return false; |
| 257 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 258 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 259 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 260 | /// when performing an instantiation that must preserve the parameter pack |
| 261 | /// use. |
| 262 | /// |
| 263 | /// This routine is meant to be overridden by the template instantiator. |
| 264 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 265 | return TemplateArgument(); |
| 266 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 267 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 268 | /// \brief "Remember" the partially-substituted pack template argument |
| 269 | /// after performing an instantiation that must preserve the parameter pack |
| 270 | /// use. |
| 271 | /// |
| 272 | /// This routine is meant to be overridden by the template instantiator. |
| 273 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 274 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 275 | /// \brief Note to the derived class when a function parameter pack is |
| 276 | /// being expanded. |
| 277 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transforms the given type into another type. |
| 280 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 281 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 282 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 283 | /// function. This is expensive, but we don't mind, because |
| 284 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 285 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 286 | /// |
| 287 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 288 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 290 | /// \brief Transforms the given type-with-location into a new |
| 291 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 292 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 293 | /// By default, this routine transforms a type by delegating to the |
| 294 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 295 | /// may override this function (to take over all type |
| 296 | /// transformations) or some set of the TransformXXXType functions |
| 297 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 298 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 299 | |
| 300 | /// \brief Transform the given type-with-location into a new |
| 301 | /// type, collecting location information in the given builder |
| 302 | /// as necessary. |
| 303 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 304 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 306 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 307 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 309 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 310 | /// statement or the TransformExpr() function to transform an expression. |
| 311 | /// Subclasses may override this function to transform statements using some |
| 312 | /// other mechanism. |
| 313 | /// |
| 314 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 315 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 316 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 317 | /// \brief Transform the given statement. |
| 318 | /// |
| 319 | /// By default, this routine transforms a statement by delegating to the |
| 320 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 321 | /// of clause. Subclasses may override this function to transform statements |
| 322 | /// using some other mechanism. |
| 323 | /// |
| 324 | /// \returns the transformed OpenMP clause. |
| 325 | OMPClause *TransformOMPClause(OMPClause *S); |
| 326 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 327 | /// \brief Transform the given expression. |
| 328 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 329 | /// By default, this routine transforms an expression by delegating to the |
| 330 | /// appropriate TransformXXXExpr function to build a new expression. |
| 331 | /// Subclasses may override this function to transform expressions using some |
| 332 | /// other mechanism. |
| 333 | /// |
| 334 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 335 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 336 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 337 | /// \brief Transform the given initializer. |
| 338 | /// |
| 339 | /// By default, this routine transforms an initializer by stripping off the |
| 340 | /// semantic nodes added by initialization, then passing the result to |
| 341 | /// TransformExpr or TransformExprs. |
| 342 | /// |
| 343 | /// \returns the transformed initializer. |
| 344 | ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit); |
| 345 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 346 | /// \brief Transform the given list of expressions. |
| 347 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 348 | /// This routine transforms a list of expressions by invoking |
| 349 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 350 | /// support for variadic templates by expanding any pack expansions (if the |
| 351 | /// derived class permits such expansion) along the way. When pack expansions |
| 352 | /// are present, the number of outputs may not equal the number of inputs. |
| 353 | /// |
| 354 | /// \param Inputs The set of expressions to be transformed. |
| 355 | /// |
| 356 | /// \param NumInputs The number of expressions in \c Inputs. |
| 357 | /// |
| 358 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 359 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 360 | /// be. |
| 361 | /// |
| 362 | /// \param Outputs The transformed input expressions will be added to this |
| 363 | /// vector. |
| 364 | /// |
| 365 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 366 | /// due to transformation. |
| 367 | /// |
| 368 | /// \returns true if an error occurred, false otherwise. |
| 369 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 370 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 371 | bool *ArgChanged = 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 373 | /// \brief Transform the given declaration, which is referenced from a type |
| 374 | /// or expression. |
| 375 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 376 | /// By default, acts as the identity function on declarations, unless the |
| 377 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 378 | /// may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 379 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 380 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 381 | = TransformedLocalDecls.find(D); |
| 382 | if (Known != TransformedLocalDecls.end()) |
| 383 | return Known->second; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 384 | |
| 385 | return D; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 386 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 387 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 388 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 389 | /// place them on the new declaration. |
| 390 | /// |
| 391 | /// By default, this operation does nothing. Subclasses may override this |
| 392 | /// behavior to transform attributes. |
| 393 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 395 | /// \brief Note that a local declaration has been transformed by this |
| 396 | /// transformer. |
| 397 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 398 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 399 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 400 | /// the transformer itself has to transform the declarations. This routine |
| 401 | /// can be overridden by a subclass that keeps track of such mappings. |
| 402 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 403 | TransformedLocalDecls[Old] = New; |
| 404 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 405 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 406 | /// \brief Transform the definition of the given declaration. |
| 407 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 409 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 410 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 411 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 414 | /// \brief Transform the given declaration, which was the first part of a |
| 415 | /// nested-name-specifier in a member access expression. |
| 416 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 417 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 418 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 419 | /// the \c T in \c x->T::member |
| 420 | /// |
| 421 | /// By default, invokes TransformDecl() to transform the declaration. |
| 422 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 423 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 424 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 425 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 426 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 427 | /// \brief Transform the given nested-name-specifier with source-location |
| 428 | /// information. |
| 429 | /// |
| 430 | /// By default, transforms all of the types and declarations within the |
| 431 | /// nested-name-specifier. Subclasses may override this function to provide |
| 432 | /// alternate behavior. |
| 433 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 434 | NestedNameSpecifierLoc NNS, |
| 435 | QualType ObjectType = QualType(), |
| 436 | NamedDecl *FirstQualifierInScope = 0); |
| 437 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 438 | /// \brief Transform the given declaration name. |
| 439 | /// |
| 440 | /// By default, transforms the types of conversion function, constructor, |
| 441 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 442 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 443 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 444 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 445 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 449 | /// \param SS The nested-name-specifier that qualifies the template |
| 450 | /// name. This nested-name-specifier must already have been transformed. |
| 451 | /// |
| 452 | /// \param Name The template name to transform. |
| 453 | /// |
| 454 | /// \param NameLoc The source location of the template name. |
| 455 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 456 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 457 | /// access expression, this is the type of the object whose member template |
| 458 | /// is being referenced. |
| 459 | /// |
| 460 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 461 | /// also refers to a name within the current (lexical) scope, this is the |
| 462 | /// declaration it refers to. |
| 463 | /// |
| 464 | /// By default, transforms the template name by transforming the declarations |
| 465 | /// and nested-name-specifiers that occur within the template name. |
| 466 | /// Subclasses may override this function to provide alternate behavior. |
| 467 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 468 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 469 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 470 | QualType ObjectType = QualType(), |
| 471 | NamedDecl *FirstQualifierInScope = 0); |
| 472 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 473 | /// \brief Transform the given template argument. |
| 474 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | /// By default, this operation transforms the type, expression, or |
| 476 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 477 | /// new template argument from the transformed result. Subclasses may |
| 478 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 479 | /// |
| 480 | /// Returns true if there was an error. |
| 481 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 482 | TemplateArgumentLoc &Output); |
| 483 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 484 | /// \brief Transform the given set of template arguments. |
| 485 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 486 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 487 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 488 | /// the transformed arguments to the output list. |
| 489 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 490 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 491 | /// a convenience function. Subclasses that wish to override this behavior |
| 492 | /// should override the iterator-based member template version. |
| 493 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 494 | /// \param Inputs The set of template arguments to be transformed. |
| 495 | /// |
| 496 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 497 | /// |
| 498 | /// \param Outputs The set of transformed template arguments output by this |
| 499 | /// routine. |
| 500 | /// |
| 501 | /// Returns true if an error occurred. |
| 502 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 503 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 504 | TemplateArgumentListInfo &Outputs) { |
| 505 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 506 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 507 | |
| 508 | /// \brief Transform the given set of template arguments. |
| 509 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 510 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 511 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 512 | /// the transformed arguments to the output list. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 513 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 514 | /// \param First An iterator to the first template argument. |
| 515 | /// |
| 516 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 517 | /// |
| 518 | /// \param Outputs The set of transformed template arguments output by this |
| 519 | /// routine. |
| 520 | /// |
| 521 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 522 | template<typename InputIterator> |
| 523 | bool TransformTemplateArguments(InputIterator First, |
| 524 | InputIterator Last, |
| 525 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 526 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 527 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 528 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 529 | TemplateArgumentLoc &ArgLoc); |
| 530 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 531 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 532 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 533 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 534 | getDerived().getBaseLocation()); |
| 535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 537 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 538 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 539 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 540 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 541 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 542 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 543 | FunctionProtoTypeLoc TL, |
| 544 | CXXRecordDecl *ThisContext, |
| 545 | unsigned ThisTypeQuals); |
| 546 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 547 | StmtResult |
| 548 | TransformSEHHandler(Stmt *Handler); |
| 549 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 550 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 551 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 552 | TemplateSpecializationTypeLoc TL, |
| 553 | TemplateName Template); |
| 554 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 555 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 556 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 557 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 558 | TemplateName Template, |
| 559 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 560 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 561 | QualType |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 562 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 563 | DependentTemplateSpecializationTypeLoc TL, |
| 564 | NestedNameSpecifierLoc QualifierLoc); |
| 565 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 566 | /// \brief Transforms the parameters of a function type into the |
| 567 | /// given vectors. |
| 568 | /// |
| 569 | /// The result vectors should be kept in sync; null entries in the |
| 570 | /// variables vector are acceptable. |
| 571 | /// |
| 572 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 573 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 574 | ParmVarDecl **Params, unsigned NumParams, |
| 575 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 576 | SmallVectorImpl<QualType> &PTypes, |
| 577 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 578 | |
| 579 | /// \brief Transforms a single function-type parameter. Return null |
| 580 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 581 | /// |
| 582 | /// \param indexAdjustment - A number to add to the parameter's |
| 583 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 584 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 585 | int indexAdjustment, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 586 | Optional<unsigned> NumExpansions, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 587 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 588 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 589 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 590 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 591 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 592 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 594 | /// \brief Transform the captures and body of a lambda expression. |
| 595 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); |
| 596 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 597 | ExprResult TransformAddressOfOperand(Expr *E); |
| 598 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 599 | bool IsAddressOfOperand); |
| 600 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 601 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 602 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 603 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 604 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 605 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 606 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 608 | #define OPENMP_CLAUSE(Name, Class) \ |
| 609 | OMPClause *Transform ## Class(Class *S); |
| 610 | #include "clang/Basic/OpenMPKinds.def" |
| 611 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 612 | /// \brief Build a new pointer type given its pointee type. |
| 613 | /// |
| 614 | /// By default, performs semantic analysis when building the pointer type. |
| 615 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 616 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 617 | |
| 618 | /// \brief Build a new block pointer type given its pointee type. |
| 619 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 621 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 622 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 623 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 624 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 625 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 626 | /// By default, performs semantic analysis when building the |
| 627 | /// reference type. Subclasses may override this routine to provide |
| 628 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 629 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 630 | /// \param LValue whether the type was written with an lvalue sigil |
| 631 | /// or an rvalue sigil. |
| 632 | QualType RebuildReferenceType(QualType ReferentType, |
| 633 | bool LValue, |
| 634 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 636 | /// \brief Build a new member pointer type given the pointee type and the |
| 637 | /// class type it refers into. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the member pointer |
| 640 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 641 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 642 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | /// \brief Build a new array type given the element type, size |
| 645 | /// modifier, size of the array (if known), size expression, and index type |
| 646 | /// qualifiers. |
| 647 | /// |
| 648 | /// By default, performs semantic analysis when building the array type. |
| 649 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 651 | QualType RebuildArrayType(QualType ElementType, |
| 652 | ArrayType::ArraySizeModifier SizeMod, |
| 653 | const llvm::APInt *Size, |
| 654 | Expr *SizeExpr, |
| 655 | unsigned IndexTypeQuals, |
| 656 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 658 | /// \brief Build a new constant array type given the element type, size |
| 659 | /// modifier, (known) size of the array, and index type qualifiers. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis when building the array type. |
| 662 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 664 | ArrayType::ArraySizeModifier SizeMod, |
| 665 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 666 | unsigned IndexTypeQuals, |
| 667 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 668 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 669 | /// \brief Build a new incomplete array type given the element type, size |
| 670 | /// modifier, and index type qualifiers. |
| 671 | /// |
| 672 | /// By default, performs semantic analysis when building the array type. |
| 673 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 675 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 676 | unsigned IndexTypeQuals, |
| 677 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 678 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 680 | /// size modifier, size expression, and index type qualifiers. |
| 681 | /// |
| 682 | /// By default, performs semantic analysis when building the array type. |
| 683 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 685 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 686 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 687 | unsigned IndexTypeQuals, |
| 688 | SourceRange BracketsRange); |
| 689 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 691 | /// size modifier, size expression, and index type qualifiers. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis when building the array type. |
| 694 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 696 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 697 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 698 | unsigned IndexTypeQuals, |
| 699 | SourceRange BracketsRange); |
| 700 | |
| 701 | /// \brief Build a new vector type given the element type and |
| 702 | /// number of elements. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis when building the vector type. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 706 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 707 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 709 | /// \brief Build a new extended vector type given the element type and |
| 710 | /// number of elements. |
| 711 | /// |
| 712 | /// By default, performs semantic analysis when building the vector type. |
| 713 | /// Subclasses may override this routine to provide different behavior. |
| 714 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 715 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | |
| 717 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 718 | /// given the element type and number of elements. |
| 719 | /// |
| 720 | /// By default, performs semantic analysis when building the vector type. |
| 721 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 723 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 724 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 726 | /// \brief Build a new function type. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis when building the function type. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
| 730 | QualType RebuildFunctionProtoType(QualType T, |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 731 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 732 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 734 | /// \brief Build a new unprototyped function type. |
| 735 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 736 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 737 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 738 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 739 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 740 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 741 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 742 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 743 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 744 | } |
| 745 | |
| 746 | /// \brief Build a new class/struct/union type. |
| 747 | QualType RebuildRecordType(RecordDecl *Record) { |
| 748 | return SemaRef.Context.getTypeDeclType(Record); |
| 749 | } |
| 750 | |
| 751 | /// \brief Build a new Enum type. |
| 752 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 753 | return SemaRef.Context.getTypeDeclType(Enum); |
| 754 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 755 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 757 | /// |
| 758 | /// By default, performs semantic analysis when building the typeof type. |
| 759 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 760 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 761 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 763 | /// |
| 764 | /// By default, builds a new TypeOfType with the given underlying type. |
| 765 | QualType RebuildTypeOfType(QualType Underlying); |
| 766 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 767 | /// \brief Build a new unary transform type. |
| 768 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 769 | UnaryTransformType::UTTKind UKind, |
| 770 | SourceLocation Loc); |
| 771 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 772 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 773 | /// |
| 774 | /// By default, performs semantic analysis when building the decltype type. |
| 775 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 776 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 778 | /// \brief Build a new C++11 auto type. |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 779 | /// |
| 780 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 781 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 782 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 783 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 784 | // that we'll retry deduction after the transformation. |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 785 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 788 | /// \brief Build a new template specialization type. |
| 789 | /// |
| 790 | /// By default, performs semantic analysis when building the template |
| 791 | /// specialization type. Subclasses may override this routine to provide |
| 792 | /// different behavior. |
| 793 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 794 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 795 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 796 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 797 | /// \brief Build a new parenthesized type. |
| 798 | /// |
| 799 | /// By default, builds a new ParenType type from the inner type. |
| 800 | /// Subclasses may override this routine to provide different behavior. |
| 801 | QualType RebuildParenType(QualType InnerType) { |
| 802 | return SemaRef.Context.getParenType(InnerType); |
| 803 | } |
| 804 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 805 | /// \brief Build a new qualified name type. |
| 806 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 807 | /// By default, builds a new ElaboratedType type from the keyword, |
| 808 | /// the nested-name-specifier and the named type. |
| 809 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 810 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 811 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 812 | NestedNameSpecifierLoc QualifierLoc, |
| 813 | QualType Named) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 814 | return SemaRef.Context.getElaboratedType(Keyword, |
| 815 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 816 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 818 | |
| 819 | /// \brief Build a new typename type that refers to a template-id. |
| 820 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 821 | /// By default, builds a new DependentNameType type from the |
| 822 | /// nested-name-specifier and the given type. Subclasses may override |
| 823 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 824 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 825 | ElaboratedTypeKeyword Keyword, |
| 826 | NestedNameSpecifierLoc QualifierLoc, |
| 827 | const IdentifierInfo *Name, |
| 828 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 829 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 830 | // Rebuild the template name. |
| 831 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 832 | CXXScopeSpec SS; |
| 833 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 834 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 835 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 836 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 837 | if (InstName.isNull()) |
| 838 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 839 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 840 | // If it's still dependent, make a dependent specialization. |
| 841 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 842 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 843 | QualifierLoc.getNestedNameSpecifier(), |
| 844 | Name, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 845 | Args); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 847 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 848 | // specialization. |
| 849 | QualType T = |
| 850 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 851 | if (T.isNull()) return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 853 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 854 | return T; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 855 | |
| 856 | return SemaRef.Context.getElaboratedType(Keyword, |
| 857 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 858 | T); |
| 859 | } |
| 860 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 861 | /// \brief Build a new typename type that refers to an identifier. |
| 862 | /// |
| 863 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 864 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 865 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 866 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 867 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 868 | NestedNameSpecifierLoc QualifierLoc, |
| 869 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 870 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 871 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 872 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 873 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 874 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 875 | // If the name is still dependent, just build a new dependent name type. |
| 876 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 877 | return SemaRef.Context.getDependentNameType(Keyword, |
| 878 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 879 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 882 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 883 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 884 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 885 | |
| 886 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 887 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 888 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 889 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 890 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 891 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 892 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 893 | if (!DC) |
| 894 | return QualType(); |
| 895 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 896 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 897 | return QualType(); |
| 898 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 899 | TagDecl *Tag = 0; |
| 900 | SemaRef.LookupQualifiedName(Result, DC); |
| 901 | switch (Result.getResultKind()) { |
| 902 | case LookupResult::NotFound: |
| 903 | case LookupResult::NotFoundInCurrentInstantiation: |
| 904 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 905 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 906 | case LookupResult::Found: |
| 907 | Tag = Result.getAsSingle<TagDecl>(); |
| 908 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 909 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 910 | case LookupResult::FoundOverloaded: |
| 911 | case LookupResult::FoundUnresolvedValue: |
| 912 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 914 | case LookupResult::Ambiguous: |
| 915 | // Let the LookupResult structure handle ambiguities. |
| 916 | return QualType(); |
| 917 | } |
| 918 | |
| 919 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 920 | // Check where the name exists but isn't a tag type and use that to emit |
| 921 | // better diagnostics. |
| 922 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 923 | SemaRef.LookupQualifiedName(Result, DC); |
| 924 | switch (Result.getResultKind()) { |
| 925 | case LookupResult::Found: |
| 926 | case LookupResult::FoundOverloaded: |
| 927 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 928 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 929 | unsigned Kind = 0; |
| 930 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 931 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 932 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 933 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 934 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 935 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 936 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 937 | default: |
| 938 | // FIXME: Would be nice to highlight just the source range. |
| 939 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 940 | << Kind << Id << DC; |
| 941 | break; |
| 942 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 943 | return QualType(); |
| 944 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 945 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 946 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 947 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 948 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 949 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 950 | return QualType(); |
| 951 | } |
| 952 | |
| 953 | // Build the elaborated-type-specifier type. |
| 954 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 955 | return SemaRef.Context.getElaboratedType(Keyword, |
| 956 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 957 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 958 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 959 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 960 | /// \brief Build a new pack expansion type. |
| 961 | /// |
| 962 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 963 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 964 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 965 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 966 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 967 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 968 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 969 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 972 | /// \brief Build a new atomic type given its value type. |
| 973 | /// |
| 974 | /// By default, performs semantic analysis when building the atomic type. |
| 975 | /// Subclasses may override this routine to provide different behavior. |
| 976 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 977 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 978 | /// \brief Build a new template name given a nested name specifier, a flag |
| 979 | /// indicating whether the "template" keyword was provided, and the template |
| 980 | /// that the template name refers to. |
| 981 | /// |
| 982 | /// By default, builds the new template name directly. Subclasses may override |
| 983 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 984 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 985 | bool TemplateKW, |
| 986 | TemplateDecl *Template); |
| 987 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 988 | /// \brief Build a new template name given a nested name specifier and the |
| 989 | /// name that is referred to as a template. |
| 990 | /// |
| 991 | /// By default, performs semantic analysis to determine whether the name can |
| 992 | /// be resolved to a specific template, then builds the appropriate kind of |
| 993 | /// template name. Subclasses may override this routine to provide different |
| 994 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 995 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 996 | const IdentifierInfo &Name, |
| 997 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 998 | QualType ObjectType, |
| 999 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1001 | /// \brief Build a new template name given a nested name specifier and the |
| 1002 | /// overloaded operator name that is referred to as a template. |
| 1003 | /// |
| 1004 | /// By default, performs semantic analysis to determine whether the name can |
| 1005 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1006 | /// template name. Subclasses may override this routine to provide different |
| 1007 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1008 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1009 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1010 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1011 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1012 | |
| 1013 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1014 | /// and the |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1015 | /// |
| 1016 | /// By default, performs semantic analysis to determine whether the name can |
| 1017 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1018 | /// template name. Subclasses may override this routine to provide different |
| 1019 | /// behavior. |
| 1020 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1021 | const TemplateArgument &ArgPack) { |
| 1022 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1023 | } |
| 1024 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1025 | /// \brief Build a new compound statement. |
| 1026 | /// |
| 1027 | /// By default, performs semantic analysis to build the new statement. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1029 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1030 | MultiStmtArg Statements, |
| 1031 | SourceLocation RBraceLoc, |
| 1032 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1033 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1034 | IsStmtExpr); |
| 1035 | } |
| 1036 | |
| 1037 | /// \brief Build a new case statement. |
| 1038 | /// |
| 1039 | /// By default, performs semantic analysis to build the new statement. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1041 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1042 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1043 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1044 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1045 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1046 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1047 | ColonLoc); |
| 1048 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1050 | /// \brief Attach the body to a new case statement. |
| 1051 | /// |
| 1052 | /// By default, performs semantic analysis to build the new statement. |
| 1053 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1054 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1055 | getSema().ActOnCaseStmtBody(S, Body); |
| 1056 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1058 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | /// \brief Build a new default statement. |
| 1060 | /// |
| 1061 | /// By default, performs semantic analysis to build the new statement. |
| 1062 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1063 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1064 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1065 | Stmt *SubStmt) { |
| 1066 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1067 | /*CurScope=*/0); |
| 1068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1070 | /// \brief Build a new label statement. |
| 1071 | /// |
| 1072 | /// By default, performs semantic analysis to build the new statement. |
| 1073 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1074 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1075 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1076 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1079 | /// \brief Build a new label statement. |
| 1080 | /// |
| 1081 | /// By default, performs semantic analysis to build the new statement. |
| 1082 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1083 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1084 | ArrayRef<const Attr*> Attrs, |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1085 | Stmt *SubStmt) { |
| 1086 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1087 | } |
| 1088 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | /// \brief Build a new "if" statement. |
| 1090 | /// |
| 1091 | /// By default, performs semantic analysis to build the new statement. |
| 1092 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1093 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1094 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1095 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1096 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1097 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1099 | /// \brief Start building a new switch statement. |
| 1100 | /// |
| 1101 | /// By default, performs semantic analysis to build the new statement. |
| 1102 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1103 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1104 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1105 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1106 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1107 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | /// \brief Attach the body to the switch statement. |
| 1110 | /// |
| 1111 | /// By default, performs semantic analysis to build the new statement. |
| 1112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1113 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1114 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1115 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /// \brief Build a new while statement. |
| 1119 | /// |
| 1120 | /// By default, performs semantic analysis to build the new statement. |
| 1121 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1122 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1123 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1124 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, 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 do-while statement. |
| 1128 | /// |
| 1129 | /// By default, performs semantic analysis to build the new statement. |
| 1130 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1131 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1132 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1133 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1134 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1135 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | /// \brief Build a new for statement. |
| 1139 | /// |
| 1140 | /// By default, performs semantic analysis to build the new statement. |
| 1141 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1142 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1143 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1144 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1145 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1146 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1147 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1150 | /// \brief Build a new goto statement. |
| 1151 | /// |
| 1152 | /// By default, performs semantic analysis to build the new statement. |
| 1153 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1154 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1155 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1156 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /// \brief Build a new indirect goto statement. |
| 1160 | /// |
| 1161 | /// By default, performs semantic analysis to build the new statement. |
| 1162 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1163 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1164 | SourceLocation StarLoc, |
| 1165 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1166 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1169 | /// \brief Build a new return statement. |
| 1170 | /// |
| 1171 | /// By default, performs semantic analysis to build the new statement. |
| 1172 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1173 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1174 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1177 | /// \brief Build a new declaration statement. |
| 1178 | /// |
| 1179 | /// By default, performs semantic analysis to build the new statement. |
| 1180 | /// Subclasses may override this routine to provide different behavior. |
Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1181 | StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls, |
| 1182 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1183 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1184 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1187 | /// \brief Build a new inline asm statement. |
| 1188 | /// |
| 1189 | /// By default, performs semantic analysis to build the new statement. |
| 1190 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1191 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1192 | bool IsVolatile, unsigned NumOutputs, |
| 1193 | unsigned NumInputs, IdentifierInfo **Names, |
| 1194 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1195 | Expr *AsmString, MultiExprArg Clobbers, |
| 1196 | SourceLocation RParenLoc) { |
| 1197 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1198 | NumInputs, Names, Constraints, Exprs, |
| 1199 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1200 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1201 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1202 | /// \brief Build a new MS style inline asm statement. |
| 1203 | /// |
| 1204 | /// By default, performs semantic analysis to build the new statement. |
| 1205 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1206 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1207 | ArrayRef<Token> AsmToks, |
| 1208 | StringRef AsmString, |
| 1209 | unsigned NumOutputs, unsigned NumInputs, |
| 1210 | ArrayRef<StringRef> Constraints, |
| 1211 | ArrayRef<StringRef> Clobbers, |
| 1212 | ArrayRef<Expr*> Exprs, |
| 1213 | SourceLocation EndLoc) { |
| 1214 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1215 | NumOutputs, NumInputs, |
| 1216 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1219 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1220 | /// |
| 1221 | /// By default, performs semantic analysis to build the new statement. |
| 1222 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1223 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1224 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1225 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1226 | Stmt *Finally) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1227 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1228 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1231 | /// \brief Rebuild an Objective-C exception declaration. |
| 1232 | /// |
| 1233 | /// By default, performs semantic analysis to build the new declaration. |
| 1234 | /// Subclasses may override this routine to provide different behavior. |
| 1235 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1236 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1237 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1238 | ExceptionDecl->getInnerLocStart(), |
| 1239 | ExceptionDecl->getLocation(), |
| 1240 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +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 Build a new Objective-C \@catch statement. |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +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. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1247 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1248 | SourceLocation RParenLoc, |
| 1249 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1250 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1251 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1252 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1253 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1254 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1255 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1256 | /// |
| 1257 | /// By default, performs semantic analysis to build the new statement. |
| 1258 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1259 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1260 | Stmt *Body) { |
| 1261 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1262 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1263 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1264 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1265 | /// |
| 1266 | /// By default, performs semantic analysis to build the new statement. |
| 1267 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1268 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1269 | Expr *Operand) { |
| 1270 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1271 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1272 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1273 | /// \brief Build a new OpenMP parallel directive. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new statement. |
| 1276 | /// Subclasses may override this routine to provide different behavior. |
| 1277 | StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1278 | Stmt *AStmt, |
| 1279 | SourceLocation StartLoc, |
| 1280 | SourceLocation EndLoc) { |
| 1281 | return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt, |
| 1282 | StartLoc, EndLoc); |
| 1283 | } |
| 1284 | |
| 1285 | /// \brief Build a new OpenMP 'default' clause. |
| 1286 | /// |
| 1287 | /// By default, performs semantic analysis to build the new statement. |
| 1288 | /// Subclasses may override this routine to provide different behavior. |
| 1289 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1290 | SourceLocation KindKwLoc, |
| 1291 | SourceLocation StartLoc, |
| 1292 | SourceLocation LParenLoc, |
| 1293 | SourceLocation EndLoc) { |
| 1294 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1295 | StartLoc, LParenLoc, EndLoc); |
| 1296 | } |
| 1297 | |
| 1298 | /// \brief Build a new OpenMP 'private' clause. |
| 1299 | /// |
| 1300 | /// By default, performs semantic analysis to build the new statement. |
| 1301 | /// Subclasses may override this routine to provide different behavior. |
| 1302 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1303 | SourceLocation StartLoc, |
| 1304 | SourceLocation LParenLoc, |
| 1305 | SourceLocation EndLoc) { |
| 1306 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1307 | EndLoc); |
| 1308 | } |
| 1309 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1310 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1311 | /// |
| 1312 | /// By default, performs semantic analysis to build the new statement. |
| 1313 | /// Subclasses may override this routine to provide different behavior. |
| 1314 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1315 | Expr *object) { |
| 1316 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1317 | } |
| 1318 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1319 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1320 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1321 | /// By default, performs semantic analysis to build the new statement. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1323 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1324 | Expr *Object, Stmt *Body) { |
| 1325 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1326 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1327 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1328 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1329 | /// |
| 1330 | /// By default, performs semantic analysis to build the new statement. |
| 1331 | /// Subclasses may override this routine to provide different behavior. |
| 1332 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1333 | Stmt *Body) { |
| 1334 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1335 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1336 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1337 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1338 | /// |
| 1339 | /// By default, performs semantic analysis to build the new statement. |
| 1340 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1341 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1342 | Stmt *Element, |
| 1343 | Expr *Collection, |
| 1344 | SourceLocation RParenLoc, |
| 1345 | Stmt *Body) { |
Sam Panzer | bc20bbb | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1346 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1347 | Element, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1348 | Collection, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1349 | RParenLoc); |
| 1350 | if (ForEachStmt.isInvalid()) |
| 1351 | return StmtError(); |
| 1352 | |
| 1353 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1354 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1355 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1356 | /// \brief Build a new C++ exception declaration. |
| 1357 | /// |
| 1358 | /// By default, performs semantic analysis to build the new decaration. |
| 1359 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1360 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1361 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1362 | SourceLocation StartLoc, |
| 1363 | SourceLocation IdLoc, |
| 1364 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1365 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1366 | StartLoc, IdLoc, Id); |
| 1367 | if (Var) |
| 1368 | getSema().CurContext->addDecl(Var); |
| 1369 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /// \brief Build a new C++ catch statement. |
| 1373 | /// |
| 1374 | /// By default, performs semantic analysis to build the new statement. |
| 1375 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1376 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1377 | VarDecl *ExceptionDecl, |
| 1378 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1379 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1380 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1383 | /// \brief Build a new C++ try statement. |
| 1384 | /// |
| 1385 | /// By default, performs semantic analysis to build the new statement. |
| 1386 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1387 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1388 | Stmt *TryBlock, |
| 1389 | MultiStmtArg Handlers) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1390 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1393 | /// \brief Build a new C++0x range-based for statement. |
| 1394 | /// |
| 1395 | /// By default, performs semantic analysis to build the new statement. |
| 1396 | /// Subclasses may override this routine to provide different behavior. |
| 1397 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1398 | SourceLocation ColonLoc, |
| 1399 | Stmt *Range, Stmt *BeginEnd, |
| 1400 | Expr *Cond, Expr *Inc, |
| 1401 | Stmt *LoopVar, |
| 1402 | SourceLocation RParenLoc) { |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1403 | // If we've just learned that the range is actually an Objective-C |
| 1404 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1405 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1406 | if (RangeStmt->isSingleDecl()) { |
| 1407 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1408 | if (RangeVar->isInvalidDecl()) |
| 1409 | return StmtError(); |
| 1410 | |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1411 | Expr *RangeExpr = RangeVar->getInit(); |
| 1412 | if (!RangeExpr->isTypeDependent() && |
| 1413 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1414 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1415 | RParenLoc); |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1420 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | 8b533d9 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1421 | Cond, Inc, LoopVar, RParenLoc, |
| 1422 | Sema::BFRK_Rebuild); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1423 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1424 | |
| 1425 | /// \brief Build a new C++0x range-based for statement. |
| 1426 | /// |
| 1427 | /// By default, performs semantic analysis to build the new statement. |
| 1428 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1429 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1430 | bool IsIfExists, |
| 1431 | NestedNameSpecifierLoc QualifierLoc, |
| 1432 | DeclarationNameInfo NameInfo, |
| 1433 | Stmt *Nested) { |
| 1434 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1435 | QualifierLoc, NameInfo, Nested); |
| 1436 | } |
| 1437 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1438 | /// \brief Attach body to a C++0x range-based for statement. |
| 1439 | /// |
| 1440 | /// By default, performs semantic analysis to finish the new statement. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
| 1442 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1443 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1444 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1445 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1446 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1447 | SourceLocation TryLoc, |
| 1448 | Stmt *TryBlock, |
| 1449 | Stmt *Handler) { |
| 1450 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1451 | } |
| 1452 | |
| 1453 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1454 | Expr *FilterExpr, |
| 1455 | Stmt *Block) { |
| 1456 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1457 | } |
| 1458 | |
| 1459 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1460 | Stmt *Block) { |
| 1461 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1462 | } |
| 1463 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1464 | /// \brief Build a new expression that references a declaration. |
| 1465 | /// |
| 1466 | /// By default, performs semantic analysis to build the new expression. |
| 1467 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1468 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1469 | LookupResult &R, |
| 1470 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1471 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | /// \brief Build a new expression that references a declaration. |
| 1476 | /// |
| 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1479 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1480 | ValueDecl *VD, |
| 1481 | const DeclarationNameInfo &NameInfo, |
| 1482 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1483 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1484 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1485 | |
| 1486 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1487 | |
| 1488 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1490 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1491 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | /// By default, performs semantic analysis to build the new expression. |
| 1494 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1495 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1497 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1500 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1502 | /// By default, performs semantic analysis to build the new expression. |
| 1503 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1504 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1505 | SourceLocation OperatorLoc, |
| 1506 | bool isArrow, |
| 1507 | CXXScopeSpec &SS, |
| 1508 | TypeSourceInfo *ScopeType, |
| 1509 | SourceLocation CCLoc, |
| 1510 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1511 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1515 | /// By default, performs semantic analysis to build the new expression. |
| 1516 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1517 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1518 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1519 | Expr *SubExpr) { |
| 1520 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1522 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1523 | /// \brief Build a new builtin offsetof expression. |
| 1524 | /// |
| 1525 | /// By default, performs semantic analysis to build the new expression. |
| 1526 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1527 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1528 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1529 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1530 | unsigned NumComponents, |
| 1531 | SourceLocation RParenLoc) { |
| 1532 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1533 | NumComponents, RParenLoc); |
| 1534 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1535 | |
| 1536 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1537 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | /// By default, performs semantic analysis to build the new expression. |
| 1540 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1541 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1542 | SourceLocation OpLoc, |
| 1543 | UnaryExprOrTypeTrait ExprKind, |
| 1544 | SourceRange R) { |
| 1545 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1548 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1549 | /// expression argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1551 | /// By default, performs semantic analysis to build the new expression. |
| 1552 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1553 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1554 | UnaryExprOrTypeTrait ExprKind, |
| 1555 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1556 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1557 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1559 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1561 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1562 | } |
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 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1565 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1566 | /// By default, performs semantic analysis to build the new expression. |
| 1567 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1568 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1570 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1572 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1573 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | RBracketLoc); |
| 1575 | } |
| 1576 | |
| 1577 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | /// By default, performs semantic analysis to build the new expression. |
| 1580 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1581 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1583 | SourceLocation RParenLoc, |
| 1584 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1585 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1586 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1590 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | /// By default, performs semantic analysis to build the new expression. |
| 1592 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1593 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1594 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1595 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1596 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1597 | const DeclarationNameInfo &MemberNameInfo, |
| 1598 | ValueDecl *Member, |
| 1599 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1600 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1601 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1602 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1603 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1604 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1605 | // We have a reference to an unnamed field. This is always the |
| 1606 | // base of an anonymous struct/union member access, i.e. the |
| 1607 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1608 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1609 | assert(Member->getType()->isRecordType() && |
| 1610 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1612 | BaseResult = |
| 1613 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1614 | QualifierLoc.getNestedNameSpecifier(), |
| 1615 | FoundDecl, Member); |
| 1616 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1617 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1618 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1619 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1621 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1622 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1623 | cast<FieldDecl>(Member)->getType(), |
| 1624 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1625 | return getSema().Owned(ME); |
| 1626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1628 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1629 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1630 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1631 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1632 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1633 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1634 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1635 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1636 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1637 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1638 | R.resolveKind(); |
| 1639 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1640 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1641 | SS, TemplateKWLoc, |
| 1642 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1643 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | /// \brief Build a new binary operator expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1649 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1650 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1651 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1652 | Expr *LHS, Expr *RHS) { |
| 1653 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | /// By default, performs semantic analysis to build the new expression. |
| 1659 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1660 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1661 | SourceLocation QuestionLoc, |
| 1662 | Expr *LHS, |
| 1663 | SourceLocation ColonLoc, |
| 1664 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1665 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1666 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | /// By default, performs semantic analysis to build the new expression. |
| 1672 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1673 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1674 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1676 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1677 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1678 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | /// By default, performs semantic analysis to build the new expression. |
| 1684 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1685 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1686 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1688 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1689 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1690 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1694 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | /// By default, performs semantic analysis to build the new expression. |
| 1696 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1697 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | SourceLocation OpLoc, |
| 1699 | SourceLocation AccessorLoc, |
| 1700 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1701 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1702 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1703 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1704 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1705 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1706 | SS, SourceLocation(), |
| 1707 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1708 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1709 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | /// By default, performs semantic analysis to build the new expression. |
| 1715 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1716 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1717 | MultiExprArg Inits, |
| 1718 | SourceLocation RBraceLoc, |
| 1719 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1720 | ExprResult Result |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1721 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1722 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1723 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1724 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1725 | // Patch in the result type we were given, which may have been computed |
| 1726 | // when the initial InitListExpr was built. |
| 1727 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1728 | ILE->setType(ResultTy); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1729 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1734 | /// By default, performs semantic analysis to build the new expression. |
| 1735 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1736 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1737 | MultiExprArg ArrayExprs, |
| 1738 | SourceLocation EqualOrColonLoc, |
| 1739 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1740 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1741 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1743 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1745 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1747 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1748 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1750 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1752 | /// By default, builds the implicit value initialization without performing |
| 1753 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1754 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1755 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1756 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1761 | /// By default, performs semantic analysis to build the new expression. |
| 1762 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1763 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1764 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1765 | SourceLocation RParenLoc) { |
| 1766 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1767 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1768 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | /// By default, performs semantic analysis to build the new expression. |
| 1774 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1775 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1776 | MultiExprArg SubExprs, |
| 1777 | SourceLocation RParenLoc) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1778 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1780 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | /// |
| 1783 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1784 | /// rather than attempting to map the label statement itself. |
| 1785 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1786 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1787 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1788 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1793 | /// By default, performs semantic analysis to build the new expression. |
| 1794 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1795 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1796 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1798 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1800 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1801 | /// \brief Build a new __builtin_choose_expr expression. |
| 1802 | /// |
| 1803 | /// By default, performs semantic analysis to build the new expression. |
| 1804 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1805 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1806 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1807 | SourceLocation RParenLoc) { |
| 1808 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1809 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1810 | RParenLoc); |
| 1811 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1812 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1813 | /// \brief Build a new generic selection expression. |
| 1814 | /// |
| 1815 | /// By default, performs semantic analysis to build the new expression. |
| 1816 | /// Subclasses may override this routine to provide different behavior. |
| 1817 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1818 | SourceLocation DefaultLoc, |
| 1819 | SourceLocation RParenLoc, |
| 1820 | Expr *ControllingExpr, |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1821 | ArrayRef<TypeSourceInfo *> Types, |
| 1822 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1823 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1824 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1827 | /// \brief Build a new overloaded operator call expression. |
| 1828 | /// |
| 1829 | /// By default, performs semantic analysis to build the new expression. |
| 1830 | /// The semantic analysis provides the behavior of template instantiation, |
| 1831 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1833 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1834 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1835 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1836 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1837 | Expr *Callee, |
| 1838 | Expr *First, |
| 1839 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | |
| 1841 | /// \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] | 1842 | /// reinterpret_cast. |
| 1843 | /// |
| 1844 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1846 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1847 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1848 | Stmt::StmtClass Class, |
| 1849 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1850 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1851 | SourceLocation RAngleLoc, |
| 1852 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1853 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1854 | SourceLocation RParenLoc) { |
| 1855 | switch (Class) { |
| 1856 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1857 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1859 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1860 | |
| 1861 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1862 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1864 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1866 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1867 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1869 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1870 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1872 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1873 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1875 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1877 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1878 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1879 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1881 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1882 | /// \brief Build a new C++ static_cast expression. |
| 1883 | /// |
| 1884 | /// By default, performs semantic analysis to build the new expression. |
| 1885 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1886 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1887 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1888 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1889 | SourceLocation RAngleLoc, |
| 1890 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1891 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1892 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1893 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1894 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1895 | SourceRange(LAngleLoc, RAngleLoc), |
| 1896 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | /// \brief Build a new C++ dynamic_cast expression. |
| 1900 | /// |
| 1901 | /// By default, performs semantic analysis to build the new expression. |
| 1902 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1903 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1904 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1905 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1906 | SourceLocation RAngleLoc, |
| 1907 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1908 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1909 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1910 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1911 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1912 | SourceRange(LAngleLoc, RAngleLoc), |
| 1913 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1917 | /// |
| 1918 | /// By default, performs semantic analysis to build the new expression. |
| 1919 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1920 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1922 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1923 | SourceLocation RAngleLoc, |
| 1924 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1925 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1926 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1927 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1928 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1929 | SourceRange(LAngleLoc, RAngleLoc), |
| 1930 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | /// \brief Build a new C++ const_cast expression. |
| 1934 | /// |
| 1935 | /// By default, performs semantic analysis to build the new expression. |
| 1936 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1937 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1938 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1939 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | SourceLocation RAngleLoc, |
| 1941 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1942 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1944 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1945 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1946 | SourceRange(LAngleLoc, RAngleLoc), |
| 1947 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1948 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1950 | /// \brief Build a new C++ functional-style cast expression. |
| 1951 | /// |
| 1952 | /// By default, performs semantic analysis to build the new expression. |
| 1953 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1954 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1955 | SourceLocation LParenLoc, |
| 1956 | Expr *Sub, |
| 1957 | SourceLocation RParenLoc) { |
| 1958 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1959 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1960 | RParenLoc); |
| 1961 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1963 | /// \brief Build a new C++ typeid(type) expression. |
| 1964 | /// |
| 1965 | /// By default, performs semantic analysis to build the new expression. |
| 1966 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1967 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1968 | SourceLocation TypeidLoc, |
| 1969 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1970 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1971 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1972 | 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 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1975 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1976 | /// \brief Build a new C++ typeid(expr) expression. |
| 1977 | /// |
| 1978 | /// By default, performs semantic analysis to build the new expression. |
| 1979 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1980 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1981 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1982 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1983 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1984 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1985 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1988 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1989 | /// |
| 1990 | /// By default, performs semantic analysis to build the new expression. |
| 1991 | /// Subclasses may override this routine to provide different behavior. |
| 1992 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1993 | SourceLocation TypeidLoc, |
| 1994 | TypeSourceInfo *Operand, |
| 1995 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1996 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1997 | RParenLoc); |
| 1998 | } |
| 1999 | |
| 2000 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2001 | /// |
| 2002 | /// By default, performs semantic analysis to build the new expression. |
| 2003 | /// Subclasses may override this routine to provide different behavior. |
| 2004 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2005 | SourceLocation TypeidLoc, |
| 2006 | Expr *Operand, |
| 2007 | SourceLocation RParenLoc) { |
| 2008 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2009 | RParenLoc); |
| 2010 | } |
| 2011 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2012 | /// \brief Build a new C++ "this" expression. |
| 2013 | /// |
| 2014 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2016 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2017 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2018 | QualType ThisType, |
| 2019 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2020 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2021 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 2022 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 2023 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | /// \brief Build a new C++ throw expression. |
| 2027 | /// |
| 2028 | /// By default, performs semantic analysis to build the new expression. |
| 2029 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2030 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2031 | bool IsThrownVariableInScope) { |
| 2032 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | /// \brief Build a new C++ default-argument expression. |
| 2036 | /// |
| 2037 | /// By default, builds a new default-argument expression, which does not |
| 2038 | /// require any semantic analysis. Subclasses may override this routine to |
| 2039 | /// provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2040 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2041 | ParmVarDecl *Param) { |
| 2042 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 2043 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2046 | /// \brief Build a new C++11 default-initialization expression. |
| 2047 | /// |
| 2048 | /// By default, builds a new default field initialization expression, which |
| 2049 | /// does not require any semantic analysis. Subclasses may override this |
| 2050 | /// routine to provide different behavior. |
| 2051 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2052 | FieldDecl *Field) { |
| 2053 | return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc, |
| 2054 | Field)); |
| 2055 | } |
| 2056 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2057 | /// \brief Build a new C++ zero-initialization expression. |
| 2058 | /// |
| 2059 | /// By default, performs semantic analysis to build the new expression. |
| 2060 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2061 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2062 | SourceLocation LParenLoc, |
| 2063 | SourceLocation RParenLoc) { |
| 2064 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2065 | None, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2068 | /// \brief Build a new C++ "new" expression. |
| 2069 | /// |
| 2070 | /// By default, performs semantic analysis to build the new expression. |
| 2071 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2072 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2073 | bool UseGlobal, |
| 2074 | SourceLocation PlacementLParen, |
| 2075 | MultiExprArg PlacementArgs, |
| 2076 | SourceLocation PlacementRParen, |
| 2077 | SourceRange TypeIdParens, |
| 2078 | QualType AllocatedType, |
| 2079 | TypeSourceInfo *AllocatedTypeInfo, |
| 2080 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2081 | SourceRange DirectInitRange, |
| 2082 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2083 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2084 | PlacementLParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2085 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2086 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2087 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2088 | AllocatedType, |
| 2089 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2090 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2091 | DirectInitRange, |
| 2092 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2095 | /// \brief Build a new C++ "delete" expression. |
| 2096 | /// |
| 2097 | /// By default, performs semantic analysis to build the new expression. |
| 2098 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2099 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2100 | bool IsGlobalDelete, |
| 2101 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2102 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2103 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2104 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2106 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2107 | /// \brief Build a new unary type trait expression. |
| 2108 | /// |
| 2109 | /// By default, performs semantic analysis to build the new expression. |
| 2110 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2111 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2112 | SourceLocation StartLoc, |
| 2113 | TypeSourceInfo *T, |
| 2114 | SourceLocation RParenLoc) { |
| 2115 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2118 | /// \brief Build a new binary type trait expression. |
| 2119 | /// |
| 2120 | /// By default, performs semantic analysis to build the new expression. |
| 2121 | /// Subclasses may override this routine to provide different behavior. |
| 2122 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2123 | SourceLocation StartLoc, |
| 2124 | TypeSourceInfo *LhsT, |
| 2125 | TypeSourceInfo *RhsT, |
| 2126 | SourceLocation RParenLoc) { |
| 2127 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2128 | } |
| 2129 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2130 | /// \brief Build a new type trait expression. |
| 2131 | /// |
| 2132 | /// By default, performs semantic analysis to build the new expression. |
| 2133 | /// Subclasses may override this routine to provide different behavior. |
| 2134 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2135 | SourceLocation StartLoc, |
| 2136 | ArrayRef<TypeSourceInfo *> Args, |
| 2137 | SourceLocation RParenLoc) { |
| 2138 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2139 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2140 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2141 | /// \brief Build a new array type trait expression. |
| 2142 | /// |
| 2143 | /// By default, performs semantic analysis to build the new expression. |
| 2144 | /// Subclasses may override this routine to provide different behavior. |
| 2145 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2146 | SourceLocation StartLoc, |
| 2147 | TypeSourceInfo *TSInfo, |
| 2148 | Expr *DimExpr, |
| 2149 | SourceLocation RParenLoc) { |
| 2150 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2151 | } |
| 2152 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2153 | /// \brief Build a new expression trait expression. |
| 2154 | /// |
| 2155 | /// By default, performs semantic analysis to build the new expression. |
| 2156 | /// Subclasses may override this routine to provide different behavior. |
| 2157 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2158 | SourceLocation StartLoc, |
| 2159 | Expr *Queried, |
| 2160 | SourceLocation RParenLoc) { |
| 2161 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2162 | } |
| 2163 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2164 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2165 | /// expression. |
| 2166 | /// |
| 2167 | /// By default, performs semantic analysis to build the new expression. |
| 2168 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2169 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2170 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2171 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2172 | const DeclarationNameInfo &NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2173 | const TemplateArgumentListInfo *TemplateArgs, |
| 2174 | bool IsAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2175 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2176 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2177 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2178 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2179 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2180 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2181 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2182 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, |
| 2183 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | /// \brief Build a new template-id expression. |
| 2187 | /// |
| 2188 | /// By default, performs semantic analysis to build the new expression. |
| 2189 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2190 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2191 | SourceLocation TemplateKWLoc, |
| 2192 | LookupResult &R, |
| 2193 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2194 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2195 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2196 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | /// \brief Build a new object-construction expression. |
| 2200 | /// |
| 2201 | /// By default, performs semantic analysis to build the new expression. |
| 2202 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2203 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2204 | SourceLocation Loc, |
| 2205 | CXXConstructorDecl *Constructor, |
| 2206 | bool IsElidable, |
| 2207 | MultiExprArg Args, |
| 2208 | bool HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2209 | bool ListInitialization, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2210 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2211 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2212 | SourceRange ParenRange) { |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2213 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2214 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2215 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2216 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2217 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2218 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2219 | ConvertedArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2220 | HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2221 | ListInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2222 | RequiresZeroInit, ConstructKind, |
| 2223 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /// \brief Build a new object-construction expression. |
| 2227 | /// |
| 2228 | /// By default, performs semantic analysis to build the new expression. |
| 2229 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2230 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2231 | SourceLocation LParenLoc, |
| 2232 | MultiExprArg Args, |
| 2233 | SourceLocation RParenLoc) { |
| 2234 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2235 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2236 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2237 | RParenLoc); |
| 2238 | } |
| 2239 | |
| 2240 | /// \brief Build a new object-construction expression. |
| 2241 | /// |
| 2242 | /// By default, performs semantic analysis to build the new expression. |
| 2243 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2244 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2245 | SourceLocation LParenLoc, |
| 2246 | MultiExprArg Args, |
| 2247 | SourceLocation RParenLoc) { |
| 2248 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2249 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2250 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2251 | RParenLoc); |
| 2252 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2253 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2254 | /// \brief Build a new member reference expression. |
| 2255 | /// |
| 2256 | /// By default, performs semantic analysis to build the new expression. |
| 2257 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2258 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2259 | QualType BaseType, |
| 2260 | bool IsArrow, |
| 2261 | SourceLocation OperatorLoc, |
| 2262 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2263 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2264 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2265 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2266 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2267 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2268 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2269 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2270 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2271 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2272 | SS, TemplateKWLoc, |
| 2273 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2274 | MemberNameInfo, |
| 2275 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2278 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2279 | /// |
| 2280 | /// By default, performs semantic analysis to build the new expression. |
| 2281 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2282 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2283 | SourceLocation OperatorLoc, |
| 2284 | bool IsArrow, |
| 2285 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2286 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2287 | NamedDecl *FirstQualifierInScope, |
| 2288 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2289 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2290 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2291 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2292 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2293 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2294 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2295 | SS, TemplateKWLoc, |
| 2296 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2297 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2299 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2300 | /// \brief Build a new noexcept expression. |
| 2301 | /// |
| 2302 | /// By default, performs semantic analysis to build the new expression. |
| 2303 | /// Subclasses may override this routine to provide different behavior. |
| 2304 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2305 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2306 | } |
| 2307 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2308 | /// \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] | 2309 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2310 | SourceLocation PackLoc, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2311 | SourceLocation RParenLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2312 | Optional<unsigned> Length) { |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2313 | if (Length) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2314 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2315 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2316 | RParenLoc, *Length); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2317 | |
| 2318 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2319 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2320 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2321 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2322 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2323 | /// \brief Build a new Objective-C boxed expression. |
| 2324 | /// |
| 2325 | /// By default, performs semantic analysis to build the new expression. |
| 2326 | /// Subclasses may override this routine to provide different behavior. |
| 2327 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2328 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2329 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2330 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2331 | /// \brief Build a new Objective-C array literal. |
| 2332 | /// |
| 2333 | /// By default, performs semantic analysis to build the new expression. |
| 2334 | /// Subclasses may override this routine to provide different behavior. |
| 2335 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2336 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2337 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2338 | MultiExprArg(Elements, NumElements)); |
| 2339 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2340 | |
| 2341 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2342 | Expr *Base, Expr *Key, |
| 2343 | ObjCMethodDecl *getterMethod, |
| 2344 | ObjCMethodDecl *setterMethod) { |
| 2345 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2346 | getterMethod, setterMethod); |
| 2347 | } |
| 2348 | |
| 2349 | /// \brief Build a new Objective-C dictionary literal. |
| 2350 | /// |
| 2351 | /// By default, performs semantic analysis to build the new expression. |
| 2352 | /// Subclasses may override this routine to provide different behavior. |
| 2353 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2354 | ObjCDictionaryElement *Elements, |
| 2355 | unsigned NumElements) { |
| 2356 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2357 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2358 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2359 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2360 | /// |
| 2361 | /// By default, performs semantic analysis to build the new expression. |
| 2362 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2363 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2364 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2365 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2366 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2367 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2368 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2369 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2370 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2371 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2372 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2373 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2374 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2375 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2376 | MultiExprArg Args, |
| 2377 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2378 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2379 | ReceiverTypeInfo->getType(), |
| 2380 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2381 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2382 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2386 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2387 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2388 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2389 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2390 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2391 | MultiExprArg Args, |
| 2392 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2393 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2394 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2395 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2396 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2397 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2400 | /// \brief Build a new Objective-C ivar reference expression. |
| 2401 | /// |
| 2402 | /// By default, performs semantic analysis to build the new expression. |
| 2403 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2404 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2405 | SourceLocation IvarLoc, |
| 2406 | bool IsArrow, bool IsFreeIvar) { |
| 2407 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2408 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2409 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2410 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2411 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2412 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2413 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2414 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2415 | false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2416 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2417 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2418 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2419 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2420 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2421 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2422 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2423 | /*FIXME:*/IvarLoc, IsArrow, |
| 2424 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2425 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2426 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2427 | /*TemplateArgs=*/0); |
| 2428 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2429 | |
| 2430 | /// \brief Build a new Objective-C property reference expression. |
| 2431 | /// |
| 2432 | /// By default, performs semantic analysis to build the new expression. |
| 2433 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2434 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2435 | ObjCPropertyDecl *Property, |
| 2436 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2437 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2438 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2439 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2440 | Sema::LookupMemberName); |
| 2441 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2442 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2443 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2444 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2445 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2446 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2447 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2448 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2449 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2450 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2451 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2452 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2453 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2454 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2455 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2456 | /*TemplateArgs=*/0); |
| 2457 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2458 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2459 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2460 | /// |
| 2461 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2462 | /// Subclasses may override this routine to provide different behavior. |
| 2463 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2464 | ObjCMethodDecl *Getter, |
| 2465 | ObjCMethodDecl *Setter, |
| 2466 | SourceLocation PropertyLoc) { |
| 2467 | // Since these expressions can only be value-dependent, we do not |
| 2468 | // need to perform semantic analysis again. |
| 2469 | return Owned( |
| 2470 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2471 | VK_LValue, OK_ObjCProperty, |
| 2472 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2475 | /// \brief Build a new Objective-C "isa" expression. |
| 2476 | /// |
| 2477 | /// By default, performs semantic analysis to build the new expression. |
| 2478 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2479 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2480 | SourceLocation OpLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2481 | bool IsArrow) { |
| 2482 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2483 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2484 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2485 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2486 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2487 | OpLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2488 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2489 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2490 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2491 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2492 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2493 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2494 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2495 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2496 | OpLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2497 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2498 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2499 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2500 | /*TemplateArgs=*/0); |
| 2501 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2503 | /// \brief Build a new shuffle vector expression. |
| 2504 | /// |
| 2505 | /// By default, performs semantic analysis to build the new expression. |
| 2506 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2507 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2508 | MultiExprArg SubExprs, |
| 2509 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2510 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2511 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2512 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2513 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2514 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2515 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2516 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2517 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2518 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2519 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2520 | SemaRef.Context.BuiltinFnTy, |
| 2521 | VK_RValue, BuiltinLoc); |
| 2522 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2523 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 2524 | CK_BuiltinFnToFnPtr).take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2525 | |
| 2526 | // Build the CallExpr |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2527 | ExprResult TheCall = SemaRef.Owned( |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2528 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs, |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2529 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2530 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2531 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2532 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2533 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2534 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2535 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2536 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2537 | /// \brief Build a new template argument pack expansion. |
| 2538 | /// |
| 2539 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2540 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2541 | /// different behavior. |
| 2542 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2543 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2544 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2545 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2546 | case TemplateArgument::Expression: { |
| 2547 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2548 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2549 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2550 | if (Result.isInvalid()) |
| 2551 | return TemplateArgumentLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2552 | |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2553 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2554 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2555 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2556 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2557 | return TemplateArgumentLoc(TemplateArgument( |
| 2558 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2559 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2560 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2561 | Pattern.getTemplateNameLoc(), |
| 2562 | EllipsisLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2563 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2564 | case TemplateArgument::Null: |
| 2565 | case TemplateArgument::Integral: |
| 2566 | case TemplateArgument::Declaration: |
| 2567 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2568 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2569 | case TemplateArgument::NullPtr: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2570 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2571 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2572 | case TemplateArgument::Type: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2573 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2574 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2575 | EllipsisLoc, |
| 2576 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2577 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2578 | Expansion); |
| 2579 | break; |
| 2580 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2582 | return TemplateArgumentLoc(); |
| 2583 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2584 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2585 | /// \brief Build a new expression pack expansion. |
| 2586 | /// |
| 2587 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2588 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2589 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2590 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2591 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2592 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2593 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2594 | |
| 2595 | /// \brief Build a new atomic operation expression. |
| 2596 | /// |
| 2597 | /// By default, performs semantic analysis to build the new expression. |
| 2598 | /// Subclasses may override this routine to provide different behavior. |
| 2599 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2600 | MultiExprArg SubExprs, |
| 2601 | QualType RetTy, |
| 2602 | AtomicExpr::AtomicOp Op, |
| 2603 | SourceLocation RParenLoc) { |
| 2604 | // Just create the expression; there is not any interesting semantic |
| 2605 | // analysis here because we can't actually build an AtomicExpr until |
| 2606 | // we are sure it is semantically sound. |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2607 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2608 | RParenLoc); |
| 2609 | } |
| 2610 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2611 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2612 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2613 | QualType ObjectType, |
| 2614 | NamedDecl *FirstQualifierInScope, |
| 2615 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2616 | |
| 2617 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2618 | QualType ObjectType, |
| 2619 | NamedDecl *FirstQualifierInScope, |
| 2620 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2621 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2622 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2623 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2624 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2625 | if (!S) |
| 2626 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2627 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2628 | switch (S->getStmtClass()) { |
| 2629 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2630 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2631 | // Transform individual statement nodes |
| 2632 | #define STMT(Node, Parent) \ |
| 2633 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2634 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2635 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2636 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2637 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2638 | // Transform expressions by calling TransformExpr. |
| 2639 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2640 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2641 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2642 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2643 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2644 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2645 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2646 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2647 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2648 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2650 | } |
| 2651 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2652 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2654 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2655 | template<typename Derived> |
| 2656 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2657 | if (!S) |
| 2658 | return S; |
| 2659 | |
| 2660 | switch (S->getClauseKind()) { |
| 2661 | default: break; |
| 2662 | // Transform individual clause nodes |
| 2663 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2664 | case OMPC_ ## Name : \ |
| 2665 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2666 | #include "clang/Basic/OpenMPKinds.def" |
| 2667 | } |
| 2668 | |
| 2669 | return S; |
| 2670 | } |
| 2671 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2672 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2673 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2674 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2675 | if (!E) |
| 2676 | return SemaRef.Owned(E); |
| 2677 | |
| 2678 | switch (E->getStmtClass()) { |
| 2679 | case Stmt::NoStmtClass: break; |
| 2680 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2681 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2682 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2683 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2684 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2687 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | template<typename Derived> |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2691 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2692 | bool CXXDirectInit) { |
| 2693 | // Initializers are instantiated like expressions, except that various outer |
| 2694 | // layers are stripped. |
| 2695 | if (!Init) |
| 2696 | return SemaRef.Owned(Init); |
| 2697 | |
| 2698 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2699 | Init = ExprTemp->getSubExpr(); |
| 2700 | |
Richard Smith | 858c2c3 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2701 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2702 | Init = MTE->GetTemporaryExpr(); |
| 2703 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2704 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2705 | Init = Binder->getSubExpr(); |
| 2706 | |
| 2707 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2708 | Init = ICE->getSubExprAsWritten(); |
| 2709 | |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2710 | if (CXXStdInitializerListExpr *ILE = |
| 2711 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 2712 | return TransformInitializer(ILE->getSubExpr(), CXXDirectInit); |
| 2713 | |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2714 | // If this is not a direct-initializer, we only need to reconstruct |
| 2715 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2716 | // the initializer is already the right type. |
| 2717 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2718 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2719 | return getDerived().TransformExpr(Init); |
| 2720 | |
| 2721 | // Revert value-initialization back to empty parens. |
| 2722 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2723 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2724 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2725 | Parens.getEnd()); |
| 2726 | } |
| 2727 | |
| 2728 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2729 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2730 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2731 | SourceLocation()); |
| 2732 | |
| 2733 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2734 | // of expressions. Any other form of initializer can just be reused directly. |
| 2735 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2736 | return getDerived().TransformExpr(Init); |
| 2737 | |
| 2738 | SmallVector<Expr*, 8> NewArgs; |
| 2739 | bool ArgChanged = false; |
| 2740 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2741 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2742 | return ExprError(); |
| 2743 | |
| 2744 | // If this was list initialization, revert to list form. |
| 2745 | if (Construct->isListInitialization()) |
| 2746 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2747 | Construct->getLocEnd(), |
| 2748 | Construct->getType()); |
| 2749 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2750 | // Build a ParenListExpr to represent anything else. |
| 2751 | SourceRange Parens = Construct->getParenRange(); |
| 2752 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2753 | Parens.getEnd()); |
| 2754 | } |
| 2755 | |
| 2756 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2757 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2758 | unsigned NumInputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2759 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2760 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2761 | bool *ArgChanged) { |
| 2762 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2763 | // If requested, drop call arguments that need to be dropped. |
| 2764 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2765 | if (ArgChanged) |
| 2766 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2767 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2768 | break; |
| 2769 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2770 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2771 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2772 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2773 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2774 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2775 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2776 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2777 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2778 | // Determine whether the set of unexpanded parameter packs can and should |
| 2779 | // be expanded. |
| 2780 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2781 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2782 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2783 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2784 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2785 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2786 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2787 | Expand, RetainExpansion, |
| 2788 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2789 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2790 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2791 | if (!Expand) { |
| 2792 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2793 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2794 | // expansion. |
| 2795 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2796 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2797 | if (OutPattern.isInvalid()) |
| 2798 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2799 | |
| 2800 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2801 | Expansion->getEllipsisLoc(), |
| 2802 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2803 | if (Out.isInvalid()) |
| 2804 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2805 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2806 | if (ArgChanged) |
| 2807 | *ArgChanged = true; |
| 2808 | Outputs.push_back(Out.get()); |
| 2809 | continue; |
| 2810 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2811 | |
| 2812 | // Record right away that the argument was changed. This needs |
| 2813 | // to happen even if the array expands to nothing. |
| 2814 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2815 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2816 | // The transform has determined that we should perform an elementwise |
| 2817 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2818 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2819 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2820 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2821 | if (Out.isInvalid()) |
| 2822 | return true; |
| 2823 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2824 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2825 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2826 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2827 | if (Out.isInvalid()) |
| 2828 | return true; |
| 2829 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2830 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2831 | Outputs.push_back(Out.get()); |
| 2832 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2833 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2834 | continue; |
| 2835 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2836 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2837 | ExprResult Result = |
| 2838 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 2839 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2840 | if (Result.isInvalid()) |
| 2841 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2842 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2843 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2844 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2845 | |
| 2846 | Outputs.push_back(Result.get()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2847 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2848 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2849 | return false; |
| 2850 | } |
| 2851 | |
| 2852 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2853 | NestedNameSpecifierLoc |
| 2854 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2855 | NestedNameSpecifierLoc NNS, |
| 2856 | QualType ObjectType, |
| 2857 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2858 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2859 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2860 | Qualifier = Qualifier.getPrefix()) |
| 2861 | Qualifiers.push_back(Qualifier); |
| 2862 | |
| 2863 | CXXScopeSpec SS; |
| 2864 | while (!Qualifiers.empty()) { |
| 2865 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2866 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2867 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2868 | switch (QNNS->getKind()) { |
| 2869 | case NestedNameSpecifier::Identifier: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2870 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2871 | *QNNS->getAsIdentifier(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2872 | Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2873 | Q.getLocalEndLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2874 | ObjectType, false, SS, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2875 | FirstQualifierInScope, false)) |
| 2876 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2877 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2878 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2879 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2880 | case NestedNameSpecifier::Namespace: { |
| 2881 | NamespaceDecl *NS |
| 2882 | = cast_or_null<NamespaceDecl>( |
| 2883 | getDerived().TransformDecl( |
| 2884 | Q.getLocalBeginLoc(), |
| 2885 | QNNS->getAsNamespace())); |
| 2886 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2887 | break; |
| 2888 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2889 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2890 | case NestedNameSpecifier::NamespaceAlias: { |
| 2891 | NamespaceAliasDecl *Alias |
| 2892 | = cast_or_null<NamespaceAliasDecl>( |
| 2893 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2894 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2895 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2896 | Q.getLocalEndLoc()); |
| 2897 | break; |
| 2898 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2899 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2900 | case NestedNameSpecifier::Global: |
| 2901 | // There is no meaningful transformation that one could perform on the |
| 2902 | // global scope. |
| 2903 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2904 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2905 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2906 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2907 | case NestedNameSpecifier::TypeSpec: { |
| 2908 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2909 | FirstQualifierInScope, SS); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2910 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2911 | if (!TL) |
| 2912 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2913 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2914 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2915 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2916 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2917 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2918 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2919 | if (TL.getType()->isEnumeralType()) |
| 2920 | SemaRef.Diag(TL.getBeginLoc(), |
| 2921 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2922 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2923 | Q.getLocalEndLoc()); |
| 2924 | break; |
| 2925 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2926 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2927 | // error because a previous error should have already been emitted. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 2928 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 2929 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2930 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2931 | << TL.getType() << SS.getRange(); |
| 2932 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2933 | return NestedNameSpecifierLoc(); |
| 2934 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2935 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2936 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2937 | // 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] | 2938 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2939 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2940 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2941 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2942 | // 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] | 2943 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2944 | !getDerived().AlwaysRebuild()) |
| 2945 | return NNS; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2946 | |
| 2947 | // If we can re-use the source-location data from the original |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2948 | // nested-name-specifier, do so. |
| 2949 | if (SS.location_size() == NNS.getDataLength() && |
| 2950 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2951 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2952 | |
| 2953 | // Allocate new nested-name-specifier location information. |
| 2954 | return SS.getWithLocInContext(SemaRef.Context); |
| 2955 | } |
| 2956 | |
| 2957 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2958 | DeclarationNameInfo |
| 2959 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2960 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2961 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2962 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2963 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2964 | |
| 2965 | switch (Name.getNameKind()) { |
| 2966 | case DeclarationName::Identifier: |
| 2967 | case DeclarationName::ObjCZeroArgSelector: |
| 2968 | case DeclarationName::ObjCOneArgSelector: |
| 2969 | case DeclarationName::ObjCMultiArgSelector: |
| 2970 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2971 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2972 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2973 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2975 | case DeclarationName::CXXConstructorName: |
| 2976 | case DeclarationName::CXXDestructorName: |
| 2977 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2978 | TypeSourceInfo *NewTInfo; |
| 2979 | CanQualType NewCanTy; |
| 2980 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2981 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2982 | if (!NewTInfo) |
| 2983 | return DeclarationNameInfo(); |
| 2984 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2985 | } |
| 2986 | else { |
| 2987 | NewTInfo = 0; |
| 2988 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2989 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2990 | if (NewT.isNull()) |
| 2991 | return DeclarationNameInfo(); |
| 2992 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2995 | DeclarationName NewName |
| 2996 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2997 | NewCanTy); |
| 2998 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2999 | NewNameInfo.setName(NewName); |
| 3000 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3001 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3005 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3009 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3010 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3011 | TemplateName Name, |
| 3012 | SourceLocation NameLoc, |
| 3013 | QualType ObjectType, |
| 3014 | NamedDecl *FirstQualifierInScope) { |
| 3015 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3016 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3017 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3018 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3019 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3020 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3021 | Template)); |
| 3022 | if (!TransTemplate) |
| 3023 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3024 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3025 | if (!getDerived().AlwaysRebuild() && |
| 3026 | SS.getScopeRep() == QTN->getQualifier() && |
| 3027 | TransTemplate == Template) |
| 3028 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3029 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3030 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3031 | TransTemplate); |
| 3032 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3033 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3034 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3035 | if (SS.getScopeRep()) { |
| 3036 | // These apply to the scope specifier, not the template. |
| 3037 | ObjectType = QualType(); |
| 3038 | FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3041 | if (!getDerived().AlwaysRebuild() && |
| 3042 | SS.getScopeRep() == DTN->getQualifier() && |
| 3043 | ObjectType.isNull()) |
| 3044 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3046 | if (DTN->isIdentifier()) { |
| 3047 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3048 | *DTN->getIdentifier(), |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3049 | NameLoc, |
| 3050 | ObjectType, |
| 3051 | FirstQualifierInScope); |
| 3052 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3054 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3055 | ObjectType); |
| 3056 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3057 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3058 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3059 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3060 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3061 | Template)); |
| 3062 | if (!TransTemplate) |
| 3063 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3064 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3065 | if (!getDerived().AlwaysRebuild() && |
| 3066 | TransTemplate == Template) |
| 3067 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3068 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3069 | return TemplateName(TransTemplate); |
| 3070 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3071 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3072 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3073 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3074 | TemplateTemplateParmDecl *TransParam |
| 3075 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3076 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3077 | if (!TransParam) |
| 3078 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3079 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3080 | if (!getDerived().AlwaysRebuild() && |
| 3081 | TransParam == SubstPack->getParameterPack()) |
| 3082 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3083 | |
| 3084 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3085 | SubstPack->getArgumentPack()); |
| 3086 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3088 | // These should be getting filtered out before they reach the AST. |
| 3089 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3093 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3094 | const TemplateArgument &Arg, |
| 3095 | TemplateArgumentLoc &Output) { |
| 3096 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3097 | switch (Arg.getKind()) { |
| 3098 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3099 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3100 | break; |
| 3101 | |
| 3102 | case TemplateArgument::Type: |
| 3103 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3104 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3105 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3106 | break; |
| 3107 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3108 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3109 | case TemplateArgument::TemplateExpansion: { |
| 3110 | NestedNameSpecifierLocBuilder Builder; |
| 3111 | TemplateName Template = Arg.getAsTemplate(); |
| 3112 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3113 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3114 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3115 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3117 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3118 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3119 | Builder.getWithLocInContext(SemaRef.Context), |
| 3120 | Loc); |
| 3121 | else |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3122 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3123 | Builder.getWithLocInContext(SemaRef.Context), |
| 3124 | Loc, Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3125 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3126 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3127 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3128 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3129 | case TemplateArgument::Expression: |
| 3130 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3131 | break; |
| 3132 | |
| 3133 | case TemplateArgument::Declaration: |
| 3134 | case TemplateArgument::Integral: |
| 3135 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3136 | case TemplateArgument::NullPtr: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3137 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3138 | break; |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | template<typename Derived> |
| 3143 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3144 | const TemplateArgumentLoc &Input, |
| 3145 | TemplateArgumentLoc &Output) { |
| 3146 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3147 | switch (Arg.getKind()) { |
| 3148 | case TemplateArgument::Null: |
| 3149 | case TemplateArgument::Integral: |
Eli Friedman | 511e3ae | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3150 | case TemplateArgument::Pack: |
| 3151 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3152 | case TemplateArgument::NullPtr: |
| 3153 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3155 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3156 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3157 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3158 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3159 | |
| 3160 | DI = getDerived().TransformType(DI); |
| 3161 | if (!DI) return true; |
| 3162 | |
| 3163 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3164 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3165 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3167 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3168 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3169 | if (QualifierLoc) { |
| 3170 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3171 | if (!QualifierLoc) |
| 3172 | return true; |
| 3173 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3174 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3175 | CXXScopeSpec SS; |
| 3176 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3177 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3178 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3179 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3180 | if (Template.isNull()) |
| 3181 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3182 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3183 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3184 | Input.getTemplateNameLoc()); |
| 3185 | return false; |
| 3186 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3187 | |
| 3188 | case TemplateArgument::TemplateExpansion: |
| 3189 | llvm_unreachable("Caller should expand pack expansions"); |
| 3190 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3191 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3192 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3193 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3194 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3195 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3196 | Expr *InputExpr = Input.getSourceExpression(); |
| 3197 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3198 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3199 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3200 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3201 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3202 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3203 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3204 | } |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3206 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3207 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3208 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3211 | /// \brief Iterator adaptor that invents template argument location information |
| 3212 | /// for each of the template arguments in its underlying iterator. |
| 3213 | template<typename Derived, typename InputIterator> |
| 3214 | class TemplateArgumentLocInventIterator { |
| 3215 | TreeTransform<Derived> &Self; |
| 3216 | InputIterator Iter; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3217 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3218 | public: |
| 3219 | typedef TemplateArgumentLoc value_type; |
| 3220 | typedef TemplateArgumentLoc reference; |
| 3221 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3222 | difference_type; |
| 3223 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3224 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3225 | class pointer { |
| 3226 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3227 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3228 | public: |
| 3229 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3231 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3232 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3233 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3234 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3235 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3236 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3237 | InputIterator Iter) |
| 3238 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3239 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3240 | TemplateArgumentLocInventIterator &operator++() { |
| 3241 | ++Iter; |
| 3242 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3243 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3244 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3245 | TemplateArgumentLocInventIterator operator++(int) { |
| 3246 | TemplateArgumentLocInventIterator Old(*this); |
| 3247 | ++(*this); |
| 3248 | return Old; |
| 3249 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3251 | reference operator*() const { |
| 3252 | TemplateArgumentLoc Result; |
| 3253 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3254 | return Result; |
| 3255 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3256 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3257 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3258 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3259 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3260 | const TemplateArgumentLocInventIterator &Y) { |
| 3261 | return X.Iter == Y.Iter; |
| 3262 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3263 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3264 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3265 | const TemplateArgumentLocInventIterator &Y) { |
| 3266 | return X.Iter != Y.Iter; |
| 3267 | } |
| 3268 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3269 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3270 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3271 | template<typename InputIterator> |
| 3272 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3273 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3274 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3275 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3276 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3277 | TemplateArgumentLoc In = *First; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3278 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3279 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3280 | // Unpack argument packs, which we translate them into separate |
| 3281 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3282 | // FIXME: We could do much better if we could guarantee that the |
| 3283 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3284 | // all of the template arguments in the argument pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3285 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3286 | TemplateArgument::pack_iterator> |
| 3287 | PackLocIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3288 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3289 | In.getArgument().pack_begin()), |
| 3290 | PackLocIterator(*this, |
| 3291 | In.getArgument().pack_end()), |
| 3292 | Outputs)) |
| 3293 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3294 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3295 | continue; |
| 3296 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3297 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3298 | if (In.getArgument().isPackExpansion()) { |
| 3299 | // We have a pack expansion, for which we will be substituting into |
| 3300 | // the pattern. |
| 3301 | SourceLocation Ellipsis; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3302 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3303 | TemplateArgumentLoc Pattern |
Eli Friedman | 850cf51 | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3304 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3305 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3306 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3307 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3308 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3309 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3310 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3311 | // Determine whether the set of unexpanded parameter packs can and should |
| 3312 | // be expanded. |
| 3313 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3314 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3315 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3316 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3317 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3318 | Unexpanded, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3319 | Expand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3320 | RetainExpansion, |
| 3321 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3322 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3323 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3324 | if (!Expand) { |
| 3325 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3326 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3327 | // expansion. |
| 3328 | TemplateArgumentLoc OutPattern; |
| 3329 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3330 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3331 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3332 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3333 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3334 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3335 | if (Out.getArgument().isNull()) |
| 3336 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3337 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3338 | Outputs.addArgument(Out); |
| 3339 | continue; |
| 3340 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3341 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3342 | // The transform has determined that we should perform an elementwise |
| 3343 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3344 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3345 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3346 | |
| 3347 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3348 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3349 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3350 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3351 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3352 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3353 | if (Out.getArgument().isNull()) |
| 3354 | return true; |
| 3355 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3356 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3357 | Outputs.addArgument(Out); |
| 3358 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3359 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3360 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3361 | // forgetting the partially-substituted parameter pack. |
| 3362 | if (RetainExpansion) { |
| 3363 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3364 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3365 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3366 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3368 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3369 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3370 | if (Out.getArgument().isNull()) |
| 3371 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3372 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3373 | Outputs.addArgument(Out); |
| 3374 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3375 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3376 | continue; |
| 3377 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3378 | |
| 3379 | // The simple case: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3380 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3381 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3382 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3383 | Outputs.addArgument(Out); |
| 3384 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3385 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3386 | return false; |
| 3387 | |
| 3388 | } |
| 3389 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3390 | //===----------------------------------------------------------------------===// |
| 3391 | // Type transformation |
| 3392 | //===----------------------------------------------------------------------===// |
| 3393 | |
| 3394 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3395 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3396 | if (getDerived().AlreadyTransformed(T)) |
| 3397 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3398 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3399 | // Temporary workaround. All of these transformations should |
| 3400 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3401 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3402 | getDerived().getBaseLocation()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3403 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3404 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3405 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3406 | if (!NewDI) |
| 3407 | return QualType(); |
| 3408 | |
| 3409 | return NewDI->getType(); |
| 3410 | } |
| 3411 | |
| 3412 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3413 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3414 | // Refine the base location to the type's location. |
| 3415 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3416 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3417 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3418 | return DI; |
| 3419 | |
| 3420 | TypeLocBuilder TLB; |
| 3421 | |
| 3422 | TypeLoc TL = DI->getTypeLoc(); |
| 3423 | TLB.reserve(TL.getFullDataSize()); |
| 3424 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3425 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3426 | if (Result.isNull()) |
| 3427 | return 0; |
| 3428 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3429 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | template<typename Derived> |
| 3433 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3434 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3435 | switch (T.getTypeLocClass()) { |
| 3436 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3437 | #define TYPELOC(CLASS, PARENT) \ |
| 3438 | case TypeLoc::CLASS: \ |
| 3439 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3440 | T.castAs<CLASS##TypeLoc>()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3441 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3443 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3444 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3448 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3449 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3450 | /// types). This is the right thing for template instantiation, but |
| 3451 | /// probably not for other clients. |
| 3452 | template<typename Derived> |
| 3453 | QualType |
| 3454 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3455 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3456 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3457 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3458 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3459 | if (Result.isNull()) |
| 3460 | return QualType(); |
| 3461 | |
| 3462 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3463 | // FIXME: this is the right thing for template instantiation, but |
| 3464 | // probably not for other clients. |
| 3465 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3466 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3467 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3468 | // 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] | 3469 | // resulting type. |
| 3470 | if (Quals.hasObjCLifetime()) { |
| 3471 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3472 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3473 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3474 | // Objective-C ARC: |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3475 | // A lifetime qualifier applied to a substituted template parameter |
| 3476 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3477 | const AutoType *AutoTy; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3478 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3479 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3480 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3481 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3482 | Qs.removeObjCLifetime(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3483 | Replacement |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3484 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3485 | Qs); |
| 3486 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3487 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3488 | Replacement); |
| 3489 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3490 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3491 | // 'auto' types behave the same way as template parameters. |
| 3492 | QualType Deduced = AutoTy->getDeducedType(); |
| 3493 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3494 | Qs.removeObjCLifetime(); |
| 3495 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3496 | Qs); |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 3497 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto()); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3498 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3499 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3500 | // Otherwise, complain about the addition of a qualifier to an |
| 3501 | // already-qualified type. |
Eli Friedman | 44ee0a7 | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3502 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3503 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3504 | << Result << R; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3505 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3506 | Quals.removeObjCLifetime(); |
| 3507 | } |
| 3508 | } |
| 3509 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3510 | if (!Quals.empty()) { |
| 3511 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | 9807a2e | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3512 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3513 | if (Result.hasLocalQualifiers()) |
| 3514 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3515 | // No location information to preserve. |
| 3516 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3517 | |
| 3518 | return Result; |
| 3519 | } |
| 3520 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3521 | template<typename Derived> |
| 3522 | TypeLoc |
| 3523 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3524 | QualType ObjectType, |
| 3525 | NamedDecl *UnqualLookup, |
| 3526 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3527 | QualType T = TL.getType(); |
| 3528 | if (getDerived().AlreadyTransformed(T)) |
| 3529 | return TL; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3531 | TypeLocBuilder TLB; |
| 3532 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3533 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3534 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3535 | TemplateSpecializationTypeLoc SpecTL = |
| 3536 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3538 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3539 | getDerived().TransformTemplateName(SS, |
| 3540 | SpecTL.getTypePtr()->getTemplateName(), |
| 3541 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3542 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3543 | if (Template.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3544 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3545 | |
| 3546 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3547 | Template); |
| 3548 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3549 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3550 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3551 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3552 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3553 | = getDerived().RebuildTemplateName(SS, |
| 3554 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3555 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3556 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3557 | if (Template.isNull()) |
| 3558 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3559 | |
| 3560 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3561 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3562 | Template, |
| 3563 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3564 | } else { |
| 3565 | // Nothing special needs to be done for these. |
| 3566 | Result = getDerived().TransformType(TLB, TL); |
| 3567 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3568 | |
| 3569 | if (Result.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3570 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3571 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3572 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3573 | } |
| 3574 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3575 | template<typename Derived> |
| 3576 | TypeSourceInfo * |
| 3577 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3578 | QualType ObjectType, |
| 3579 | NamedDecl *UnqualLookup, |
| 3580 | CXXScopeSpec &SS) { |
| 3581 | // FIXME: Painfully copy-paste from the above! |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3583 | QualType T = TSInfo->getType(); |
| 3584 | if (getDerived().AlreadyTransformed(T)) |
| 3585 | return TSInfo; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3587 | TypeLocBuilder TLB; |
| 3588 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3589 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3590 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3591 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3592 | TemplateSpecializationTypeLoc SpecTL = |
| 3593 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3594 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3595 | TemplateName Template |
| 3596 | = getDerived().TransformTemplateName(SS, |
| 3597 | SpecTL.getTypePtr()->getTemplateName(), |
| 3598 | SpecTL.getTemplateNameLoc(), |
| 3599 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3600 | if (Template.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3601 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3602 | |
| 3603 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3604 | Template); |
| 3605 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3606 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3607 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3608 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3609 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3610 | = getDerived().RebuildTemplateName(SS, |
| 3611 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3612 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3613 | ObjectType, UnqualLookup); |
| 3614 | if (Template.isNull()) |
| 3615 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3616 | |
| 3617 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3618 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3619 | Template, |
| 3620 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3621 | } else { |
| 3622 | // Nothing special needs to be done for these. |
| 3623 | Result = getDerived().TransformType(TLB, TL); |
| 3624 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3625 | |
| 3626 | if (Result.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3627 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3628 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3629 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3630 | } |
| 3631 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3632 | template <class TyLoc> static inline |
| 3633 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3634 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3635 | NewT.setNameLoc(T.getNameLoc()); |
| 3636 | return T.getType(); |
| 3637 | } |
| 3638 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3639 | template<typename Derived> |
| 3640 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3641 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3642 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3643 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3644 | if (T.needsExtraLocalData()) |
| 3645 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3646 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3647 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3648 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3649 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3650 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3651 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3652 | // FIXME: recurse? |
| 3653 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3654 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3656 | template<typename Derived> |
Reid Kleckner | 12df246 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3657 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3658 | DecayedTypeLoc TL) { |
| 3659 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3660 | if (OriginalType.isNull()) |
| 3661 | return QualType(); |
| 3662 | |
| 3663 | QualType Result = TL.getType(); |
| 3664 | if (getDerived().AlwaysRebuild() || |
| 3665 | OriginalType != TL.getOriginalLoc().getType()) |
| 3666 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3667 | TLB.push<DecayedTypeLoc>(Result); |
| 3668 | // Nothing to set for DecayedTypeLoc. |
| 3669 | return Result; |
| 3670 | } |
| 3671 | |
| 3672 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3673 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3674 | PointerTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3675 | QualType PointeeType |
| 3676 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3677 | if (PointeeType.isNull()) |
| 3678 | return QualType(); |
| 3679 | |
| 3680 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3681 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3682 | // A dependent pointer type 'T *' has is being transformed such |
| 3683 | // that an Objective-C class type is being replaced for 'T'. The |
| 3684 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3685 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3686 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3687 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3688 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3689 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3690 | return Result; |
| 3691 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3693 | if (getDerived().AlwaysRebuild() || |
| 3694 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3695 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3696 | if (Result.isNull()) |
| 3697 | return QualType(); |
| 3698 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3699 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3700 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3701 | // pointing to. |
| 3702 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3703 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3704 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3705 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3706 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3707 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3708 | |
| 3709 | template<typename Derived> |
| 3710 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3711 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3712 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3713 | QualType PointeeType |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3714 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3715 | if (PointeeType.isNull()) |
| 3716 | return QualType(); |
| 3717 | |
| 3718 | QualType Result = TL.getType(); |
| 3719 | if (getDerived().AlwaysRebuild() || |
| 3720 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3721 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3722 | TL.getSigilLoc()); |
| 3723 | if (Result.isNull()) |
| 3724 | return QualType(); |
| 3725 | } |
| 3726 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3727 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3728 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3729 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3732 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3733 | /// don't care whether the type itself is an l-value type or an r-value |
| 3734 | /// type; we only care if the type was *written* as an l-value type |
| 3735 | /// or an r-value type. |
| 3736 | template<typename Derived> |
| 3737 | QualType |
| 3738 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3739 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3740 | const ReferenceType *T = TL.getTypePtr(); |
| 3741 | |
| 3742 | // Note that this works with the pointee-as-written. |
| 3743 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3744 | if (PointeeType.isNull()) |
| 3745 | return QualType(); |
| 3746 | |
| 3747 | QualType Result = TL.getType(); |
| 3748 | if (getDerived().AlwaysRebuild() || |
| 3749 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3750 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3751 | T->isSpelledAsLValue(), |
| 3752 | TL.getSigilLoc()); |
| 3753 | if (Result.isNull()) |
| 3754 | return QualType(); |
| 3755 | } |
| 3756 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3757 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3758 | // referring to. |
| 3759 | TLB.TypeWasModifiedSafely( |
| 3760 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3761 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3762 | // r-value references can be rebuilt as l-value references. |
| 3763 | ReferenceTypeLoc NewTL; |
| 3764 | if (isa<LValueReferenceType>(Result)) |
| 3765 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3766 | else |
| 3767 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3768 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3769 | |
| 3770 | return Result; |
| 3771 | } |
| 3772 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | template<typename Derived> |
| 3774 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3775 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3776 | LValueReferenceTypeLoc TL) { |
| 3777 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3780 | template<typename Derived> |
| 3781 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3782 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3783 | RValueReferenceTypeLoc TL) { |
| 3784 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3785 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3786 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3787 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3789 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3790 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3791 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3792 | if (PointeeType.isNull()) |
| 3793 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3794 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3795 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3796 | TypeSourceInfo* NewClsTInfo = 0; |
| 3797 | if (OldClsTInfo) { |
| 3798 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3799 | if (!NewClsTInfo) |
| 3800 | return QualType(); |
| 3801 | } |
| 3802 | |
| 3803 | const MemberPointerType *T = TL.getTypePtr(); |
| 3804 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3805 | QualType NewClsType; |
| 3806 | if (NewClsTInfo) |
| 3807 | NewClsType = NewClsTInfo->getType(); |
| 3808 | else { |
| 3809 | NewClsType = getDerived().TransformType(OldClsType); |
| 3810 | if (NewClsType.isNull()) |
| 3811 | return QualType(); |
| 3812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3814 | QualType Result = TL.getType(); |
| 3815 | if (getDerived().AlwaysRebuild() || |
| 3816 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3817 | NewClsType != OldClsType) { |
| 3818 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3819 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3820 | if (Result.isNull()) |
| 3821 | return QualType(); |
| 3822 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3823 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3824 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3825 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3826 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3827 | |
| 3828 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3829 | } |
| 3830 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3831 | template<typename Derived> |
| 3832 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3833 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3834 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3835 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3836 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3837 | if (ElementType.isNull()) |
| 3838 | return QualType(); |
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 | QualType Result = TL.getType(); |
| 3841 | if (getDerived().AlwaysRebuild() || |
| 3842 | ElementType != T->getElementType()) { |
| 3843 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3844 | T->getSizeModifier(), |
| 3845 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3846 | T->getIndexTypeCVRQualifiers(), |
| 3847 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3848 | if (Result.isNull()) |
| 3849 | return QualType(); |
| 3850 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3851 | |
| 3852 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3853 | // a ConstantArrayType is allowed to have an element type which is a |
| 3854 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3855 | // types have the same location layout. |
| 3856 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3857 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3858 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3859 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3860 | Expr *Size = TL.getSizeExpr(); |
| 3861 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3862 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3863 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3864 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3865 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3866 | } |
| 3867 | NewTL.setSizeExpr(Size); |
| 3868 | |
| 3869 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3872 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3873 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3874 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3875 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3876 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3877 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3878 | if (ElementType.isNull()) |
| 3879 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3880 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3881 | QualType Result = TL.getType(); |
| 3882 | if (getDerived().AlwaysRebuild() || |
| 3883 | ElementType != T->getElementType()) { |
| 3884 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3885 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3886 | T->getIndexTypeCVRQualifiers(), |
| 3887 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3888 | if (Result.isNull()) |
| 3889 | return QualType(); |
| 3890 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3891 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3892 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3893 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3894 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3895 | NewTL.setSizeExpr(0); |
| 3896 | |
| 3897 | return Result; |
| 3898 | } |
| 3899 | |
| 3900 | template<typename Derived> |
| 3901 | QualType |
| 3902 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3903 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3904 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3905 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3906 | if (ElementType.isNull()) |
| 3907 | return QualType(); |
| 3908 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3909 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3910 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3911 | if (SizeResult.isInvalid()) |
| 3912 | return QualType(); |
| 3913 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3914 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3915 | |
| 3916 | QualType Result = TL.getType(); |
| 3917 | if (getDerived().AlwaysRebuild() || |
| 3918 | ElementType != T->getElementType() || |
| 3919 | Size != T->getSizeExpr()) { |
| 3920 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3921 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3922 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3923 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3924 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3925 | if (Result.isNull()) |
| 3926 | return QualType(); |
| 3927 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3928 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3929 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3930 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3931 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3932 | NewTL.setSizeExpr(Size); |
| 3933 | |
| 3934 | return Result; |
| 3935 | } |
| 3936 | |
| 3937 | template<typename Derived> |
| 3938 | QualType |
| 3939 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3940 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3941 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3942 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3943 | if (ElementType.isNull()) |
| 3944 | return QualType(); |
| 3945 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3946 | // Array bounds are constant expressions. |
| 3947 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3948 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3949 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3950 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3951 | Expr *origSize = TL.getSizeExpr(); |
| 3952 | if (!origSize) origSize = T->getSizeExpr(); |
| 3953 | |
| 3954 | ExprResult sizeResult |
| 3955 | = getDerived().TransformExpr(origSize); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3956 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3957 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3958 | return QualType(); |
| 3959 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3960 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3961 | |
| 3962 | QualType Result = TL.getType(); |
| 3963 | if (getDerived().AlwaysRebuild() || |
| 3964 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3965 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3966 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3967 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3968 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3969 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3970 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3971 | if (Result.isNull()) |
| 3972 | return QualType(); |
| 3973 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3974 | |
| 3975 | // We might have any sort of array type now, but fortunately they |
| 3976 | // all have the same location layout. |
| 3977 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3978 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3979 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3980 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3981 | |
| 3982 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3983 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3984 | |
| 3985 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3986 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3987 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3988 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3989 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3990 | |
| 3991 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3992 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3993 | if (ElementType.isNull()) |
| 3994 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3995 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3996 | // Vector sizes are constant expressions. |
| 3997 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3998 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3999 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4000 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4001 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4002 | if (Size.isInvalid()) |
| 4003 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4004 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4005 | QualType Result = TL.getType(); |
| 4006 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4007 | ElementType != T->getElementType() || |
| 4008 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4009 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4010 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4011 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4012 | if (Result.isNull()) |
| 4013 | return QualType(); |
| 4014 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4015 | |
| 4016 | // Result might be dependent or not. |
| 4017 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4018 | DependentSizedExtVectorTypeLoc NewTL |
| 4019 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4020 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4021 | } else { |
| 4022 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4023 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4024 | } |
| 4025 | |
| 4026 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4027 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
| 4029 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4030 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4031 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4032 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4033 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4034 | if (ElementType.isNull()) |
| 4035 | return QualType(); |
| 4036 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4037 | QualType Result = TL.getType(); |
| 4038 | if (getDerived().AlwaysRebuild() || |
| 4039 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4040 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4041 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4042 | if (Result.isNull()) |
| 4043 | return QualType(); |
| 4044 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4045 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4046 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4047 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4048 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4049 | return Result; |
| 4050 | } |
| 4051 | |
| 4052 | template<typename Derived> |
| 4053 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4054 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4055 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4056 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4057 | if (ElementType.isNull()) |
| 4058 | return QualType(); |
| 4059 | |
| 4060 | QualType Result = TL.getType(); |
| 4061 | if (getDerived().AlwaysRebuild() || |
| 4062 | ElementType != T->getElementType()) { |
| 4063 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4064 | T->getNumElements(), |
| 4065 | /*FIXME*/ SourceLocation()); |
| 4066 | if (Result.isNull()) |
| 4067 | return QualType(); |
| 4068 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4069 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4070 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4071 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4072 | |
| 4073 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4074 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4076 | template <typename Derived> |
| 4077 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4078 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4079 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4080 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4081 | TypeSourceInfo *NewDI = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4082 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4083 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4084 | // 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] | 4085 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4086 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4087 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4088 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4089 | TypeLocBuilder TLB; |
| 4090 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4091 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4092 | |
| 4093 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4094 | OldExpansionTL.getPatternLoc()); |
| 4095 | if (Result.isNull()) |
| 4096 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4097 | |
| 4098 | Result = RebuildPackExpansionType(Result, |
| 4099 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4100 | OldExpansionTL.getEllipsisLoc(), |
| 4101 | NumExpansions); |
| 4102 | if (Result.isNull()) |
| 4103 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4104 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4105 | PackExpansionTypeLoc NewExpansionTL |
| 4106 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4107 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4108 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4109 | } else |
| 4110 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4111 | if (!NewDI) |
| 4112 | return 0; |
| 4113 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4114 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4115 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4116 | |
| 4117 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4118 | OldParm->getDeclContext(), |
| 4119 | OldParm->getInnerLocStart(), |
| 4120 | OldParm->getLocation(), |
| 4121 | OldParm->getIdentifier(), |
| 4122 | NewDI->getType(), |
| 4123 | NewDI, |
| 4124 | OldParm->getStorageClass(), |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4125 | /* DefArg */ NULL); |
| 4126 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4127 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4128 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | template<typename Derived> |
| 4132 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4133 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4134 | ParmVarDecl **Params, unsigned NumParams, |
| 4135 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4136 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4137 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4138 | int indexAdjustment = 0; |
| 4139 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4140 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4141 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4142 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4143 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4144 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4145 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4146 | if (OldParm->isParameterPack()) { |
| 4147 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4148 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4149 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4150 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4151 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4152 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4153 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4154 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4155 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4156 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4157 | // Determine whether we should expand the parameter packs. |
| 4158 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4159 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4160 | Optional<unsigned> OrigNumExpansions = |
| 4161 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4162 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4163 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4164 | Pattern.getSourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4165 | Unexpanded, |
| 4166 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4167 | RetainExpansion, |
| 4168 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4169 | return true; |
| 4170 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4171 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4172 | if (ShouldExpand) { |
| 4173 | // Expand the function parameter pack into multiple, separate |
| 4174 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4175 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4176 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4177 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4178 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4179 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4180 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4181 | OrigNumExpansions, |
| 4182 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4183 | if (!NewParm) |
| 4184 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4185 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4186 | OutParamTypes.push_back(NewParm->getType()); |
| 4187 | if (PVars) |
| 4188 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4189 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4190 | |
| 4191 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4192 | // forgetting the partially-substituted parameter pack. |
| 4193 | if (RetainExpansion) { |
| 4194 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4195 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4196 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4197 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4198 | OrigNumExpansions, |
| 4199 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4200 | if (!NewParm) |
| 4201 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4202 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4203 | OutParamTypes.push_back(NewParm->getType()); |
| 4204 | if (PVars) |
| 4205 | PVars->push_back(NewParm); |
| 4206 | } |
| 4207 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4208 | // The next parameter should have the same adjustment as the |
| 4209 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4210 | // on every push. Also, if we push nothing, the adjustment should |
| 4211 | // go down by one. |
| 4212 | indexAdjustment--; |
| 4213 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4214 | // We're done with the pack expansion. |
| 4215 | continue; |
| 4216 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4217 | |
| 4218 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4219 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4220 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4221 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4222 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4223 | NumExpansions, |
| 4224 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4225 | } else { |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4226 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4227 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4228 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4229 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4230 | if (!NewParm) |
| 4231 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4232 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4233 | OutParamTypes.push_back(NewParm->getType()); |
| 4234 | if (PVars) |
| 4235 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4236 | continue; |
| 4237 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4238 | |
| 4239 | // Deal with the possibility that we don't have a parameter |
| 4240 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4241 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4242 | bool IsPackExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4243 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4244 | QualType NewType; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4245 | if (const PackExpansionType *Expansion |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4246 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4247 | // We have a function parameter pack that may need to be expanded. |
| 4248 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4249 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4250 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4251 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4252 | // Determine whether we should expand the parameter packs. |
| 4253 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4254 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4255 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4256 | Unexpanded, |
| 4257 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4258 | RetainExpansion, |
| 4259 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4260 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4261 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4263 | if (ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4264 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4265 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4266 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4267 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4268 | QualType NewType = getDerived().TransformType(Pattern); |
| 4269 | if (NewType.isNull()) |
| 4270 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4271 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4272 | OutParamTypes.push_back(NewType); |
| 4273 | if (PVars) |
| 4274 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4275 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4276 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4277 | // We're done with the pack expansion. |
| 4278 | continue; |
| 4279 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4281 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4282 | // forgetting the partially-substituted parameter pack. |
| 4283 | if (RetainExpansion) { |
| 4284 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4285 | QualType NewType = getDerived().TransformType(Pattern); |
| 4286 | if (NewType.isNull()) |
| 4287 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4289 | OutParamTypes.push_back(NewType); |
| 4290 | if (PVars) |
| 4291 | PVars->push_back(0); |
| 4292 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4293 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4294 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4295 | // expansion. |
| 4296 | OldType = Expansion->getPattern(); |
| 4297 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4298 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4299 | NewType = getDerived().TransformType(OldType); |
| 4300 | } else { |
| 4301 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4302 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4304 | if (NewType.isNull()) |
| 4305 | return true; |
| 4306 | |
| 4307 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4308 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4309 | NumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4310 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4311 | OutParamTypes.push_back(NewType); |
| 4312 | if (PVars) |
| 4313 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4314 | } |
| 4315 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4316 | #ifndef NDEBUG |
| 4317 | if (PVars) { |
| 4318 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4319 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4320 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4321 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4322 | #endif |
| 4323 | |
| 4324 | return false; |
| 4325 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4326 | |
| 4327 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4328 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4329 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4330 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4331 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4332 | } |
| 4333 | |
| 4334 | template<typename Derived> |
| 4335 | QualType |
| 4336 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4337 | FunctionProtoTypeLoc TL, |
| 4338 | CXXRecordDecl *ThisContext, |
| 4339 | unsigned ThisTypeQuals) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4340 | // Transform the parameters and return type. |
| 4341 | // |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4342 | // 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] | 4343 | // When the function has a trailing return type, we instantiate the |
| 4344 | // parameters before the return type, since the return type can then refer |
| 4345 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4346 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4347 | SmallVector<QualType, 4> ParamTypes; |
| 4348 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4349 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4350 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4351 | QualType ResultType; |
| 4352 | |
Richard Smith | 9fbf327 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4353 | if (T->hasTrailingReturn()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4354 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4355 | TL.getParmArray(), |
| 4356 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4357 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4358 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4359 | return QualType(); |
| 4360 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4361 | { |
| 4362 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4363 | // If a declaration declares a member function or member function |
| 4364 | // 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] | 4365 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4366 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4367 | // declarator. |
| 4368 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4369 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4370 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4371 | if (ResultType.isNull()) |
| 4372 | return QualType(); |
| 4373 | } |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4374 | } |
| 4375 | else { |
| 4376 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4377 | if (ResultType.isNull()) |
| 4378 | return QualType(); |
| 4379 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4380 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4381 | TL.getParmArray(), |
| 4382 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4383 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4384 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4385 | return QualType(); |
| 4386 | } |
| 4387 | |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4388 | // FIXME: Need to transform the exception-specification too. |
| 4389 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4390 | QualType Result = TL.getType(); |
| 4391 | if (getDerived().AlwaysRebuild() || |
| 4392 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4393 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4394 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4395 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4396 | T->getExtProtoInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4397 | if (Result.isNull()) |
| 4398 | return QualType(); |
| 4399 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4400 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4401 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4402 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4403 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4404 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4405 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4406 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4407 | NewTL.setArg(i, ParamDecls[i]); |
| 4408 | |
| 4409 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4410 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4412 | template<typename Derived> |
| 4413 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4414 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4415 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4416 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4417 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4418 | if (ResultType.isNull()) |
| 4419 | return QualType(); |
| 4420 | |
| 4421 | QualType Result = TL.getType(); |
| 4422 | if (getDerived().AlwaysRebuild() || |
| 4423 | ResultType != T->getResultType()) |
| 4424 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4425 | |
| 4426 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4427 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4428 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4429 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4430 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4431 | |
| 4432 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4433 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4435 | template<typename Derived> QualType |
| 4436 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4437 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4438 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4439 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4440 | if (!D) |
| 4441 | return QualType(); |
| 4442 | |
| 4443 | QualType Result = TL.getType(); |
| 4444 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4445 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4446 | if (Result.isNull()) |
| 4447 | return QualType(); |
| 4448 | } |
| 4449 | |
| 4450 | // We might get an arbitrary type spec type back. We should at |
| 4451 | // least always get a type spec type, though. |
| 4452 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4453 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4454 | |
| 4455 | return Result; |
| 4456 | } |
| 4457 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4458 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4459 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4460 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4461 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4462 | TypedefNameDecl *Typedef |
| 4463 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4464 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4465 | if (!Typedef) |
| 4466 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4468 | QualType Result = TL.getType(); |
| 4469 | if (getDerived().AlwaysRebuild() || |
| 4470 | Typedef != T->getDecl()) { |
| 4471 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4472 | if (Result.isNull()) |
| 4473 | return QualType(); |
| 4474 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4475 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4476 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4477 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4478 | |
| 4479 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4481 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4482 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4483 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4484 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4485 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4486 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4487 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4488 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4489 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4490 | if (E.isInvalid()) |
| 4491 | return QualType(); |
| 4492 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4493 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4494 | if (E.isInvalid()) |
| 4495 | return QualType(); |
| 4496 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4497 | QualType Result = TL.getType(); |
| 4498 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4499 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4500 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4501 | if (Result.isNull()) |
| 4502 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4503 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4504 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4506 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4507 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4508 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4509 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4510 | |
| 4511 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
| 4514 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4515 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4516 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4517 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4518 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4519 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4520 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4521 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4522 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4523 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4524 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4525 | if (Result.isNull()) |
| 4526 | return QualType(); |
| 4527 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4528 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4529 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4530 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4531 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4532 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4533 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4534 | |
| 4535 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4536 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4537 | |
| 4538 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4539 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4540 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4541 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4543 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4544 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4545 | /*IsDecltype=*/ true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4546 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4547 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4548 | if (E.isInvalid()) |
| 4549 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4551 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4552 | if (E.isInvalid()) |
| 4553 | return QualType(); |
| 4554 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4555 | QualType Result = TL.getType(); |
| 4556 | if (getDerived().AlwaysRebuild() || |
| 4557 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4558 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4559 | if (Result.isNull()) |
| 4560 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4561 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4562 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4563 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4564 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4565 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4566 | |
| 4567 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4571 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4572 | TypeLocBuilder &TLB, |
| 4573 | UnaryTransformTypeLoc TL) { |
| 4574 | QualType Result = TL.getType(); |
| 4575 | if (Result->isDependentType()) { |
| 4576 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4577 | QualType NewBase = |
| 4578 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4579 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4580 | T->getUTTKind(), |
| 4581 | TL.getKWLoc()); |
| 4582 | if (Result.isNull()) |
| 4583 | return QualType(); |
| 4584 | } |
| 4585 | |
| 4586 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4587 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4588 | NewTL.setParensRange(TL.getParensRange()); |
| 4589 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4590 | return Result; |
| 4591 | } |
| 4592 | |
| 4593 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4594 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4595 | AutoTypeLoc TL) { |
| 4596 | const AutoType *T = TL.getTypePtr(); |
| 4597 | QualType OldDeduced = T->getDeducedType(); |
| 4598 | QualType NewDeduced; |
| 4599 | if (!OldDeduced.isNull()) { |
| 4600 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4601 | if (NewDeduced.isNull()) |
| 4602 | return QualType(); |
| 4603 | } |
| 4604 | |
| 4605 | QualType Result = TL.getType(); |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4606 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4607 | T->isDependentType()) { |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4608 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4609 | if (Result.isNull()) |
| 4610 | return QualType(); |
| 4611 | } |
| 4612 | |
| 4613 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4614 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4615 | |
| 4616 | return Result; |
| 4617 | } |
| 4618 | |
| 4619 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4620 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4621 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4622 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4623 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4624 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4625 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4626 | if (!Record) |
| 4627 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4628 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4629 | QualType Result = TL.getType(); |
| 4630 | if (getDerived().AlwaysRebuild() || |
| 4631 | Record != T->getDecl()) { |
| 4632 | Result = getDerived().RebuildRecordType(Record); |
| 4633 | if (Result.isNull()) |
| 4634 | return QualType(); |
| 4635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4636 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4637 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4638 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4639 | |
| 4640 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4642 | |
| 4643 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4644 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4645 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4646 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4647 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4648 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4649 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4650 | if (!Enum) |
| 4651 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4652 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4653 | QualType Result = TL.getType(); |
| 4654 | if (getDerived().AlwaysRebuild() || |
| 4655 | Enum != T->getDecl()) { |
| 4656 | Result = getDerived().RebuildEnumType(Enum); |
| 4657 | if (Result.isNull()) |
| 4658 | return QualType(); |
| 4659 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4660 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4661 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4662 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4663 | |
| 4664 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4665 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4666 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4667 | template<typename Derived> |
| 4668 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4669 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4670 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4671 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4672 | TL.getTypePtr()->getDecl()); |
| 4673 | if (!D) return QualType(); |
| 4674 | |
| 4675 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4676 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4677 | return T; |
| 4678 | } |
| 4679 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4680 | template<typename Derived> |
| 4681 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4682 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4683 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4684 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4685 | } |
| 4686 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4688 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4689 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4690 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4691 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4692 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4693 | // Substitute into the replacement type, which itself might involve something |
| 4694 | // that needs to be transformed. This only tends to occur with default |
| 4695 | // template arguments of template template parameters. |
| 4696 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4697 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4698 | if (Replacement.isNull()) |
| 4699 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4701 | // Always canonicalize the replacement type. |
| 4702 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4703 | QualType Result |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4704 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4705 | Replacement); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4706 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4707 | // Propagate type-source information. |
| 4708 | SubstTemplateTypeParmTypeLoc NewTL |
| 4709 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4710 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4711 | return Result; |
| 4712 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4716 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4717 | TypeLocBuilder &TLB, |
| 4718 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4719 | return TransformTypeSpecType(TLB, TL); |
| 4720 | } |
| 4721 | |
| 4722 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4723 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4724 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4725 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4726 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4727 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4728 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4729 | // because we can't have a dependent nested-name-specifier anyway. |
| 4730 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4732 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4733 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4734 | if (Template.isNull()) |
| 4735 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4736 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4737 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4738 | } |
| 4739 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4740 | template<typename Derived> |
| 4741 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4742 | AtomicTypeLoc TL) { |
| 4743 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4744 | if (ValueType.isNull()) |
| 4745 | return QualType(); |
| 4746 | |
| 4747 | QualType Result = TL.getType(); |
| 4748 | if (getDerived().AlwaysRebuild() || |
| 4749 | ValueType != TL.getValueLoc().getType()) { |
| 4750 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4751 | if (Result.isNull()) |
| 4752 | return QualType(); |
| 4753 | } |
| 4754 | |
| 4755 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4756 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4757 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4758 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4759 | |
| 4760 | return Result; |
| 4761 | } |
| 4762 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4763 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4764 | /// container that provides a \c getArgLoc() member function. |
| 4765 | /// |
| 4766 | /// This iterator is intended to be used with the iterator form of |
| 4767 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4768 | template<typename ArgLocContainer> |
| 4769 | class TemplateArgumentLocContainerIterator { |
| 4770 | ArgLocContainer *Container; |
| 4771 | unsigned Index; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4773 | public: |
| 4774 | typedef TemplateArgumentLoc value_type; |
| 4775 | typedef TemplateArgumentLoc reference; |
| 4776 | typedef int difference_type; |
| 4777 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4778 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4779 | class pointer { |
| 4780 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4781 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4782 | public: |
| 4783 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4784 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4785 | const TemplateArgumentLoc *operator->() const { |
| 4786 | return &Arg; |
| 4787 | } |
| 4788 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4789 | |
| 4790 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4791 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4792 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4793 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4794 | unsigned Index) |
| 4795 | : Container(&Container), Index(Index) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4797 | TemplateArgumentLocContainerIterator &operator++() { |
| 4798 | ++Index; |
| 4799 | return *this; |
| 4800 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4802 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4803 | TemplateArgumentLocContainerIterator Old(*this); |
| 4804 | ++(*this); |
| 4805 | return Old; |
| 4806 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4807 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4808 | TemplateArgumentLoc operator*() const { |
| 4809 | return Container->getArgLoc(Index); |
| 4810 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4811 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4812 | pointer operator->() const { |
| 4813 | return pointer(Container->getArgLoc(Index)); |
| 4814 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4815 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4816 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4817 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4818 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4819 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4820 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4821 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4822 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4823 | return !(X == Y); |
| 4824 | } |
| 4825 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4826 | |
| 4827 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4828 | template <typename Derived> |
| 4829 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4830 | TypeLocBuilder &TLB, |
| 4831 | TemplateSpecializationTypeLoc TL, |
| 4832 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4833 | TemplateArgumentListInfo NewTemplateArgs; |
| 4834 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4835 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4836 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4837 | ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4838 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4839 | ArgIterator(TL, TL.getNumArgs()), |
| 4840 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4841 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4843 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4844 | |
| 4845 | QualType Result = |
| 4846 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4847 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4848 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4849 | |
| 4850 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4851 | // Specializations of template template parameters are represented as |
| 4852 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4853 | // within a dependent context can transform them into |
| 4854 | // DependentTemplateSpecializationTypes. |
| 4855 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4856 | DependentTemplateSpecializationTypeLoc NewTL |
| 4857 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4858 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4859 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4860 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4861 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4862 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4863 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4864 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4865 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4866 | return Result; |
| 4867 | } |
| 4868 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4869 | TemplateSpecializationTypeLoc NewTL |
| 4870 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4871 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4872 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4873 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4874 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4875 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4876 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4877 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4878 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4879 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4880 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4881 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4882 | template <typename Derived> |
| 4883 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4884 | TypeLocBuilder &TLB, |
| 4885 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4886 | TemplateName Template, |
| 4887 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4888 | TemplateArgumentListInfo NewTemplateArgs; |
| 4889 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4890 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4891 | typedef TemplateArgumentLocContainerIterator< |
| 4892 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4893 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4894 | ArgIterator(TL, TL.getNumArgs()), |
| 4895 | NewTemplateArgs)) |
| 4896 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4897 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4898 | // 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] | 4899 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4900 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4901 | QualType Result |
| 4902 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4903 | TL.getTypePtr()->getKeyword(), |
| 4904 | DTN->getQualifier(), |
| 4905 | DTN->getIdentifier(), |
| 4906 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4907 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4908 | DependentTemplateSpecializationTypeLoc NewTL |
| 4909 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4910 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4911 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4912 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4913 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4914 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4915 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4916 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4917 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4918 | return Result; |
| 4919 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4920 | |
| 4921 | QualType Result |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4922 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4923 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4924 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4925 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4926 | if (!Result.isNull()) { |
| 4927 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4928 | TemplateSpecializationTypeLoc NewTL |
| 4929 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4930 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4931 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4932 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4933 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4934 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4935 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4936 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4938 | return Result; |
| 4939 | } |
| 4940 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4942 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4943 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4944 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4945 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4947 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4948 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4949 | if (TL.getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4950 | QualifierLoc |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4951 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4952 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4953 | return QualType(); |
| 4954 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4955 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4956 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4957 | if (NamedT.isNull()) |
| 4958 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4959 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4960 | // C++0x [dcl.type.elab]p2: |
| 4961 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4962 | // resolves to an alias template specialization, the |
| 4963 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4964 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4965 | if (const TemplateSpecializationType *TST = |
| 4966 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4967 | TemplateName Template = TST->getTemplateName(); |
| 4968 | if (TypeAliasTemplateDecl *TAT = |
| 4969 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4970 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4971 | diag::err_tag_reference_non_tag) << 4; |
| 4972 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4973 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4974 | } |
| 4975 | } |
| 4976 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4977 | QualType Result = TL.getType(); |
| 4978 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4979 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4980 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4981 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4982 | T->getKeyword(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4983 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4984 | if (Result.isNull()) |
| 4985 | return QualType(); |
| 4986 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4987 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4988 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4989 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4990 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4991 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4992 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | |
| 4994 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4995 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4996 | TypeLocBuilder &TLB, |
| 4997 | AttributedTypeLoc TL) { |
| 4998 | const AttributedType *oldType = TL.getTypePtr(); |
| 4999 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5000 | if (modifiedType.isNull()) |
| 5001 | return QualType(); |
| 5002 | |
| 5003 | QualType result = TL.getType(); |
| 5004 | |
| 5005 | // FIXME: dependent operand expressions? |
| 5006 | if (getDerived().AlwaysRebuild() || |
| 5007 | modifiedType != oldType->getModifiedType()) { |
| 5008 | // TODO: this is really lame; we should really be rebuilding the |
| 5009 | // equivalent type from first principles. |
| 5010 | QualType equivalentType |
| 5011 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5012 | if (equivalentType.isNull()) |
| 5013 | return QualType(); |
| 5014 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5015 | modifiedType, |
| 5016 | equivalentType); |
| 5017 | } |
| 5018 | |
| 5019 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5020 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5021 | if (TL.hasAttrOperand()) |
| 5022 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5023 | if (TL.hasAttrExprOperand()) |
| 5024 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5025 | else if (TL.hasAttrEnumOperand()) |
| 5026 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5027 | |
| 5028 | return result; |
| 5029 | } |
| 5030 | |
| 5031 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5032 | QualType |
| 5033 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5034 | ParenTypeLoc TL) { |
| 5035 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5036 | if (Inner.isNull()) |
| 5037 | return QualType(); |
| 5038 | |
| 5039 | QualType Result = TL.getType(); |
| 5040 | if (getDerived().AlwaysRebuild() || |
| 5041 | Inner != TL.getInnerLoc().getType()) { |
| 5042 | Result = getDerived().RebuildParenType(Inner); |
| 5043 | if (Result.isNull()) |
| 5044 | return QualType(); |
| 5045 | } |
| 5046 | |
| 5047 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5048 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5049 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5050 | return Result; |
| 5051 | } |
| 5052 | |
| 5053 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5054 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5055 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5056 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5057 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5058 | NestedNameSpecifierLoc QualifierLoc |
| 5059 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5060 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5061 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5063 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5064 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5065 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5066 | QualifierLoc, |
| 5067 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5068 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5069 | if (Result.isNull()) |
| 5070 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5071 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5072 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5073 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5074 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5075 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5076 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5077 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5078 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5079 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5080 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5081 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5082 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5083 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5084 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5085 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5088 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5089 | QualType TreeTransform<Derived>:: |
| 5090 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5091 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5092 | NestedNameSpecifierLoc QualifierLoc; |
| 5093 | if (TL.getQualifierLoc()) { |
| 5094 | QualifierLoc |
| 5095 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5096 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5097 | return QualType(); |
| 5098 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5099 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5100 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5101 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | template<typename Derived> |
| 5105 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5106 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5107 | DependentTemplateSpecializationTypeLoc TL, |
| 5108 | NestedNameSpecifierLoc QualifierLoc) { |
| 5109 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5110 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5111 | TemplateArgumentListInfo NewTemplateArgs; |
| 5112 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5113 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5115 | typedef TemplateArgumentLocContainerIterator< |
| 5116 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5117 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5118 | ArgIterator(TL, TL.getNumArgs()), |
| 5119 | NewTemplateArgs)) |
| 5120 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5121 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5122 | QualType Result |
| 5123 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5124 | QualifierLoc, |
| 5125 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5126 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5127 | NewTemplateArgs); |
| 5128 | if (Result.isNull()) |
| 5129 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5131 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5132 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5133 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5134 | // Copy information relevant to the template specialization. |
| 5135 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5136 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5137 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5138 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5139 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5140 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5141 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5142 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5143 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5144 | // Copy information relevant to the elaborated type. |
| 5145 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5146 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5147 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5148 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5149 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5150 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5151 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5152 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5153 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5154 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5155 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5156 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5157 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5158 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5159 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5160 | TemplateSpecializationTypeLoc SpecTL |
| 5161 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5162 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5163 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5164 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5165 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5166 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5167 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5168 | } |
| 5169 | return Result; |
| 5170 | } |
| 5171 | |
| 5172 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5173 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5174 | PackExpansionTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5175 | QualType Pattern |
| 5176 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5177 | if (Pattern.isNull()) |
| 5178 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5179 | |
| 5180 | QualType Result = TL.getType(); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5181 | if (getDerived().AlwaysRebuild() || |
| 5182 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5183 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5184 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5185 | TL.getEllipsisLoc(), |
| 5186 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5187 | if (Result.isNull()) |
| 5188 | return QualType(); |
| 5189 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5190 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5191 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5192 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5193 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5197 | QualType |
| 5198 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5199 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5200 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5201 | TLB.pushFullCopy(TL); |
| 5202 | return TL.getType(); |
| 5203 | } |
| 5204 | |
| 5205 | template<typename Derived> |
| 5206 | QualType |
| 5207 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5208 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5209 | // ObjCObjectType is never dependent. |
| 5210 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5211 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | |
| 5214 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5215 | QualType |
| 5216 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5217 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5218 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5219 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5220 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5221 | } |
| 5222 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5223 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5224 | // Statement transformation |
| 5225 | //===----------------------------------------------------------------------===// |
| 5226 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5227 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5229 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5233 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5234 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5235 | return getDerived().TransformCompoundStmt(S, false); |
| 5236 | } |
| 5237 | |
| 5238 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5239 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5240 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5241 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5242 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5243 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5244 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5245 | bool SubStmtChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5246 | SmallVector<Stmt*, 8> Statements; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5247 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5248 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5249 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5250 | if (Result.isInvalid()) { |
| 5251 | // Immediately fail if this was a DeclStmt, since it's very |
| 5252 | // likely that this will cause problems for future statements. |
| 5253 | if (isa<DeclStmt>(*B)) |
| 5254 | return StmtError(); |
| 5255 | |
| 5256 | // Otherwise, just keep processing substatements and fail later. |
| 5257 | SubStmtInvalid = true; |
| 5258 | continue; |
| 5259 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5261 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5262 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5263 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5265 | if (SubStmtInvalid) |
| 5266 | return StmtError(); |
| 5267 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5268 | if (!getDerived().AlwaysRebuild() && |
| 5269 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5270 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5271 | |
| 5272 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5273 | Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5274 | S->getRBracLoc(), |
| 5275 | IsStmtExpr); |
| 5276 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5278 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5279 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5280 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5281 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5282 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5283 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5284 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5285 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5286 | // Transform the left-hand case value. |
| 5287 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5288 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5289 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5290 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5291 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5292 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5293 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5294 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5295 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5296 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5297 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5298 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5299 | // Build the case statement. |
| 5300 | // Case statements are always rebuilt so that they will attached to their |
| 5301 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5302 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5303 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5304 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5305 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5306 | S->getColonLoc()); |
| 5307 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5308 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5309 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5310 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5311 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5312 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5313 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5314 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5315 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5316 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5320 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5321 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5322 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5323 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5324 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5325 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5327 | // Default statements are always rebuilt |
| 5328 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5329 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5330 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5332 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5333 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5334 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5335 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5336 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5337 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5339 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5340 | S->getDecl()); |
| 5341 | if (!LD) |
| 5342 | return StmtError(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5343 | |
| 5344 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5345 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5346 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5347 | cast<LabelDecl>(LD), SourceLocation(), |
| 5348 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5351 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5352 | StmtResult |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5353 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5354 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5355 | if (SubStmt.isInvalid()) |
| 5356 | return StmtError(); |
| 5357 | |
| 5358 | // TODO: transform attributes |
| 5359 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5360 | return S; |
| 5361 | |
| 5362 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5363 | S->getAttrs(), |
| 5364 | SubStmt.get()); |
| 5365 | } |
| 5366 | |
| 5367 | template<typename Derived> |
| 5368 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5369 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5370 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5371 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5372 | VarDecl *ConditionVar = 0; |
| 5373 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5374 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5375 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5376 | getDerived().TransformDefinition( |
| 5377 | S->getConditionVariable()->getLocation(), |
| 5378 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5379 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5380 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5381 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5382 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5383 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5384 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5385 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5386 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5387 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5388 | if (S->getCond()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5389 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5390 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5391 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5392 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5393 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5394 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5395 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5396 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5397 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5398 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5399 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5400 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5401 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5402 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5403 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5404 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5405 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5406 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5407 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5408 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5409 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5410 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5412 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5413 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5414 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5415 | Then.get() == S->getThen() && |
| 5416 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5417 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5419 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5420 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5421 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5425 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5426 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5427 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5428 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5429 | VarDecl *ConditionVar = 0; |
| 5430 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5431 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5432 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5433 | getDerived().TransformDefinition( |
| 5434 | S->getConditionVariable()->getLocation(), |
| 5435 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5436 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5437 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5438 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5439 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5440 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5441 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5442 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5443 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5445 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5446 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5447 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5448 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5449 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5450 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5451 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5452 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5453 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5454 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5455 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5457 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5458 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5459 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5461 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5462 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5463 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5464 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5465 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5466 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5467 | VarDecl *ConditionVar = 0; |
| 5468 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5469 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5470 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5471 | getDerived().TransformDefinition( |
| 5472 | S->getConditionVariable()->getLocation(), |
| 5473 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5474 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5475 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5476 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5477 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5478 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5479 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5480 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5481 | |
| 5482 | if (S->getCond()) { |
| 5483 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5484 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5485 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5486 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5487 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5488 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5489 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5490 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5491 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5492 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5493 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5494 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5495 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5496 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5497 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5498 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5499 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5500 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5501 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5502 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5503 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5504 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5505 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5507 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5508 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5509 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5510 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5511 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5512 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5513 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5514 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5515 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5516 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5517 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5519 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5520 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5521 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5522 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5523 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5524 | if (!getDerived().AlwaysRebuild() && |
| 5525 | Cond.get() == S->getCond() && |
| 5526 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5527 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5528 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5529 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5530 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5531 | S->getRParenLoc()); |
| 5532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5533 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5534 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5535 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5536 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5537 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5538 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5539 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5540 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5541 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5542 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5543 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5544 | VarDecl *ConditionVar = 0; |
| 5545 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5546 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5547 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5548 | getDerived().TransformDefinition( |
| 5549 | S->getConditionVariable()->getLocation(), |
| 5550 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5551 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5552 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5553 | } else { |
| 5554 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5555 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5556 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5557 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5558 | |
| 5559 | if (S->getCond()) { |
| 5560 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5561 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5562 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5563 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5564 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5565 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5566 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5567 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5568 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5569 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5570 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5571 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5572 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5573 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5574 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5575 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5576 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5577 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5578 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5579 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5580 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5581 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5582 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5583 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5584 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5585 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5586 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5587 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5588 | if (!getDerived().AlwaysRebuild() && |
| 5589 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5590 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5591 | Inc.get() == S->getInc() && |
| 5592 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5593 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5595 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5596 | Init.get(), FullCond, ConditionVar, |
| 5597 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5598 | } |
| 5599 | |
| 5600 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5601 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5602 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5603 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5604 | S->getLabel()); |
| 5605 | if (!LD) |
| 5606 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5608 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5610 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5614 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5616 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5617 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5618 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5619 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5621 | if (!getDerived().AlwaysRebuild() && |
| 5622 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5623 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5624 | |
| 5625 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5626 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5630 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5632 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5635 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5636 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5638 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5640 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5641 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5642 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5644 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5645 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5646 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5647 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5648 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5649 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5650 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5653 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5654 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5655 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5656 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5657 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5658 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5659 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5660 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5661 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5662 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5663 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5665 | if (Transformed != *D) |
| 5666 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5668 | Decls.push_back(Transformed); |
| 5669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5671 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5672 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5673 | |
Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5674 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5675 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5677 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5678 | StmtResult |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5679 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5680 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5681 | SmallVector<Expr*, 8> Constraints; |
| 5682 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5683 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5684 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5685 | ExprResult AsmString; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5686 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5687 | |
| 5688 | bool ExprsChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5689 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5690 | // Go through the outputs. |
| 5691 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5692 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5693 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5694 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5695 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5696 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5697 | // Transform the output expr. |
| 5698 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5699 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5700 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5701 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5702 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5703 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5704 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5705 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5706 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5707 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5708 | // Go through the inputs. |
| 5709 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5710 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5711 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5712 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5713 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5714 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5715 | // Transform the input expr. |
| 5716 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5717 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5718 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5719 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5720 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5721 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5722 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5723 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5724 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5725 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5726 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5727 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5728 | |
| 5729 | // Go through the clobbers. |
| 5730 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | 5c7f594 | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5731 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5732 | |
| 5733 | // No need to transform the asm string literal. |
| 5734 | AsmString = SemaRef.Owned(S->getAsmString()); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5735 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5736 | S->isVolatile(), S->getNumOutputs(), |
| 5737 | S->getNumInputs(), Names.data(), |
| 5738 | Constraints, Exprs, AsmString.get(), |
| 5739 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5740 | } |
| 5741 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5742 | template<typename Derived> |
| 5743 | StmtResult |
| 5744 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5745 | ArrayRef<Token> AsmToks = |
| 5746 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5747 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5748 | bool HadError = false, HadChange = false; |
| 5749 | |
| 5750 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5751 | SmallVector<Expr*, 8> TransformedExprs; |
| 5752 | TransformedExprs.reserve(SrcExprs.size()); |
| 5753 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5754 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5755 | if (!Result.isUsable()) { |
| 5756 | HadError = true; |
| 5757 | } else { |
| 5758 | HadChange |= (Result.get() != SrcExprs[i]); |
| 5759 | TransformedExprs.push_back(Result.take()); |
| 5760 | } |
| 5761 | } |
| 5762 | |
| 5763 | if (HadError) return StmtError(); |
| 5764 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 5765 | return Owned(S); |
| 5766 | |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5767 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5768 | AsmToks, S->getAsmString(), |
| 5769 | S->getNumOutputs(), S->getNumInputs(), |
| 5770 | S->getAllConstraints(), S->getClobbers(), |
| 5771 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5772 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5773 | |
| 5774 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5775 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5776 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5777 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5778 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5779 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5780 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5781 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5782 | // Transform the @catch statements (if present). |
| 5783 | bool AnyCatchChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5784 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5785 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5786 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5787 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5788 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5789 | if (Catch.get() != S->getCatchStmt(I)) |
| 5790 | AnyCatchChanged = true; |
| 5791 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5792 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5793 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5794 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5795 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5796 | if (S->getFinallyStmt()) { |
| 5797 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5798 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5799 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | // If nothing changed, just retain this statement. |
| 5803 | if (!getDerived().AlwaysRebuild() && |
| 5804 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5805 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5806 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5807 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5808 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5809 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5810 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5811 | CatchStmts, Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5814 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5815 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5817 | // Transform the @catch parameter, if there is one. |
| 5818 | VarDecl *Var = 0; |
| 5819 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5820 | TypeSourceInfo *TSInfo = 0; |
| 5821 | if (FromVar->getTypeSourceInfo()) { |
| 5822 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5823 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5824 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5825 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5826 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5827 | QualType T; |
| 5828 | if (TSInfo) |
| 5829 | T = TSInfo->getType(); |
| 5830 | else { |
| 5831 | T = getDerived().TransformType(FromVar->getType()); |
| 5832 | if (T.isNull()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5833 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5834 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5835 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5836 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5837 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5838 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5839 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5840 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5841 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5842 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5843 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5844 | |
| 5845 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5846 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5847 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5849 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5850 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5851 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5852 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5853 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5854 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5855 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5856 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5857 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5858 | // If nothing changed, just retain this statement. |
| 5859 | if (!getDerived().AlwaysRebuild() && |
| 5860 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5861 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5862 | |
| 5863 | // Build a new statement. |
| 5864 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5865 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5866 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5867 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5868 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5869 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5870 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5871 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5872 | if (S->getThrowExpr()) { |
| 5873 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5874 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5875 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5876 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5877 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5878 | if (!getDerived().AlwaysRebuild() && |
| 5879 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5880 | return getSema().Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5881 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5882 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5883 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5884 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5885 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5886 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5887 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5888 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5889 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5890 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5891 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5892 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5893 | Object = |
| 5894 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5895 | Object.get()); |
| 5896 | if (Object.isInvalid()) |
| 5897 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5898 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5899 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5900 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5901 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5902 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5903 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5904 | // If nothing change, just retain the current statement. |
| 5905 | if (!getDerived().AlwaysRebuild() && |
| 5906 | Object.get() == S->getSynchExpr() && |
| 5907 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5908 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5909 | |
| 5910 | // Build a new statement. |
| 5911 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5912 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5916 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5917 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5918 | ObjCAutoreleasePoolStmt *S) { |
| 5919 | // Transform the body. |
| 5920 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5921 | if (Body.isInvalid()) |
| 5922 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5923 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5924 | // If nothing changed, just retain this statement. |
| 5925 | if (!getDerived().AlwaysRebuild() && |
| 5926 | Body.get() == S->getSubStmt()) |
| 5927 | return SemaRef.Owned(S); |
| 5928 | |
| 5929 | // Build a new statement. |
| 5930 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5931 | S->getAtLoc(), Body.get()); |
| 5932 | } |
| 5933 | |
| 5934 | template<typename Derived> |
| 5935 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5936 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5937 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5938 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5939 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5940 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5941 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5942 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5943 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5944 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5945 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5946 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5947 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5948 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5949 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5950 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5951 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5952 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5953 | // If nothing changed, just retain this statement. |
| 5954 | if (!getDerived().AlwaysRebuild() && |
| 5955 | Element.get() == S->getElement() && |
| 5956 | Collection.get() == S->getCollection() && |
| 5957 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5958 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5959 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5960 | // Build a new statement. |
| 5961 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5962 | Element.get(), |
| 5963 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5964 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5965 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | |
| 5969 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5970 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5971 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5972 | // Transform the exception declaration, if any. |
| 5973 | VarDecl *Var = 0; |
| 5974 | if (S->getExceptionDecl()) { |
| 5975 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5976 | TypeSourceInfo *T = getDerived().TransformType( |
| 5977 | ExceptionDecl->getTypeSourceInfo()); |
| 5978 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5979 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5980 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5981 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5982 | ExceptionDecl->getInnerLocStart(), |
| 5983 | ExceptionDecl->getLocation(), |
| 5984 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5985 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5986 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5987 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5988 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5989 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5990 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5991 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5992 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5993 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5994 | if (!getDerived().AlwaysRebuild() && |
| 5995 | !Var && |
| 5996 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5997 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5998 | |
| 5999 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 6000 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6001 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6003 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6004 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6005 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6006 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 6007 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6008 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6009 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 6010 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6011 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6012 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6013 | // Transform the handlers. |
| 6014 | bool HandlerChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6015 | SmallVector<Stmt*, 8> Handlers; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6016 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6017 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6018 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 6019 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6020 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6021 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6022 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 6023 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 6024 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6025 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6026 | if (!getDerived().AlwaysRebuild() && |
| 6027 | TryBlock.get() == S->getTryBlock() && |
| 6028 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6029 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6030 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6031 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6032 | Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6033 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6034 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6035 | template<typename Derived> |
| 6036 | StmtResult |
| 6037 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6038 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6039 | if (Range.isInvalid()) |
| 6040 | return StmtError(); |
| 6041 | |
| 6042 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6043 | if (BeginEnd.isInvalid()) |
| 6044 | return StmtError(); |
| 6045 | |
| 6046 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6047 | if (Cond.isInvalid()) |
| 6048 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6049 | if (Cond.get()) |
| 6050 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 6051 | if (Cond.isInvalid()) |
| 6052 | return StmtError(); |
| 6053 | if (Cond.get()) |
| 6054 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6055 | |
| 6056 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6057 | if (Inc.isInvalid()) |
| 6058 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6059 | if (Inc.get()) |
| 6060 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6061 | |
| 6062 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6063 | if (LoopVar.isInvalid()) |
| 6064 | return StmtError(); |
| 6065 | |
| 6066 | StmtResult NewStmt = S; |
| 6067 | if (getDerived().AlwaysRebuild() || |
| 6068 | Range.get() != S->getRangeStmt() || |
| 6069 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6070 | Cond.get() != S->getCond() || |
| 6071 | Inc.get() != S->getInc() || |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6072 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6073 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6074 | S->getColonLoc(), Range.get(), |
| 6075 | BeginEnd.get(), Cond.get(), |
| 6076 | Inc.get(), LoopVar.get(), |
| 6077 | S->getRParenLoc()); |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6078 | if (NewStmt.isInvalid()) |
| 6079 | return StmtError(); |
| 6080 | } |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6081 | |
| 6082 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6083 | if (Body.isInvalid()) |
| 6084 | return StmtError(); |
| 6085 | |
| 6086 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6087 | // it now so we have a new statement to attach the body to. |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6088 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6089 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6090 | S->getColonLoc(), Range.get(), |
| 6091 | BeginEnd.get(), Cond.get(), |
| 6092 | Inc.get(), LoopVar.get(), |
| 6093 | S->getRParenLoc()); |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6094 | if (NewStmt.isInvalid()) |
| 6095 | return StmtError(); |
| 6096 | } |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6097 | |
| 6098 | if (NewStmt.get() == S) |
| 6099 | return SemaRef.Owned(S); |
| 6100 | |
| 6101 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6102 | } |
| 6103 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6104 | template<typename Derived> |
| 6105 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6106 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6107 | MSDependentExistsStmt *S) { |
| 6108 | // Transform the nested-name-specifier, if any. |
| 6109 | NestedNameSpecifierLoc QualifierLoc; |
| 6110 | if (S->getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6111 | QualifierLoc |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6112 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6113 | if (!QualifierLoc) |
| 6114 | return StmtError(); |
| 6115 | } |
| 6116 | |
| 6117 | // Transform the declaration name. |
| 6118 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6119 | if (NameInfo.getName()) { |
| 6120 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6121 | if (!NameInfo.getName()) |
| 6122 | return StmtError(); |
| 6123 | } |
| 6124 | |
| 6125 | // Check whether anything changed. |
| 6126 | if (!getDerived().AlwaysRebuild() && |
| 6127 | QualifierLoc == S->getQualifierLoc() && |
| 6128 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6129 | return S; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6130 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6131 | // Determine whether this name exists, if we can. |
| 6132 | CXXScopeSpec SS; |
| 6133 | SS.Adopt(QualifierLoc); |
| 6134 | bool Dependent = false; |
| 6135 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 6136 | case Sema::IER_Exists: |
| 6137 | if (S->isIfExists()) |
| 6138 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6139 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6140 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6141 | |
| 6142 | case Sema::IER_DoesNotExist: |
| 6143 | if (S->isIfNotExists()) |
| 6144 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6145 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6146 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6147 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6148 | case Sema::IER_Dependent: |
| 6149 | Dependent = true; |
| 6150 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6151 | |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6152 | case Sema::IER_Error: |
| 6153 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6154 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6155 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6156 | // We need to continue with the instantiation, so do so now. |
| 6157 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6158 | if (SubStmt.isInvalid()) |
| 6159 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6160 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6161 | // If we have resolved the name, just transform to the substatement. |
| 6162 | if (!Dependent) |
| 6163 | return SubStmt; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6164 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6165 | // The name is still dependent, so build a dependent expression again. |
| 6166 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6167 | S->isIfExists(), |
| 6168 | QualifierLoc, |
| 6169 | NameInfo, |
| 6170 | SubStmt.get()); |
| 6171 | } |
| 6172 | |
| 6173 | template<typename Derived> |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6174 | ExprResult |
| 6175 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6176 | NestedNameSpecifierLoc QualifierLoc; |
| 6177 | if (E->getQualifierLoc()) { |
| 6178 | QualifierLoc |
| 6179 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6180 | if (!QualifierLoc) |
| 6181 | return ExprError(); |
| 6182 | } |
| 6183 | |
| 6184 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6185 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6186 | if (!PD) |
| 6187 | return ExprError(); |
| 6188 | |
| 6189 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6190 | if (Base.isInvalid()) |
| 6191 | return ExprError(); |
| 6192 | |
| 6193 | return new (SemaRef.getASTContext()) |
| 6194 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6195 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6196 | QualifierLoc, E->getMemberLoc()); |
| 6197 | } |
| 6198 | |
| 6199 | template<typename Derived> |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6200 | StmtResult |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6201 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 6202 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 6203 | if(TryBlock.isInvalid()) return StmtError(); |
| 6204 | |
| 6205 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 6206 | if(!getDerived().AlwaysRebuild() && |
| 6207 | TryBlock.get() == S->getTryBlock() && |
| 6208 | Handler.get() == S->getHandler()) |
| 6209 | return SemaRef.Owned(S); |
| 6210 | |
| 6211 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 6212 | S->getTryLoc(), |
| 6213 | TryBlock.take(), |
| 6214 | Handler.take()); |
| 6215 | } |
| 6216 | |
| 6217 | template<typename Derived> |
| 6218 | StmtResult |
| 6219 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 6220 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6221 | if(Block.isInvalid()) return StmtError(); |
| 6222 | |
| 6223 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 6224 | Block.take()); |
| 6225 | } |
| 6226 | |
| 6227 | template<typename Derived> |
| 6228 | StmtResult |
| 6229 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 6230 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 6231 | if(FilterExpr.isInvalid()) return StmtError(); |
| 6232 | |
| 6233 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 6234 | if(Block.isInvalid()) return StmtError(); |
| 6235 | |
| 6236 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 6237 | FilterExpr.take(), |
| 6238 | Block.take()); |
| 6239 | } |
| 6240 | |
| 6241 | template<typename Derived> |
| 6242 | StmtResult |
| 6243 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6244 | if(isa<SEHFinallyStmt>(Handler)) |
| 6245 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6246 | else |
| 6247 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6248 | } |
| 6249 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6250 | template<typename Derived> |
| 6251 | StmtResult |
| 6252 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 6253 | // Transform the clauses |
| 6254 | llvm::SmallVector<OMPClause *, 5> TClauses; |
| 6255 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6256 | TClauses.reserve(Clauses.size()); |
| 6257 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6258 | I != E; ++I) { |
| 6259 | if (*I) { |
| 6260 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| 6261 | if (!Clause) |
| 6262 | return StmtError(); |
| 6263 | TClauses.push_back(Clause); |
| 6264 | } |
| 6265 | else { |
| 6266 | TClauses.push_back(0); |
| 6267 | } |
| 6268 | } |
| 6269 | if (!D->getAssociatedStmt()) |
| 6270 | return StmtError(); |
| 6271 | StmtResult AssociatedStmt = |
| 6272 | getDerived().TransformStmt(D->getAssociatedStmt()); |
| 6273 | if (AssociatedStmt.isInvalid()) |
| 6274 | return StmtError(); |
| 6275 | |
| 6276 | return getDerived().RebuildOMPParallelDirective(TClauses, |
| 6277 | AssociatedStmt.take(), |
| 6278 | D->getLocStart(), |
| 6279 | D->getLocEnd()); |
| 6280 | } |
| 6281 | |
| 6282 | template<typename Derived> |
| 6283 | OMPClause * |
| 6284 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| 6285 | return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(), |
| 6286 | C->getDefaultKindKwLoc(), |
| 6287 | C->getLocStart(), |
| 6288 | C->getLParenLoc(), |
| 6289 | C->getLocEnd()); |
| 6290 | } |
| 6291 | |
| 6292 | template<typename Derived> |
| 6293 | OMPClause * |
| 6294 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
| 6295 | llvm::SmallVector<Expr *, 5> Vars; |
| 6296 | Vars.reserve(C->varlist_size()); |
| 6297 | for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(), |
| 6298 | E = C->varlist_end(); |
| 6299 | I != E; ++I) { |
| 6300 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6301 | if (EVar.isInvalid()) |
| 6302 | return 0; |
| 6303 | Vars.push_back(EVar.take()); |
| 6304 | } |
| 6305 | return getDerived().RebuildOMPPrivateClause(Vars, |
| 6306 | C->getLocStart(), |
| 6307 | C->getLParenLoc(), |
| 6308 | C->getLocEnd()); |
| 6309 | } |
| 6310 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6311 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6312 | // Expression transformation |
| 6313 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6314 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6315 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6316 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6317 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6319 | |
| 6320 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6321 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6322 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6323 | NestedNameSpecifierLoc QualifierLoc; |
| 6324 | if (E->getQualifierLoc()) { |
| 6325 | QualifierLoc |
| 6326 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6327 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6328 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6329 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6330 | |
| 6331 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6332 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6333 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6334 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6335 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6336 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6337 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6338 | if (NameInfo.getName()) { |
| 6339 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6340 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6341 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6342 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6343 | |
| 6344 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6345 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6346 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6347 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6348 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6349 | |
| 6350 | // Mark it referenced in the new context regardless. |
| 6351 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6352 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6353 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6354 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6355 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6356 | |
| 6357 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6358 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6359 | TemplateArgs = &TransArgs; |
| 6360 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6361 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6362 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6363 | E->getNumTemplateArgs(), |
| 6364 | TransArgs)) |
| 6365 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6366 | } |
| 6367 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6368 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6369 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6370 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6371 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6372 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6373 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6374 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6375 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6377 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6378 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6379 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6380 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6381 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6382 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6383 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6384 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6385 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6386 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6387 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6389 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6390 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6391 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6392 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6393 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6394 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6395 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6396 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6397 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6398 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6399 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6403 | ExprResult |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6404 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 391ca9f | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6405 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6406 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6407 | return SemaRef.MaybeBindToTemporary(E); |
| 6408 | } |
| 6409 | |
| 6410 | template<typename Derived> |
| 6411 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6412 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6413 | ExprResult ControllingExpr = |
| 6414 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6415 | if (ControllingExpr.isInvalid()) |
| 6416 | return ExprError(); |
| 6417 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6418 | SmallVector<Expr *, 4> AssocExprs; |
| 6419 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6420 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6421 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6422 | if (TS) { |
| 6423 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6424 | if (!AssocType) |
| 6425 | return ExprError(); |
| 6426 | AssocTypes.push_back(AssocType); |
| 6427 | } else { |
| 6428 | AssocTypes.push_back(0); |
| 6429 | } |
| 6430 | |
| 6431 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6432 | if (AssocExpr.isInvalid()) |
| 6433 | return ExprError(); |
| 6434 | AssocExprs.push_back(AssocExpr.release()); |
| 6435 | } |
| 6436 | |
| 6437 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6438 | E->getDefaultLoc(), |
| 6439 | E->getRParenLoc(), |
| 6440 | ControllingExpr.release(), |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 6441 | AssocTypes, |
| 6442 | AssocExprs); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | template<typename Derived> |
| 6446 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6447 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6448 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6449 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6450 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6451 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6452 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6453 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6454 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6455 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6456 | E->getRParen()); |
| 6457 | } |
| 6458 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6459 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6460 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6461 | /// object available. |
| 6462 | template<typename Derived> |
| 6463 | ExprResult |
| 6464 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6465 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 6466 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); |
| 6467 | else |
| 6468 | return getDerived().TransformExpr(E); |
| 6469 | } |
| 6470 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6471 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6472 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6473 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | 82b0001 | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 6474 | ExprResult SubExpr; |
| 6475 | if (E->getOpcode() == UO_AddrOf) |
| 6476 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 6477 | else |
| 6478 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6479 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6480 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6482 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6483 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6484 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6485 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6486 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6487 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6489 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6490 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6491 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6492 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6493 | // Transform the type. |
| 6494 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6495 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6496 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6497 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6498 | // Transform all of the components into components similar to what the |
| 6499 | // parser uses. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6500 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6501 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6502 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6503 | // template code that we don't care. |
| 6504 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6505 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6506 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6507 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6508 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6509 | const Node &ON = E->getComponent(I); |
| 6510 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6511 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6512 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6513 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6514 | switch (ON.getKind()) { |
| 6515 | case Node::Array: { |
| 6516 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6517 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6518 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6519 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6520 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6521 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6522 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6523 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6524 | break; |
| 6525 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6526 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6527 | case Node::Field: |
| 6528 | case Node::Identifier: |
| 6529 | Comp.isBrackets = false; |
| 6530 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6531 | if (!Comp.U.IdentInfo) |
| 6532 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6533 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6534 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6535 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6536 | case Node::Base: |
| 6537 | // Will be recomputed during the rebuild. |
| 6538 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6539 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6540 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6541 | Components.push_back(Comp); |
| 6542 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6543 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6544 | // If nothing changed, retain the existing expression. |
| 6545 | if (!getDerived().AlwaysRebuild() && |
| 6546 | Type == E->getTypeSourceInfo() && |
| 6547 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6548 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6549 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6550 | // Build a new offsetof expression. |
| 6551 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6552 | Components.data(), Components.size(), |
| 6553 | E->getRParenLoc()); |
| 6554 | } |
| 6555 | |
| 6556 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6557 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6558 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6559 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6560 | "opaque value expression requires transformation"); |
| 6561 | return SemaRef.Owned(E); |
| 6562 | } |
| 6563 | |
| 6564 | template<typename Derived> |
| 6565 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6566 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6567 | // Rebuild the syntactic form. The original syntactic form has |
| 6568 | // opaque-value expressions in it, so strip those away and rebuild |
| 6569 | // the result. This is a really awful way of doing this, but the |
| 6570 | // better solution (rebuilding the semantic expressions and |
| 6571 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6572 | // TreeTransform to not strip away implicit conversions. |
| 6573 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6574 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6575 | if (result.isInvalid()) return ExprError(); |
| 6576 | |
| 6577 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6578 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6579 | // should reapply. |
| 6580 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6581 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6582 | |
| 6583 | return result; |
| 6584 | } |
| 6585 | |
| 6586 | template<typename Derived> |
| 6587 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6588 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6589 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6590 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6591 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6592 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6593 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6594 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6595 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6596 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6597 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6598 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6599 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6600 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6601 | E->getKind(), |
| 6602 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6604 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6605 | // C++0x [expr.sizeof]p1: |
| 6606 | // The operand is either an expression, which is an unevaluated operand |
| 6607 | // [...] |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 6608 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 6609 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6610 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6611 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6612 | if (SubExpr.isInvalid()) |
| 6613 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6614 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6615 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6616 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6617 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6618 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6619 | E->getOperatorLoc(), |
| 6620 | E->getKind(), |
| 6621 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6624 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6625 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6626 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6627 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6628 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6629 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6630 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6631 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6632 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6633 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6634 | |
| 6635 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6636 | if (!getDerived().AlwaysRebuild() && |
| 6637 | LHS.get() == E->getLHS() && |
| 6638 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6639 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6640 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6641 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6642 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6643 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6644 | E->getRBracketLoc()); |
| 6645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6646 | |
| 6647 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6648 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6649 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6650 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6651 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6652 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6653 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | |
| 6655 | // Transform arguments. |
| 6656 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6657 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6658 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6659 | &ArgChanged)) |
| 6660 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6661 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6662 | if (!getDerived().AlwaysRebuild() && |
| 6663 | Callee.get() == E->getCallee() && |
| 6664 | !ArgChanged) |
Dmitri Gribenko | 1ad23d6 | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 6665 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6666 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6667 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6668 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6669 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6670 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6671 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6672 | E->getRParenLoc()); |
| 6673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6674 | |
| 6675 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6676 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6677 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6678 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6679 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6680 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6681 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6682 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6683 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6684 | QualifierLoc |
| 6685 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6686 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6687 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6688 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6689 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6690 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6691 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6692 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6693 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6694 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6695 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6696 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6697 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6698 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6699 | if (FoundDecl == E->getMemberDecl()) { |
| 6700 | FoundDecl = Member; |
| 6701 | } else { |
| 6702 | FoundDecl = cast_or_null<NamedDecl>( |
| 6703 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6704 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6705 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6706 | } |
| 6707 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6708 | if (!getDerived().AlwaysRebuild() && |
| 6709 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6710 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6711 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6712 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6713 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6714 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6715 | // Mark it referenced in the new context regardless. |
| 6716 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6717 | SemaRef.MarkMemberReferenced(E); |
| 6718 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6719 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6720 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6721 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6722 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6723 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6724 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6725 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6726 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6727 | E->getNumTemplateArgs(), |
| 6728 | TransArgs)) |
| 6729 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6730 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6731 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6732 | // FIXME: Bogus source location for the operator |
| 6733 | SourceLocation FakeOperatorLoc |
| 6734 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6735 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6736 | // FIXME: to do this check properly, we will need to preserve the |
| 6737 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6738 | // base (and therefore couldn't do the check) and a |
| 6739 | // nested-name-qualifier (and therefore could do the lookup). |
| 6740 | NamedDecl *FirstQualifierInScope = 0; |
| 6741 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6742 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6743 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6744 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6745 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6746 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6747 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6748 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6749 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6750 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6751 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6752 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6754 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6755 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6756 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6757 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6758 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6759 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6760 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6761 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6762 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6763 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6764 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6765 | if (!getDerived().AlwaysRebuild() && |
| 6766 | LHS.get() == E->getLHS() && |
| 6767 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6768 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6769 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6770 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6771 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6773 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6774 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6775 | } |
| 6776 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6777 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6778 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6779 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6780 | CompoundAssignOperator *E) { |
| 6781 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6783 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6784 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6785 | ExprResult TreeTransform<Derived>:: |
| 6786 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6787 | // Just rebuild the common and RHS expressions and see whether we |
| 6788 | // get any changes. |
| 6789 | |
| 6790 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6791 | if (commonExpr.isInvalid()) |
| 6792 | return ExprError(); |
| 6793 | |
| 6794 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6795 | if (rhs.isInvalid()) |
| 6796 | return ExprError(); |
| 6797 | |
| 6798 | if (!getDerived().AlwaysRebuild() && |
| 6799 | commonExpr.get() == e->getCommon() && |
| 6800 | rhs.get() == e->getFalseExpr()) |
| 6801 | return SemaRef.Owned(e); |
| 6802 | |
| 6803 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6804 | e->getQuestionLoc(), |
| 6805 | 0, |
| 6806 | e->getColonLoc(), |
| 6807 | rhs.get()); |
| 6808 | } |
| 6809 | |
| 6810 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6811 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6812 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6813 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6814 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6815 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6816 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6817 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6818 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6819 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6820 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6821 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6822 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6823 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6824 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6825 | if (!getDerived().AlwaysRebuild() && |
| 6826 | Cond.get() == E->getCond() && |
| 6827 | LHS.get() == E->getLHS() && |
| 6828 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6829 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6830 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6831 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6832 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6833 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6834 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6835 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6836 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6837 | |
| 6838 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6839 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6840 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6841 | // Implicit casts are eliminated during transformation, since they |
| 6842 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6843 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6845 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6846 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6847 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6848 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6849 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6850 | if (!Type) |
| 6851 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6852 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6853 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6854 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6855 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6856 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6857 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6858 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6859 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6860 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6861 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6862 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6863 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6864 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6865 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6866 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6867 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6868 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6869 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6870 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6871 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6872 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6873 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6874 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6875 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6876 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6877 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6878 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6879 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6880 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6881 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6882 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6883 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6884 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6885 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6886 | // Note: the expression type doesn't necessarily match the |
| 6887 | // type-as-written, but that's okay, because it should always be |
| 6888 | // derivable from the initializer. |
| 6889 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6890 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6891 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6892 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6893 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6894 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6895 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6896 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6897 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6898 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6899 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6900 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6901 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6902 | if (!getDerived().AlwaysRebuild() && |
| 6903 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6904 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6906 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6907 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6908 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6909 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6910 | E->getAccessorLoc(), |
| 6911 | E->getAccessor()); |
| 6912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6913 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6915 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6916 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6917 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6918 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6919 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6920 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6921 | Inits, &InitChanged)) |
| 6922 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6923 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6924 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6925 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6926 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6927 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6928 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6929 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6930 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6931 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6932 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6933 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6934 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6935 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6936 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6937 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6938 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6939 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6940 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6941 | // transform the designators. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6942 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6943 | bool ExprChanged = false; |
| 6944 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6945 | DEnd = E->designators_end(); |
| 6946 | D != DEnd; ++D) { |
| 6947 | if (D->isFieldDesignator()) { |
| 6948 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6949 | D->getDotLoc(), |
| 6950 | D->getFieldLoc())); |
| 6951 | continue; |
| 6952 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6953 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6954 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6955 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6956 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6957 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6958 | |
| 6959 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6960 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6961 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6962 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6963 | ArrayExprs.push_back(Index.release()); |
| 6964 | continue; |
| 6965 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6967 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6968 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6969 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6970 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6971 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6972 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6973 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6974 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6975 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6976 | |
| 6977 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6978 | End.get(), |
| 6979 | D->getLBracketLoc(), |
| 6980 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6981 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6982 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6983 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6984 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6985 | ArrayExprs.push_back(Start.release()); |
| 6986 | ArrayExprs.push_back(End.release()); |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 6990 | Init.get() == E->getInit() && |
| 6991 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6992 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6993 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6994 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6995 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6996 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6997 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6998 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7000 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7001 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7002 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7003 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7004 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7005 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7006 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7007 | QualType T = getDerived().TransformType(E->getType()); |
| 7008 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7009 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7011 | if (!getDerived().AlwaysRebuild() && |
| 7012 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7013 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7015 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7017 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7018 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7019 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7020 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7021 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7022 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7023 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7024 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7025 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7026 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7027 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7028 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7029 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7030 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7031 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7032 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7033 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7034 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7035 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7036 | } |
| 7037 | |
| 7038 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7039 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7040 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7041 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7042 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7043 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7044 | &ArgumentChanged)) |
| 7045 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7046 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7047 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7048 | Inits, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7049 | E->getRParenLoc()); |
| 7050 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7051 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7052 | /// \brief Transform an address-of-label expression. |
| 7053 | /// |
| 7054 | /// By default, the transformation of an address-of-label expression always |
| 7055 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7056 | /// the corresponding label statement by semantic analysis. |
| 7057 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7058 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7059 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7060 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7061 | E->getLabel()); |
| 7062 | if (!LD) |
| 7063 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7064 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7065 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7066 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7068 | |
| 7069 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7070 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7071 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7072 | SemaRef.ActOnStartStmtExpr(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7073 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7074 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7075 | if (SubStmt.isInvalid()) { |
| 7076 | SemaRef.ActOnStmtExprError(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7077 | return ExprError(); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7078 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7079 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7080 | if (!getDerived().AlwaysRebuild() && |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7081 | SubStmt.get() == E->getSubStmt()) { |
| 7082 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7083 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7084 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7085 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7086 | |
| 7087 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7088 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7089 | E->getRParenLoc()); |
| 7090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7091 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7092 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7093 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7094 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7095 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7096 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7097 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7098 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7099 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7100 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7101 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7102 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7103 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7104 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7105 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7106 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7107 | if (!getDerived().AlwaysRebuild() && |
| 7108 | Cond.get() == E->getCond() && |
| 7109 | LHS.get() == E->getLHS() && |
| 7110 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7111 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7113 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7114 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7115 | E->getRParenLoc()); |
| 7116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7118 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7119 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7120 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7121 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7125 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7126 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7127 | switch (E->getOperator()) { |
| 7128 | case OO_New: |
| 7129 | case OO_Delete: |
| 7130 | case OO_Array_New: |
| 7131 | case OO_Array_Delete: |
| 7132 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7133 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7134 | case OO_Call: { |
| 7135 | // This is a call to an object's operator(). |
| 7136 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7137 | |
| 7138 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7139 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7140 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7141 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7142 | |
| 7143 | // FIXME: Poor location information |
| 7144 | SourceLocation FakeLParenLoc |
| 7145 | = SemaRef.PP.getLocForEndOfToken( |
| 7146 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 7147 | |
| 7148 | // Transform the call arguments. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7149 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7150 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7151 | Args)) |
| 7152 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7153 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7154 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7155 | Args, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7156 | E->getLocEnd()); |
| 7157 | } |
| 7158 | |
| 7159 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7160 | case OO_##Name: |
| 7161 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7162 | #include "clang/Basic/OperatorKinds.def" |
| 7163 | case OO_Subscript: |
| 7164 | // Handled below. |
| 7165 | break; |
| 7166 | |
| 7167 | case OO_Conditional: |
| 7168 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7169 | |
| 7170 | case OO_None: |
| 7171 | case NUM_OVERLOADED_OPERATORS: |
| 7172 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7173 | } |
| 7174 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7175 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7176 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7177 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7178 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7179 | ExprResult First; |
| 7180 | if (E->getOperator() == OO_Amp) |
| 7181 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7182 | else |
| 7183 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7184 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7185 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7186 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7187 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7188 | if (E->getNumArgs() == 2) { |
| 7189 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7190 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7191 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7192 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7194 | if (!getDerived().AlwaysRebuild() && |
| 7195 | Callee.get() == E->getCallee() && |
| 7196 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7197 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7198 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7199 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7200 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7201 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7202 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7203 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7204 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7205 | Callee.get(), |
| 7206 | First.get(), |
| 7207 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7208 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7210 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7211 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7212 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7213 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7216 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7217 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7218 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7219 | // Transform the callee. |
| 7220 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7221 | if (Callee.isInvalid()) |
| 7222 | return ExprError(); |
| 7223 | |
| 7224 | // Transform exec config. |
| 7225 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7226 | if (EC.isInvalid()) |
| 7227 | return ExprError(); |
| 7228 | |
| 7229 | // Transform arguments. |
| 7230 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7231 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7232 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7233 | &ArgChanged)) |
| 7234 | return ExprError(); |
| 7235 | |
| 7236 | if (!getDerived().AlwaysRebuild() && |
| 7237 | Callee.get() == E->getCallee() && |
| 7238 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7239 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7240 | |
| 7241 | // FIXME: Wrong source location information for the '('. |
| 7242 | SourceLocation FakeLParenLoc |
| 7243 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7244 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7245 | Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7246 | E->getRParenLoc(), EC.get()); |
| 7247 | } |
| 7248 | |
| 7249 | template<typename Derived> |
| 7250 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7251 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7252 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7253 | if (!Type) |
| 7254 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7255 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7256 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7257 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7258 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7259 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7260 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7261 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7262 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7263 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7264 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7265 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7266 | E->getStmtClass(), |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7267 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7268 | Type, |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7269 | E->getAngleBrackets().getEnd(), |
| 7270 | // FIXME. this should be '(' location |
| 7271 | E->getAngleBrackets().getEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7272 | SubExpr.get(), |
Abramo Bagnara | 6cf7d7d | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7273 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7275 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7276 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7277 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7278 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7279 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7280 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7281 | |
| 7282 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7283 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7284 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7285 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7288 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7289 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7290 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7291 | CXXReinterpretCastExpr *E) { |
| 7292 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7294 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7295 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7296 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7297 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7298 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7299 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7300 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7301 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7302 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7303 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7304 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7305 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7306 | if (!Type) |
| 7307 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7308 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7309 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7310 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7311 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7312 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7313 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7314 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7315 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7316 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7317 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7318 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7319 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7320 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7321 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7322 | E->getRParenLoc()); |
| 7323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7324 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7325 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7326 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7327 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7328 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7329 | TypeSourceInfo *TInfo |
| 7330 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7331 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7332 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7333 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7334 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7335 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7336 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7337 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7338 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7339 | E->getLocStart(), |
| 7340 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7341 | E->getLocEnd()); |
| 7342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7343 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7344 | // We don't know whether the subexpression is potentially evaluated until |
| 7345 | // after we perform semantic analysis. We speculatively assume it is |
| 7346 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7347 | // potentially evaluated. |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7348 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7349 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7350 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7351 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7352 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7353 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7354 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7355 | if (!getDerived().AlwaysRebuild() && |
| 7356 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7357 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7358 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7359 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7360 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7361 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7362 | E->getLocEnd()); |
| 7363 | } |
| 7364 | |
| 7365 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7366 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7367 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7368 | if (E->isTypeOperand()) { |
| 7369 | TypeSourceInfo *TInfo |
| 7370 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7371 | if (!TInfo) |
| 7372 | return ExprError(); |
| 7373 | |
| 7374 | if (!getDerived().AlwaysRebuild() && |
| 7375 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7376 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7377 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7378 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7379 | E->getLocStart(), |
| 7380 | TInfo, |
| 7381 | E->getLocEnd()); |
| 7382 | } |
| 7383 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7384 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7385 | |
| 7386 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7387 | if (SubExpr.isInvalid()) |
| 7388 | return ExprError(); |
| 7389 | |
| 7390 | if (!getDerived().AlwaysRebuild() && |
| 7391 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7392 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7393 | |
| 7394 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7395 | E->getLocStart(), |
| 7396 | SubExpr.get(), |
| 7397 | E->getLocEnd()); |
| 7398 | } |
| 7399 | |
| 7400 | template<typename Derived> |
| 7401 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7402 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7403 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7404 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7406 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7407 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7408 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7409 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7410 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7411 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7412 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7413 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7414 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7415 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | cafeb94 | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 7416 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7417 | |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7418 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7419 | // Make sure that we capture 'this'. |
| 7420 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7421 | return SemaRef.Owned(E); |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7422 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7423 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7424 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7425 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7426 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7427 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7428 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7429 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7430 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7431 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7432 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7434 | if (!getDerived().AlwaysRebuild() && |
| 7435 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7436 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7437 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7438 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7439 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7441 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7442 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7443 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7444 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7445 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7446 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7447 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7448 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7449 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7450 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7451 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7452 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7453 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7454 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7455 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7457 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7458 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7459 | ExprResult |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 7460 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7461 | FieldDecl *Field |
| 7462 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7463 | E->getField())); |
| 7464 | if (!Field) |
| 7465 | return ExprError(); |
| 7466 | |
| 7467 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
| 7468 | return SemaRef.Owned(E); |
| 7469 | |
| 7470 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 7471 | } |
| 7472 | |
| 7473 | template<typename Derived> |
| 7474 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7475 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7476 | CXXScalarValueInitExpr *E) { |
| 7477 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7478 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7479 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7480 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7481 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7482 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7483 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7484 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7485 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7486 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7487 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7489 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7490 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7491 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7492 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7493 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7494 | TypeSourceInfo *AllocTypeInfo |
| 7495 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7496 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7497 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7498 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7499 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7500 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7501 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7502 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7503 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7504 | // Transform the placement arguments (if any). |
| 7505 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7506 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7507 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7508 | E->getNumPlacementArgs(), true, |
| 7509 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7510 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7511 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7512 | // Transform the initializer (if any). |
| 7513 | Expr *OldInit = E->getInitializer(); |
| 7514 | ExprResult NewInit; |
| 7515 | if (OldInit) |
| 7516 | NewInit = getDerived().TransformExpr(OldInit); |
| 7517 | if (NewInit.isInvalid()) |
| 7518 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7519 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7520 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7521 | FunctionDecl *OperatorNew = 0; |
| 7522 | if (E->getOperatorNew()) { |
| 7523 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7524 | getDerived().TransformDecl(E->getLocStart(), |
| 7525 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7526 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7527 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | FunctionDecl *OperatorDelete = 0; |
| 7531 | if (E->getOperatorDelete()) { |
| 7532 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7533 | getDerived().TransformDecl(E->getLocStart(), |
| 7534 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7535 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7536 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7537 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7539 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7540 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7541 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7542 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7543 | OperatorNew == E->getOperatorNew() && |
| 7544 | OperatorDelete == E->getOperatorDelete() && |
| 7545 | !ArgumentChanged) { |
| 7546 | // Mark any declarations we need as referenced. |
| 7547 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7548 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7549 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7550 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7551 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7552 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7553 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7554 | QualType ElementType |
| 7555 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7556 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7557 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7558 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7559 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7560 | } |
| 7561 | } |
| 7562 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7563 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7564 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7565 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7566 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7567 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7568 | if (!ArraySize.get()) { |
| 7569 | // If no array size was specified, but the new expression was |
| 7570 | // instantiated with an array type (e.g., "new T" where T is |
| 7571 | // instantiated with "int[4]"), extract the outer bound from the |
| 7572 | // array type as our array size. We do this with constant and |
| 7573 | // dependently-sized array types. |
| 7574 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7575 | if (!ArrayT) { |
| 7576 | // Do nothing |
| 7577 | } else if (const ConstantArrayType *ConsArrayT |
| 7578 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7579 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7580 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7581 | ConsArrayT->getSize(), |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7582 | SemaRef.Context.getSizeType(), |
| 7583 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7584 | AllocType = ConsArrayT->getElementType(); |
| 7585 | } else if (const DependentSizedArrayType *DepArrayT |
| 7586 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7587 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7588 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7589 | AllocType = DepArrayT->getElementType(); |
| 7590 | } |
| 7591 | } |
| 7592 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7594 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7595 | E->isGlobalNew(), |
| 7596 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7597 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7598 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7599 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7600 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7601 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7602 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7603 | E->getDirectInitRange(), |
| 7604 | NewInit.take()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7605 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7606 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7607 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7608 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7609 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7610 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7611 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7612 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7613 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7614 | // Transform the delete operator, if known. |
| 7615 | FunctionDecl *OperatorDelete = 0; |
| 7616 | if (E->getOperatorDelete()) { |
| 7617 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7618 | getDerived().TransformDecl(E->getLocStart(), |
| 7619 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7620 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7621 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7622 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7624 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7625 | Operand.get() == E->getArgument() && |
| 7626 | OperatorDelete == E->getOperatorDelete()) { |
| 7627 | // Mark any declarations we need as referenced. |
| 7628 | // FIXME: instantiation-specific. |
| 7629 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7630 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7631 | |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7632 | if (!E->getArgument()->isTypeDependent()) { |
| 7633 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7634 | E->getDestroyedType()); |
| 7635 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7636 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7637 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7638 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7639 | } |
| 7640 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7641 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7642 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7644 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7645 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7646 | E->isGlobalDelete(), |
| 7647 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7648 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7651 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7652 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7653 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7654 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7655 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7656 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7657 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7658 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7659 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7660 | bool MayBePseudoDestructor = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7661 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7662 | E->getOperatorLoc(), |
| 7663 | E->isArrow()? tok::arrow : tok::period, |
| 7664 | ObjectTypePtr, |
| 7665 | MayBePseudoDestructor); |
| 7666 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7667 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7668 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7669 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7670 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7671 | if (QualifierLoc) { |
| 7672 | QualifierLoc |
| 7673 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7674 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7675 | return ExprError(); |
| 7676 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7677 | CXXScopeSpec SS; |
| 7678 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7679 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7680 | PseudoDestructorTypeStorage Destroyed; |
| 7681 | if (E->getDestroyedTypeInfo()) { |
| 7682 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7683 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7684 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7685 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7686 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7687 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7688 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7689 | // We aren't likely to be able to resolve the identifier down to a type |
| 7690 | // now anyway, so just retain the identifier. |
| 7691 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7692 | E->getDestroyedTypeLoc()); |
| 7693 | } else { |
| 7694 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7695 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7696 | *E->getDestroyedTypeIdentifier(), |
| 7697 | E->getDestroyedTypeLoc(), |
| 7698 | /*Scope=*/0, |
| 7699 | SS, ObjectTypePtr, |
| 7700 | false); |
| 7701 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7702 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7703 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7704 | Destroyed |
| 7705 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7706 | E->getDestroyedTypeLoc()); |
| 7707 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7708 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7709 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7710 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 303b96f | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 7711 | CXXScopeSpec EmptySS; |
| 7712 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 7713 | E->getScopeTypeInfo(), ObjectType, 0, EmptySS); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7714 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7715 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7716 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7717 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7718 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7719 | E->getOperatorLoc(), |
| 7720 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7721 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7722 | ScopeTypeInfo, |
| 7723 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7724 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7725 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7726 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7727 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7728 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7729 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7730 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7731 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7732 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7733 | Sema::LookupOrdinaryName); |
| 7734 | |
| 7735 | // Transform all the decls. |
| 7736 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7737 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7738 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7739 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7740 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7741 | if (!InstD) { |
| 7742 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7743 | // This can happen because of dependent hiding. |
| 7744 | if (isa<UsingShadowDecl>(*I)) |
| 7745 | continue; |
| 7746 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7747 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7748 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7749 | |
| 7750 | // Expand using declarations. |
| 7751 | if (isa<UsingDecl>(InstD)) { |
| 7752 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7753 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7754 | E = UD->shadow_end(); I != E; ++I) |
| 7755 | R.addDecl(*I); |
| 7756 | continue; |
| 7757 | } |
| 7758 | |
| 7759 | R.addDecl(InstD); |
| 7760 | } |
| 7761 | |
| 7762 | // Resolve a kind, but don't do any further analysis. If it's |
| 7763 | // ambiguous, the callee needs to deal with it. |
| 7764 | R.resolveKind(); |
| 7765 | |
| 7766 | // Rebuild the nested-name qualifier, if present. |
| 7767 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7768 | if (Old->getQualifierLoc()) { |
| 7769 | NestedNameSpecifierLoc QualifierLoc |
| 7770 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7771 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7772 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7773 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7774 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7775 | } |
| 7776 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7777 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7778 | CXXRecordDecl *NamingClass |
| 7779 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7780 | Old->getNameLoc(), |
| 7781 | Old->getNamingClass())); |
| 7782 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7783 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7784 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7785 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7786 | } |
| 7787 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7788 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7789 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7790 | // If we have neither explicit template arguments, nor the template keyword, |
| 7791 | // it's a normal declaration name. |
| 7792 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7793 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7794 | |
| 7795 | // If we have template arguments, rebuild them, then rebuild the |
| 7796 | // templateid expression. |
| 7797 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 02e221b | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 7798 | if (Old->hasExplicitTemplateArgs() && |
| 7799 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7800 | Old->getNumTemplateArgs(), |
| 7801 | TransArgs)) |
| 7802 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7803 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7804 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7805 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7807 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7808 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7809 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7810 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7811 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7812 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7813 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7814 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7815 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7816 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7817 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7818 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7819 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7820 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7821 | T, |
| 7822 | E->getLocEnd()); |
| 7823 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7824 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7825 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7826 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7827 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7828 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7829 | if (!LhsT) |
| 7830 | return ExprError(); |
| 7831 | |
| 7832 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7833 | if (!RhsT) |
| 7834 | return ExprError(); |
| 7835 | |
| 7836 | if (!getDerived().AlwaysRebuild() && |
| 7837 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7838 | return SemaRef.Owned(E); |
| 7839 | |
| 7840 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7841 | E->getLocStart(), |
| 7842 | LhsT, RhsT, |
| 7843 | E->getLocEnd()); |
| 7844 | } |
| 7845 | |
| 7846 | template<typename Derived> |
| 7847 | ExprResult |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7848 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7849 | bool ArgChanged = false; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7850 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7851 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7852 | TypeSourceInfo *From = E->getArg(I); |
| 7853 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7854 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7855 | TypeLocBuilder TLB; |
| 7856 | TLB.reserve(FromTL.getFullDataSize()); |
| 7857 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7858 | if (To.isNull()) |
| 7859 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7860 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7861 | if (To == From->getType()) |
| 7862 | Args.push_back(From); |
| 7863 | else { |
| 7864 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7865 | ArgChanged = true; |
| 7866 | } |
| 7867 | continue; |
| 7868 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7869 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7870 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7871 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7872 | // We have a pack expansion. Instantiate it. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7873 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7874 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7875 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7876 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7877 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7878 | // Determine whether the set of unexpanded parameter packs can and should |
| 7879 | // be expanded. |
| 7880 | bool Expand = true; |
| 7881 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 7882 | Optional<unsigned> OrigNumExpansions = |
| 7883 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7884 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7885 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7886 | PatternTL.getSourceRange(), |
| 7887 | Unexpanded, |
| 7888 | Expand, RetainExpansion, |
| 7889 | NumExpansions)) |
| 7890 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7891 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7892 | if (!Expand) { |
| 7893 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7894 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7895 | // expansion. |
| 7896 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7897 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7898 | TypeLocBuilder TLB; |
| 7899 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7900 | |
| 7901 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7902 | if (To.isNull()) |
| 7903 | return ExprError(); |
| 7904 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7905 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7906 | PatternTL.getSourceRange(), |
| 7907 | ExpansionTL.getEllipsisLoc(), |
| 7908 | NumExpansions); |
| 7909 | if (To.isNull()) |
| 7910 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7911 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7912 | PackExpansionTypeLoc ToExpansionTL |
| 7913 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7914 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7915 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7916 | continue; |
| 7917 | } |
| 7918 | |
| 7919 | // Expand the pack expansion by substituting for each argument in the |
| 7920 | // pack(s). |
| 7921 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7922 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 7923 | TypeLocBuilder TLB; |
| 7924 | TLB.reserve(PatternTL.getFullDataSize()); |
| 7925 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7926 | if (To.isNull()) |
| 7927 | return ExprError(); |
| 7928 | |
Eli Friedman | 20cfeca | 2013-07-19 21:49:32 +0000 | [diff] [blame^] | 7929 | if (To->containsUnexpandedParameterPack()) { |
| 7930 | To = getDerived().RebuildPackExpansionType(To, |
| 7931 | PatternTL.getSourceRange(), |
| 7932 | ExpansionTL.getEllipsisLoc(), |
| 7933 | NumExpansions); |
| 7934 | if (To.isNull()) |
| 7935 | return ExprError(); |
| 7936 | |
| 7937 | PackExpansionTypeLoc ToExpansionTL |
| 7938 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7939 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7940 | } |
| 7941 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7942 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7943 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7944 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7945 | if (!RetainExpansion) |
| 7946 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7947 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7948 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 7949 | // forgetting the partially-substituted parameter pack. |
| 7950 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7951 | |
| 7952 | TypeLocBuilder TLB; |
| 7953 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7954 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7955 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7956 | if (To.isNull()) |
| 7957 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7958 | |
| 7959 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7960 | PatternTL.getSourceRange(), |
| 7961 | ExpansionTL.getEllipsisLoc(), |
| 7962 | NumExpansions); |
| 7963 | if (To.isNull()) |
| 7964 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7965 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7966 | PackExpansionTypeLoc ToExpansionTL |
| 7967 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7968 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7969 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7970 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7971 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7972 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 7973 | return SemaRef.Owned(E); |
| 7974 | |
| 7975 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 7976 | E->getLocStart(), |
| 7977 | Args, |
| 7978 | E->getLocEnd()); |
| 7979 | } |
| 7980 | |
| 7981 | template<typename Derived> |
| 7982 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7983 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7984 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7985 | if (!T) |
| 7986 | return ExprError(); |
| 7987 | |
| 7988 | if (!getDerived().AlwaysRebuild() && |
| 7989 | T == E->getQueriedTypeSourceInfo()) |
| 7990 | return SemaRef.Owned(E); |
| 7991 | |
| 7992 | ExprResult SubExpr; |
| 7993 | { |
| 7994 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7995 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7996 | if (SubExpr.isInvalid()) |
| 7997 | return ExprError(); |
| 7998 | |
| 7999 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 8000 | return SemaRef.Owned(E); |
| 8001 | } |
| 8002 | |
| 8003 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8004 | E->getLocStart(), |
| 8005 | T, |
| 8006 | SubExpr.get(), |
| 8007 | E->getLocEnd()); |
| 8008 | } |
| 8009 | |
| 8010 | template<typename Derived> |
| 8011 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8012 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8013 | ExprResult SubExpr; |
| 8014 | { |
| 8015 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8016 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8017 | if (SubExpr.isInvalid()) |
| 8018 | return ExprError(); |
| 8019 | |
| 8020 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 8021 | return SemaRef.Owned(E); |
| 8022 | } |
| 8023 | |
| 8024 | return getDerived().RebuildExpressionTrait( |
| 8025 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8026 | } |
| 8027 | |
| 8028 | template<typename Derived> |
| 8029 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8030 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8031 | DependentScopeDeclRefExpr *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8032 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); |
| 8033 | } |
| 8034 | |
| 8035 | template<typename Derived> |
| 8036 | ExprResult |
| 8037 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8038 | DependentScopeDeclRefExpr *E, |
| 8039 | bool IsAddressOfOperand) { |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8040 | NestedNameSpecifierLoc QualifierLoc |
| 8041 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8042 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8043 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8044 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8045 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8046 | // TODO: If this is a conversion-function-id, verify that the |
| 8047 | // destination type name (if present) resolves the same way after |
| 8048 | // instantiation as it did in the local scope. |
| 8049 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8050 | DeclarationNameInfo NameInfo |
| 8051 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8052 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8053 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8054 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8055 | if (!E->hasExplicitTemplateArgs()) { |
| 8056 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8057 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8058 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8059 | // if name has not changed, DNLoc has not changed either. |
| 8060 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8061 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8062 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8063 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8064 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8065 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8066 | /*TemplateArgs*/ 0, |
| 8067 | IsAddressOfOperand); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8068 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8069 | |
| 8070 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8071 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8072 | E->getNumTemplateArgs(), |
| 8073 | TransArgs)) |
| 8074 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8075 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8076 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8077 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8078 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8079 | &TransArgs, |
| 8080 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8084 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8085 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8086 | // CXXConstructExprs other than for list-initialization and |
| 8087 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8088 | // a 1-argument construction we just transform that argument. |
Richard Smith | 73ed67c | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8089 | if ((E->getNumArgs() == 1 || |
| 8090 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8091 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8092 | !E->isListInitialization()) |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8093 | return getDerived().TransformExpr(E->getArg(0)); |
| 8094 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8095 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8096 | |
| 8097 | QualType T = getDerived().TransformType(E->getType()); |
| 8098 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8099 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8100 | |
| 8101 | CXXConstructorDecl *Constructor |
| 8102 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8103 | getDerived().TransformDecl(E->getLocStart(), |
| 8104 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8105 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8106 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8107 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8108 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8109 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8110 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8111 | &ArgumentChanged)) |
| 8112 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8113 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8114 | if (!getDerived().AlwaysRebuild() && |
| 8115 | T == E->getType() && |
| 8116 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8117 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8118 | // Mark the constructor as referenced. |
| 8119 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8120 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8121 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8122 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8123 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8124 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8125 | Constructor, E->isElidable(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8126 | Args, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8127 | E->hadMultipleCandidates(), |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8128 | E->isListInitialization(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8129 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8130 | E->getConstructionKind(), |
| 8131 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8133 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8134 | /// \brief Transform a C++ temporary-binding expression. |
| 8135 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8136 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8137 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8138 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8139 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8140 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8141 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8143 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8144 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8145 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8146 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8147 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8148 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8149 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8150 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8151 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8152 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8153 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8154 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8155 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8156 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8157 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8158 | CXXTemporaryObjectExpr *E) { |
| 8159 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8160 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8161 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8163 | CXXConstructorDecl *Constructor |
| 8164 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8165 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8166 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8167 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8168 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8169 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8170 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8171 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8172 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8173 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8174 | &ArgumentChanged)) |
| 8175 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8177 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8178 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8179 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8180 | !ArgumentChanged) { |
| 8181 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8182 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8183 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8184 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8185 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8186 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8187 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8188 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8189 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8190 | E->getLocEnd()); |
| 8191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8193 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8194 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8195 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8196 | // Transform the type of the lambda parameters and start the definition of |
| 8197 | // the lambda itself. |
| 8198 | TypeSourceInfo *MethodTy |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8199 | = TransformType(E->getCallOperator()->getTypeSourceInfo()); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8200 | if (!MethodTy) |
| 8201 | return ExprError(); |
| 8202 | |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8203 | // Create the local class that will describe the lambda. |
| 8204 | CXXRecordDecl *Class |
| 8205 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| 8206 | MethodTy, |
| 8207 | /*KnownDependent=*/false); |
| 8208 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8209 | |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8210 | // Transform lambda parameters. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8211 | SmallVector<QualType, 4> ParamTypes; |
| 8212 | SmallVector<ParmVarDecl *, 4> Params; |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8213 | if (getDerived().TransformFunctionTypeParams(E->getLocStart(), |
| 8214 | E->getCallOperator()->param_begin(), |
| 8215 | E->getCallOperator()->param_size(), |
| 8216 | 0, ParamTypes, &Params)) |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8217 | return ExprError(); |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8218 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8219 | // Build the call operator. |
| 8220 | CXXMethodDecl *CallOperator |
| 8221 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8222 | MethodTy, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8223 | E->getCallOperator()->getLocEnd(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8224 | Params); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8225 | getDerived().transformAttrs(E->getCallOperator(), CallOperator); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8226 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8227 | return getDerived().TransformLambdaScope(E, CallOperator); |
| 8228 | } |
| 8229 | |
| 8230 | template<typename Derived> |
| 8231 | ExprResult |
| 8232 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
| 8233 | CXXMethodDecl *CallOperator) { |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8234 | bool Invalid = false; |
| 8235 | |
| 8236 | // Transform any init-capture expressions before entering the scope of the |
| 8237 | // lambda. |
| 8238 | llvm::SmallVector<ExprResult, 8> InitCaptureExprs; |
| 8239 | InitCaptureExprs.resize(E->explicit_capture_end() - |
| 8240 | E->explicit_capture_begin()); |
| 8241 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8242 | CEnd = E->capture_end(); |
| 8243 | C != CEnd; ++C) { |
| 8244 | if (!C->isInitCapture()) |
| 8245 | continue; |
| 8246 | InitCaptureExprs[C - E->capture_begin()] = |
| 8247 | getDerived().TransformExpr(E->getInitCaptureInit(C)); |
| 8248 | } |
| 8249 | |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8250 | // Introduce the context of the call operator. |
| 8251 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 8252 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8253 | // Enter the scope of the lambda. |
| 8254 | sema::LambdaScopeInfo *LSI |
| 8255 | = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), |
| 8256 | E->getCaptureDefault(), |
| 8257 | E->hasExplicitParameters(), |
| 8258 | E->hasExplicitResultType(), |
| 8259 | E->isMutable()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8260 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8261 | // Transform captures. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8262 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8263 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8264 | CEnd = E->capture_end(); |
| 8265 | C != CEnd; ++C) { |
| 8266 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8267 | // the list of explicit captures. |
| 8268 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8269 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8270 | FinishedExplicitCaptures = true; |
| 8271 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8272 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8273 | // Capturing 'this' is trivial. |
| 8274 | if (C->capturesThis()) { |
| 8275 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8276 | continue; |
| 8277 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8278 | |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8279 | // Rebuild init-captures, including the implied field declaration. |
| 8280 | if (C->isInitCapture()) { |
| 8281 | ExprResult Init = InitCaptureExprs[C - E->capture_begin()]; |
| 8282 | if (Init.isInvalid()) { |
| 8283 | Invalid = true; |
| 8284 | continue; |
| 8285 | } |
| 8286 | FieldDecl *OldFD = C->getInitCaptureField(); |
| 8287 | FieldDecl *NewFD = getSema().checkInitCapture( |
| 8288 | C->getLocation(), OldFD->getType()->isReferenceType(), |
| 8289 | OldFD->getIdentifier(), Init.take()); |
| 8290 | if (!NewFD) |
| 8291 | Invalid = true; |
| 8292 | else |
| 8293 | getDerived().transformedLocalDecl(OldFD, NewFD); |
| 8294 | continue; |
| 8295 | } |
| 8296 | |
| 8297 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 8298 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8299 | // Determine the capture kind for Sema. |
| 8300 | Sema::TryCaptureKind Kind |
| 8301 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8302 | : C->getCaptureKind() == LCK_ByCopy |
| 8303 | ? Sema::TryCapture_ExplicitByVal |
| 8304 | : Sema::TryCapture_ExplicitByRef; |
| 8305 | SourceLocation EllipsisLoc; |
| 8306 | if (C->isPackExpansion()) { |
| 8307 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8308 | bool ShouldExpand = false; |
| 8309 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8310 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8311 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8312 | C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8313 | Unexpanded, |
| 8314 | ShouldExpand, RetainExpansion, |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8315 | NumExpansions)) { |
| 8316 | Invalid = true; |
| 8317 | continue; |
| 8318 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8319 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8320 | if (ShouldExpand) { |
| 8321 | // The transform has determined that we should perform an expansion; |
| 8322 | // transform and capture each of the arguments. |
| 8323 | // expansion of the pattern. Do so. |
| 8324 | VarDecl *Pack = C->getCapturedVar(); |
| 8325 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8326 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8327 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8328 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8329 | Pack)); |
| 8330 | if (!CapturedVar) { |
| 8331 | Invalid = true; |
| 8332 | continue; |
| 8333 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8334 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8335 | // Capture the transformed variable. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8336 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8337 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8338 | continue; |
| 8339 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8340 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8341 | EllipsisLoc = C->getEllipsisLoc(); |
| 8342 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8343 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8344 | // Transform the captured variable. |
| 8345 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8346 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8347 | C->getCapturedVar())); |
| 8348 | if (!CapturedVar) { |
| 8349 | Invalid = true; |
| 8350 | continue; |
| 8351 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8352 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8353 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8354 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8355 | } |
| 8356 | if (!FinishedExplicitCaptures) |
| 8357 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8358 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8359 | |
| 8360 | // Enter a new evaluation context to insulate the lambda from any |
| 8361 | // cleanups from the enclosing full-expression. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8362 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8363 | |
| 8364 | if (Invalid) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8365 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8366 | /*IsInstantiation=*/true); |
| 8367 | return ExprError(); |
| 8368 | } |
| 8369 | |
| 8370 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8371 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8372 | if (Body.isInvalid()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8373 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8374 | /*IsInstantiation=*/true); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8375 | return ExprError(); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8376 | } |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8377 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8378 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8379 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8380 | } |
| 8381 | |
| 8382 | template<typename Derived> |
| 8383 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8384 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8385 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8386 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8387 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8388 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8389 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8390 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8391 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8392 | Args.reserve(E->arg_size()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8393 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8394 | &ArgumentChanged)) |
| 8395 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8396 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8397 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8398 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8399 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8400 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8402 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8403 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8404 | E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8405 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8406 | E->getRParenLoc()); |
| 8407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8408 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8409 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8410 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8411 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8412 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8413 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8414 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8415 | Expr *OldBase; |
| 8416 | QualType BaseType; |
| 8417 | QualType ObjectType; |
| 8418 | if (!E->isImplicitAccess()) { |
| 8419 | OldBase = E->getBase(); |
| 8420 | Base = getDerived().TransformExpr(OldBase); |
| 8421 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8422 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8423 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8424 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8425 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8426 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8427 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8428 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8429 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8430 | ObjectTy, |
| 8431 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8432 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8433 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8434 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8435 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8436 | BaseType = ((Expr*) Base.get())->getType(); |
| 8437 | } else { |
| 8438 | OldBase = 0; |
| 8439 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8440 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8442 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8443 | // Transform the first part of the nested-name-specifier that qualifies |
| 8444 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8445 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8446 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8447 | E->getFirstQualifierFoundInScope(), |
| 8448 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8449 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8450 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8451 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8452 | QualifierLoc |
| 8453 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8454 | ObjectType, |
| 8455 | FirstQualifierInScope); |
| 8456 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8457 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8458 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8459 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8460 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8461 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8462 | // TODO: If this is a conversion-function-id, verify that the |
| 8463 | // destination type name (if present) resolves the same way after |
| 8464 | // instantiation as it did in the local scope. |
| 8465 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8466 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8467 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8468 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8469 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8470 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8471 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8472 | // This is a reference to a member without an explicitly-specified |
| 8473 | // template argument list. Optimize for this common case. |
| 8474 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8475 | Base.get() == OldBase && |
| 8476 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8477 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8478 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8479 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8480 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8481 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8482 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8483 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8484 | E->isArrow(), |
| 8485 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8486 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8487 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8488 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8489 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8490 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8491 | } |
| 8492 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8493 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8494 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8495 | E->getNumTemplateArgs(), |
| 8496 | TransArgs)) |
| 8497 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8498 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8499 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8500 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8501 | E->isArrow(), |
| 8502 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8503 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8504 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8505 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8506 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8507 | &TransArgs); |
| 8508 | } |
| 8509 | |
| 8510 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8511 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8512 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8513 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8514 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8515 | QualType BaseType; |
| 8516 | if (!Old->isImplicitAccess()) { |
| 8517 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8518 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8519 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8520 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8521 | Old->isArrow()); |
| 8522 | if (Base.isInvalid()) |
| 8523 | return ExprError(); |
| 8524 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8525 | } else { |
| 8526 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8527 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8528 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8529 | NestedNameSpecifierLoc QualifierLoc; |
| 8530 | if (Old->getQualifierLoc()) { |
| 8531 | QualifierLoc |
| 8532 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8533 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8534 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8535 | } |
| 8536 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8537 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8538 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8539 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8540 | Sema::LookupOrdinaryName); |
| 8541 | |
| 8542 | // Transform all the decls. |
| 8543 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8544 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8545 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8546 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8547 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8548 | if (!InstD) { |
| 8549 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8550 | // This can happen because of dependent hiding. |
| 8551 | if (isa<UsingShadowDecl>(*I)) |
| 8552 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8553 | else { |
| 8554 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8555 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8556 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8557 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8558 | |
| 8559 | // Expand using declarations. |
| 8560 | if (isa<UsingDecl>(InstD)) { |
| 8561 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8562 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8563 | E = UD->shadow_end(); I != E; ++I) |
| 8564 | R.addDecl(*I); |
| 8565 | continue; |
| 8566 | } |
| 8567 | |
| 8568 | R.addDecl(InstD); |
| 8569 | } |
| 8570 | |
| 8571 | R.resolveKind(); |
| 8572 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8573 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8574 | if (Old->getNamingClass()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8575 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8576 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8577 | Old->getMemberLoc(), |
| 8578 | Old->getNamingClass())); |
| 8579 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8580 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8581 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8582 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8583 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8584 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8585 | TemplateArgumentListInfo TransArgs; |
| 8586 | if (Old->hasExplicitTemplateArgs()) { |
| 8587 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8588 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8589 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8590 | Old->getNumTemplateArgs(), |
| 8591 | TransArgs)) |
| 8592 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8593 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8594 | |
| 8595 | // FIXME: to do this check properly, we will need to preserve the |
| 8596 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8597 | // base (and therefore couldn't do the check) and a |
| 8598 | // nested-name-qualifier (and therefore could do the lookup). |
| 8599 | NamedDecl *FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8600 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8601 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8602 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8603 | Old->getOperatorLoc(), |
| 8604 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8605 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8606 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8607 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8608 | R, |
| 8609 | (Old->hasExplicitTemplateArgs() |
| 8610 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8611 | } |
| 8612 | |
| 8613 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8614 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8615 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8616 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8617 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8618 | if (SubExpr.isInvalid()) |
| 8619 | return ExprError(); |
| 8620 | |
| 8621 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8622 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8623 | |
| 8624 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8625 | } |
| 8626 | |
| 8627 | template<typename Derived> |
| 8628 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8629 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8630 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8631 | if (Pattern.isInvalid()) |
| 8632 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8633 | |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8634 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8635 | return SemaRef.Owned(E); |
| 8636 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8637 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8638 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8639 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8640 | |
| 8641 | template<typename Derived> |
| 8642 | ExprResult |
| 8643 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8644 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8645 | // Note: This is an instantiation-centric view. |
| 8646 | if (!E->isValueDependent()) |
| 8647 | return SemaRef.Owned(E); |
| 8648 | |
| 8649 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8650 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8651 | // so |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8652 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8653 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8654 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8655 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8656 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8657 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8658 | ShouldExpand, RetainExpansion, |
| 8659 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8660 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8661 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8662 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8663 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8664 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8665 | NamedDecl *Pack = E->getPack(); |
| 8666 | if (!ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8667 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8668 | Pack)); |
| 8669 | if (!Pack) |
| 8670 | return ExprError(); |
| 8671 | } |
| 8672 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8673 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8674 | // We now know the length of the parameter pack, so build a new expression |
| 8675 | // that stores that length. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8676 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 8677 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8678 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8679 | } |
| 8680 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8681 | template<typename Derived> |
| 8682 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8683 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8684 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8685 | // Default behavior is to do nothing with this transformation. |
| 8686 | return SemaRef.Owned(E); |
| 8687 | } |
| 8688 | |
| 8689 | template<typename Derived> |
| 8690 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8691 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8692 | SubstNonTypeTemplateParmExpr *E) { |
| 8693 | // Default behavior is to do nothing with this transformation. |
| 8694 | return SemaRef.Owned(E); |
| 8695 | } |
| 8696 | |
| 8697 | template<typename Derived> |
| 8698 | ExprResult |
Richard Smith | 9a4db03 | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 8699 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 8700 | // Default behavior is to do nothing with this transformation. |
| 8701 | return SemaRef.Owned(E); |
| 8702 | } |
| 8703 | |
| 8704 | template<typename Derived> |
| 8705 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8706 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8707 | MaterializeTemporaryExpr *E) { |
| 8708 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8709 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8710 | |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8711 | template<typename Derived> |
| 8712 | ExprResult |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 8713 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 8714 | CXXStdInitializerListExpr *E) { |
| 8715 | return getDerived().TransformExpr(E->getSubExpr()); |
| 8716 | } |
| 8717 | |
| 8718 | template<typename Derived> |
| 8719 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8720 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8721 | return SemaRef.MaybeBindToTemporary(E); |
| 8722 | } |
| 8723 | |
| 8724 | template<typename Derived> |
| 8725 | ExprResult |
| 8726 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | d8b5ca1 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8727 | return SemaRef.Owned(E); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8728 | } |
| 8729 | |
| 8730 | template<typename Derived> |
| 8731 | ExprResult |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8732 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8733 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8734 | if (SubExpr.isInvalid()) |
| 8735 | return ExprError(); |
| 8736 | |
| 8737 | if (!getDerived().AlwaysRebuild() && |
| 8738 | SubExpr.get() == E->getSubExpr()) |
| 8739 | return SemaRef.Owned(E); |
| 8740 | |
| 8741 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8742 | } |
| 8743 | |
| 8744 | template<typename Derived> |
| 8745 | ExprResult |
| 8746 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8747 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8748 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8749 | bool ArgChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8750 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8751 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8752 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8753 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8754 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8755 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8756 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8757 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8758 | Elements.data(), |
| 8759 | Elements.size()); |
| 8760 | } |
| 8761 | |
| 8762 | template<typename Derived> |
| 8763 | ExprResult |
| 8764 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8765 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8766 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8767 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8768 | bool ArgChanged = false; |
| 8769 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8770 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8771 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8772 | if (OrigElement.isPackExpansion()) { |
| 8773 | // This key/value element is a pack expansion. |
| 8774 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8775 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8776 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8777 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8778 | |
| 8779 | // Determine whether the set of unexpanded parameter packs can |
| 8780 | // and should be expanded. |
| 8781 | bool Expand = true; |
| 8782 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8783 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8784 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8785 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8786 | OrigElement.Value->getLocEnd()); |
| 8787 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8788 | PatternRange, |
| 8789 | Unexpanded, |
| 8790 | Expand, RetainExpansion, |
| 8791 | NumExpansions)) |
| 8792 | return ExprError(); |
| 8793 | |
| 8794 | if (!Expand) { |
| 8795 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8796 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8797 | // expansion. |
| 8798 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8799 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8800 | if (Key.isInvalid()) |
| 8801 | return ExprError(); |
| 8802 | |
| 8803 | if (Key.get() != OrigElement.Key) |
| 8804 | ArgChanged = true; |
| 8805 | |
| 8806 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8807 | if (Value.isInvalid()) |
| 8808 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8809 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8810 | if (Value.get() != OrigElement.Value) |
| 8811 | ArgChanged = true; |
| 8812 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8813 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8814 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8815 | }; |
| 8816 | Elements.push_back(Expansion); |
| 8817 | continue; |
| 8818 | } |
| 8819 | |
| 8820 | // Record right away that the argument was changed. This needs |
| 8821 | // to happen even if the array expands to nothing. |
| 8822 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8823 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8824 | // The transform has determined that we should perform an elementwise |
| 8825 | // expansion of the pattern. Do so. |
| 8826 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8827 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8828 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8829 | if (Key.isInvalid()) |
| 8830 | return ExprError(); |
| 8831 | |
| 8832 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8833 | if (Value.isInvalid()) |
| 8834 | return ExprError(); |
| 8835 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8836 | ObjCDictionaryElement Element = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8837 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8838 | }; |
| 8839 | |
| 8840 | // If any unexpanded parameter packs remain, we still have a |
| 8841 | // pack expansion. |
| 8842 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8843 | Value.get()->containsUnexpandedParameterPack()) |
| 8844 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8845 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8846 | Elements.push_back(Element); |
| 8847 | } |
| 8848 | |
| 8849 | // We've finished with this pack expansion. |
| 8850 | continue; |
| 8851 | } |
| 8852 | |
| 8853 | // Transform and check key. |
| 8854 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8855 | if (Key.isInvalid()) |
| 8856 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8857 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8858 | if (Key.get() != OrigElement.Key) |
| 8859 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8860 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8861 | // Transform and check value. |
| 8862 | ExprResult Value |
| 8863 | = getDerived().TransformExpr(OrigElement.Value); |
| 8864 | if (Value.isInvalid()) |
| 8865 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8866 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8867 | if (Value.get() != OrigElement.Value) |
| 8868 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8869 | |
| 8870 | ObjCDictionaryElement Element = { |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 8871 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8872 | }; |
| 8873 | Elements.push_back(Element); |
| 8874 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8875 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8876 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8877 | return SemaRef.MaybeBindToTemporary(E); |
| 8878 | |
| 8879 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 8880 | Elements.data(), |
| 8881 | Elements.size()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8882 | } |
| 8883 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8884 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8885 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8886 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8887 | TypeSourceInfo *EncodedTypeInfo |
| 8888 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 8889 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8890 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8891 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8892 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8893 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8894 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8895 | |
| 8896 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 8897 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8898 | E->getRParenLoc()); |
| 8899 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8900 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8901 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8902 | ExprResult TreeTransform<Derived>:: |
| 8903 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | 93b6457 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 8904 | // This is a kind of implicit conversion, and it needs to get dropped |
| 8905 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 8906 | // do, as well a more specific one: this expression is only valid when |
| 8907 | // it appears *immediately* as an argument expression. |
| 8908 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8909 | } |
| 8910 | |
| 8911 | template<typename Derived> |
| 8912 | ExprResult TreeTransform<Derived>:: |
| 8913 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8914 | TypeSourceInfo *TSInfo |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8915 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 8916 | if (!TSInfo) |
| 8917 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8918 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8919 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8920 | if (Result.isInvalid()) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8921 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8922 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8923 | if (!getDerived().AlwaysRebuild() && |
| 8924 | TSInfo == E->getTypeInfoAsWritten() && |
| 8925 | Result.get() == E->getSubExpr()) |
| 8926 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8927 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8928 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8929 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 8930 | Result.get()); |
| 8931 | } |
| 8932 | |
| 8933 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8934 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8935 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8936 | // Transform arguments. |
| 8937 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8938 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8939 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8940 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8941 | &ArgChanged)) |
| 8942 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8943 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8944 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 8945 | // Class message: transform the receiver type. |
| 8946 | TypeSourceInfo *ReceiverTypeInfo |
| 8947 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 8948 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8949 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8950 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8951 | // If nothing changed, just retain the existing message send. |
| 8952 | if (!getDerived().AlwaysRebuild() && |
| 8953 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8954 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8955 | |
| 8956 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8957 | SmallVector<SourceLocation, 16> SelLocs; |
| 8958 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8959 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 8960 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8961 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8962 | E->getMethodDecl(), |
| 8963 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8964 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8965 | E->getRightLoc()); |
| 8966 | } |
| 8967 | |
| 8968 | // Instance message: transform the receiver |
| 8969 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 8970 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8971 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8972 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 8973 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8974 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8975 | |
| 8976 | // If nothing changed, just retain the existing message send. |
| 8977 | if (!getDerived().AlwaysRebuild() && |
| 8978 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 8979 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8980 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8981 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8982 | SmallVector<SourceLocation, 16> SelLocs; |
| 8983 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8984 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8985 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 8986 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8987 | E->getMethodDecl(), |
| 8988 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8989 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8990 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8991 | } |
| 8992 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8993 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8994 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8995 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8996 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8997 | } |
| 8998 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8999 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9000 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9001 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9002 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9003 | } |
| 9004 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9005 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9006 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9007 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9008 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9009 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9010 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9011 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9012 | |
| 9013 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9014 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9015 | // If nothing changed, just retain the existing expression. |
| 9016 | if (!getDerived().AlwaysRebuild() && |
| 9017 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9018 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9019 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9020 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9021 | E->getLocation(), |
| 9022 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9023 | } |
| 9024 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9025 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9026 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9027 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9028 | // 'super' and types never change. Property never changes. Just |
| 9029 | // retain the existing expression. |
| 9030 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9031 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9032 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9033 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9034 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9035 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9036 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9037 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9038 | // We don't need to transform the property; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9039 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9040 | // If nothing changed, just retain the existing expression. |
| 9041 | if (!getDerived().AlwaysRebuild() && |
| 9042 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9043 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9044 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9045 | if (E->isExplicitProperty()) |
| 9046 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9047 | E->getExplicitProperty(), |
| 9048 | E->getLocation()); |
| 9049 | |
| 9050 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9051 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9052 | E->getImplicitPropertyGetter(), |
| 9053 | E->getImplicitPropertySetter(), |
| 9054 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9055 | } |
| 9056 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9057 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9058 | ExprResult |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9059 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9060 | // Transform the base expression. |
| 9061 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9062 | if (Base.isInvalid()) |
| 9063 | return ExprError(); |
| 9064 | |
| 9065 | // Transform the key expression. |
| 9066 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9067 | if (Key.isInvalid()) |
| 9068 | return ExprError(); |
| 9069 | |
| 9070 | // If nothing changed, just retain the existing expression. |
| 9071 | if (!getDerived().AlwaysRebuild() && |
| 9072 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 9073 | return SemaRef.Owned(E); |
| 9074 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9075 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9076 | Base.get(), Key.get(), |
| 9077 | E->getAtIndexMethodDecl(), |
| 9078 | E->setAtIndexMethodDecl()); |
| 9079 | } |
| 9080 | |
| 9081 | template<typename Derived> |
| 9082 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9083 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9084 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9085 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9086 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9087 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9088 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9089 | // If nothing changed, just retain the existing expression. |
| 9090 | if (!getDerived().AlwaysRebuild() && |
| 9091 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9092 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9093 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9094 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9095 | E->getOpLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9096 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9097 | } |
| 9098 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9099 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9100 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9101 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9102 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9103 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9104 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9105 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9106 | SubExprs, &ArgumentChanged)) |
| 9107 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9108 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9109 | if (!getDerived().AlwaysRebuild() && |
| 9110 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9111 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9113 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9114 | SubExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9115 | E->getRParenLoc()); |
| 9116 | } |
| 9117 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9118 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9119 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9120 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9121 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9122 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9123 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 9124 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 9125 | |
| 9126 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 9127 | blockScope->TheDecl->setBlockMissingReturnType( |
| 9128 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9129 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9130 | SmallVector<ParmVarDecl*, 4> params; |
| 9131 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9132 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 9133 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9134 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 9135 | oldBlock->param_begin(), |
| 9136 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9137 | 0, paramTypes, ¶ms)) { |
| 9138 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9139 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9140 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9141 | |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9142 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9143 | QualType exprResultType = |
| 9144 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 9145 | |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9146 | QualType functionType = |
| 9147 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9148 | exprFunctionType->getExtProtoInfo()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9149 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9150 | |
| 9151 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9152 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 9153 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9154 | |
| 9155 | if (!oldBlock->blockMissingReturnType()) { |
| 9156 | blockScope->HasImplicitReturnType = false; |
| 9157 | blockScope->ReturnType = exprResultType; |
| 9158 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9159 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9160 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9161 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9162 | if (body.isInvalid()) { |
| 9163 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9164 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9165 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9166 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9167 | #ifndef NDEBUG |
| 9168 | // In builds with assertions, make sure that we captured everything we |
| 9169 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9170 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 9171 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 9172 | e = oldBlock->capture_end(); i != e; ++i) { |
| 9173 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9174 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9175 | // Ignore parameter packs. |
| 9176 | if (isa<ParmVarDecl>(oldCapture) && |
| 9177 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 9178 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9179 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9180 | VarDecl *newCapture = |
| 9181 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 9182 | oldCapture)); |
| 9183 | assert(blockScope->CaptureMap.count(newCapture)); |
| 9184 | } |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9185 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9186 | } |
| 9187 | #endif |
| 9188 | |
| 9189 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 9190 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9191 | } |
| 9192 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9193 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9194 | ExprResult |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9195 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 9196 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9197 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9198 | |
| 9199 | template<typename Derived> |
| 9200 | ExprResult |
| 9201 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9202 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 9203 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9204 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9205 | SubExprs.reserve(E->getNumSubExprs()); |
| 9206 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 9207 | SubExprs, &ArgumentChanged)) |
| 9208 | return ExprError(); |
| 9209 | |
| 9210 | if (!getDerived().AlwaysRebuild() && |
| 9211 | !ArgumentChanged) |
| 9212 | return SemaRef.Owned(E); |
| 9213 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9214 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9215 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9216 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9218 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9219 | // Type reconstruction |
| 9220 | //===----------------------------------------------------------------------===// |
| 9221 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9222 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9223 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 9224 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9225 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9226 | getDerived().getBaseEntity()); |
| 9227 | } |
| 9228 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9229 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9230 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 9231 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9232 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9233 | getDerived().getBaseEntity()); |
| 9234 | } |
| 9235 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9236 | template<typename Derived> |
| 9237 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9238 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9239 | bool WrittenAsLValue, |
| 9240 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9241 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9242 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9243 | } |
| 9244 | |
| 9245 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9246 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9247 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9248 | QualType ClassType, |
| 9249 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9250 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9251 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9252 | } |
| 9253 | |
| 9254 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9255 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9256 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9257 | ArrayType::ArraySizeModifier SizeMod, |
| 9258 | const llvm::APInt *Size, |
| 9259 | Expr *SizeExpr, |
| 9260 | unsigned IndexTypeQuals, |
| 9261 | SourceRange BracketsRange) { |
| 9262 | if (SizeExpr || !Size) |
| 9263 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9264 | IndexTypeQuals, BracketsRange, |
| 9265 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9266 | |
| 9267 | QualType Types[] = { |
| 9268 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9269 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9270 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9271 | }; |
Craig Topper | b960232 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 9272 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9273 | QualType SizeType; |
| 9274 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9275 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9276 | SizeType = Types[I]; |
| 9277 | break; |
| 9278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9279 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9280 | // Note that we can return a VariableArrayType here in the case where |
| 9281 | // the element type was a dependent VariableArrayType. |
| 9282 | IntegerLiteral *ArraySize |
| 9283 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9284 | /*FIXME*/BracketsRange.getBegin()); |
| 9285 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9286 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9287 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9288 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9289 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9290 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9291 | QualType |
| 9292 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9293 | ArrayType::ArraySizeModifier SizeMod, |
| 9294 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9295 | unsigned IndexTypeQuals, |
| 9296 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9297 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9298 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9299 | } |
| 9300 | |
| 9301 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9302 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9303 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9304 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9305 | unsigned IndexTypeQuals, |
| 9306 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9307 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9308 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9309 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9310 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9311 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9312 | QualType |
| 9313 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9314 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9315 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9316 | unsigned IndexTypeQuals, |
| 9317 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9318 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9319 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9320 | IndexTypeQuals, BracketsRange); |
| 9321 | } |
| 9322 | |
| 9323 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9324 | QualType |
| 9325 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9326 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9327 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9328 | unsigned IndexTypeQuals, |
| 9329 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9330 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9331 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9332 | IndexTypeQuals, BracketsRange); |
| 9333 | } |
| 9334 | |
| 9335 | template<typename Derived> |
| 9336 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9337 | unsigned NumElements, |
| 9338 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9339 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9340 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9341 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9342 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9343 | template<typename Derived> |
| 9344 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 9345 | unsigned NumElements, |
| 9346 | SourceLocation AttributeLoc) { |
| 9347 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9348 | NumElements, true); |
| 9349 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9350 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9351 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9352 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9354 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9355 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9356 | QualType |
| 9357 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9358 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9359 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9360 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9362 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9363 | template<typename Derived> |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9364 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 9365 | QualType T, |
| 9366 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9367 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 9368 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9369 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9370 | getDerived().getBaseEntity(), |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9371 | EPI); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9373 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9374 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9375 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9376 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9377 | } |
| 9378 | |
| 9379 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9380 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9381 | assert(D && "no decl found"); |
| 9382 | if (D->isInvalidDecl()) return QualType(); |
| 9383 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9384 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9385 | TypeDecl *Ty; |
| 9386 | if (isa<UsingDecl>(D)) { |
| 9387 | UsingDecl *Using = cast<UsingDecl>(D); |
| 9388 | assert(Using->isTypeName() && |
| 9389 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9390 | |
| 9391 | // A valid resolved using typename decl points to exactly one type decl. |
| 9392 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9393 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9394 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9395 | } else { |
| 9396 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9397 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9398 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9399 | } |
| 9400 | |
| 9401 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9402 | } |
| 9403 | |
| 9404 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9405 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9406 | SourceLocation Loc) { |
| 9407 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9408 | } |
| 9409 | |
| 9410 | template<typename Derived> |
| 9411 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9412 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9413 | } |
| 9414 | |
| 9415 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9416 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9417 | SourceLocation Loc) { |
| 9418 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9419 | } |
| 9420 | |
| 9421 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9422 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9423 | UnaryTransformType::UTTKind UKind, |
| 9424 | SourceLocation Loc) { |
| 9425 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9426 | } |
| 9427 | |
| 9428 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9429 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9430 | TemplateName Template, |
| 9431 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9432 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9433 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9434 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9435 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9436 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9437 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9438 | SourceLocation KWLoc) { |
| 9439 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9440 | } |
| 9441 | |
| 9442 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9443 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9444 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9445 | bool TemplateKW, |
| 9446 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9447 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9448 | Template); |
| 9449 | } |
| 9450 | |
| 9451 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9452 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9453 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9454 | const IdentifierInfo &Name, |
| 9455 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9456 | QualType ObjectType, |
| 9457 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9458 | UnqualifiedId TemplateName; |
| 9459 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9460 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9461 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9462 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9463 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9464 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9465 | /*EnteringContext=*/false, |
| 9466 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9467 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9470 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9471 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9472 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9473 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9474 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9475 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9476 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9477 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9478 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9479 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9480 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9481 | Sema::TemplateTy Template; |
| 9482 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9483 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9484 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9485 | /*EnteringContext=*/false, |
| 9486 | Template); |
| 9487 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9488 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9489 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9490 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9491 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9492 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9493 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9494 | Expr *OrigCallee, |
| 9495 | Expr *First, |
| 9496 | Expr *Second) { |
| 9497 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9498 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9499 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9500 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9501 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9502 | if (!First->getType()->isOverloadableType() && |
| 9503 | !Second->getType()->isOverloadableType()) |
| 9504 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9505 | Callee->getLocStart(), |
| 9506 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9507 | } else if (Op == OO_Arrow) { |
| 9508 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9509 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9510 | } else if (Second == 0 || isPostIncDec) { |
| 9511 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9512 | // The argument is not of overloadable type, so try to create a |
| 9513 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9514 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9515 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9516 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9517 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9518 | } |
| 9519 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9520 | if (!First->getType()->isOverloadableType() && |
| 9521 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9522 | // Neither of the arguments is an overloadable type, so try to |
| 9523 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9524 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9525 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9526 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9527 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9528 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9529 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9530 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9531 | } |
| 9532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9533 | |
| 9534 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9535 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9536 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9537 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9538 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9539 | assert(ULE->requiresADL()); |
| 9540 | |
| 9541 | // FIXME: Do we have to check |
| 9542 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9543 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9544 | } else { |
Richard Smith | f641166 | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 9545 | // If we've resolved this to a particular non-member function, just call |
| 9546 | // that function. If we resolved it to a member function, |
| 9547 | // CreateOverloaded* will find that function for us. |
| 9548 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 9549 | if (!isa<CXXMethodDecl>(ND)) |
| 9550 | Functions.addDecl(ND); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9551 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9552 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9553 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9554 | Expr *Args[2] = { First, Second }; |
| 9555 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9557 | // Create the overloaded operator invocation for unary operators. |
| 9558 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9559 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9560 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9561 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9562 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9563 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9564 | if (Op == OO_Subscript) { |
| 9565 | SourceLocation LBrace; |
| 9566 | SourceLocation RBrace; |
| 9567 | |
| 9568 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9569 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9570 | LBrace = SourceLocation::getFromRawEncoding( |
| 9571 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9572 | RBrace = SourceLocation::getFromRawEncoding( |
| 9573 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9574 | } else { |
| 9575 | LBrace = Callee->getLocStart(); |
| 9576 | RBrace = OpLoc; |
| 9577 | } |
| 9578 | |
| 9579 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9580 | First, Second); |
| 9581 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9582 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9583 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9584 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9585 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9586 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9587 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9588 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9589 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9590 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9592 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9593 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9594 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9595 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9596 | SourceLocation OperatorLoc, |
| 9597 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9598 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9599 | TypeSourceInfo *ScopeType, |
| 9600 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9601 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9602 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9603 | QualType BaseType = Base->getType(); |
| 9604 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9605 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9606 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9607 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9608 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9609 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9610 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9611 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9612 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9613 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9614 | /*FIXME?*/true); |
| 9615 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9616 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9617 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9618 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9619 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9620 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9621 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9622 | |
Richard Smith | 6314db9 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9623 | // The scope type is now known to be a valid nested name specifier |
| 9624 | // component. Tack it on to the end of the nested name specifier. |
| 9625 | if (ScopeType) |
| 9626 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9627 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9628 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9629 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9630 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9631 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9632 | SS, TemplateKWLoc, |
| 9633 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9634 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9635 | /*TemplateArgs*/ 0); |
| 9636 | } |
| 9637 | |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9638 | template<typename Derived> |
| 9639 | StmtResult |
| 9640 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 9641 | SourceLocation Loc = S->getLocStart(); |
| 9642 | unsigned NumParams = S->getCapturedDecl()->getNumParams(); |
| 9643 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0, |
| 9644 | S->getCapturedRegionKind(), NumParams); |
| 9645 | StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 9646 | |
| 9647 | if (Body.isInvalid()) { |
| 9648 | getSema().ActOnCapturedRegionError(); |
| 9649 | return StmtError(); |
| 9650 | } |
| 9651 | |
| 9652 | return getSema().ActOnCapturedRegionEnd(Body.take()); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9653 | } |
| 9654 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9655 | } // end namespace clang |
| 9656 | |
| 9657 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |