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. |
Richard Smith | baa9af1 | 2013-11-07 20:07:17 +0000 | [diff] [blame] | 145 | /// |
| 146 | /// We must always rebuild all AST nodes when performing variadic template |
| 147 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 148 | /// statement node appears at most once in its containing declaration. |
| 149 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 151 | /// \brief Returns the location of the entity being transformed, if that |
| 152 | /// information was not available elsewhere in the AST. |
| 153 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 155 | /// provide an alternative implementation that provides better location |
| 156 | /// information. |
| 157 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 159 | /// \brief Returns the name of the entity being transformed, if that |
| 160 | /// information was not available elsewhere in the AST. |
| 161 | /// |
| 162 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 163 | /// implementation with a more precise name. |
| 164 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 165 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 166 | /// \brief Sets the "base" location and entity when that |
| 167 | /// information is known based on another transformation. |
| 168 | /// |
| 169 | /// By default, the source location and entity are ignored. Subclasses can |
| 170 | /// override this function to provide a customized implementation. |
| 171 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 173 | /// \brief RAII object that temporarily sets the base location and entity |
| 174 | /// used for reporting diagnostics in types. |
| 175 | class TemporaryBase { |
| 176 | TreeTransform &Self; |
| 177 | SourceLocation OldLocation; |
| 178 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 180 | public: |
| 181 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 183 | OldLocation = Self.getDerived().getBaseLocation(); |
| 184 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 186 | if (Location.isValid()) |
| 187 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 190 | ~TemporaryBase() { |
| 191 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 192 | } |
| 193 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | |
| 195 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 196 | /// transformed. |
| 197 | /// |
| 198 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | /// 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] | 200 | /// not change. For example, template instantiation need not traverse |
| 201 | /// non-dependent types. |
| 202 | bool AlreadyTransformed(QualType T) { |
| 203 | return T.isNull(); |
| 204 | } |
| 205 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 206 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 207 | /// because it is a default argument. |
| 208 | /// |
| 209 | /// Subclasses can provide an alternative implementation of this routine to |
| 210 | /// determine which kinds of call arguments get dropped. By default, |
| 211 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 212 | bool DropCallArgument(Expr *E) { |
| 213 | return E->isDefaultArgument(); |
| 214 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 215 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 216 | /// \brief Determine whether we should expand a pack expansion with the |
| 217 | /// given set of parameter packs into separate arguments by repeatedly |
| 218 | /// transforming the pattern. |
| 219 | /// |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 220 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 221 | /// Subclasses can override this routine to provide different behavior. |
| 222 | /// |
| 223 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 224 | /// pack expansion. |
| 225 | /// |
| 226 | /// \param PatternRange The source range that covers the entire pattern of |
| 227 | /// the pack expansion. |
| 228 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 229 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 230 | /// pattern. |
| 231 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 232 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 233 | /// expand the corresponding pack expansions into separate arguments. When |
| 234 | /// set, \c NumExpansions must also be set. |
| 235 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 236 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 237 | /// pack expansion after all of the expanded arguments. This is used |
| 238 | /// when extending explicitly-specified template argument packs per |
| 239 | /// C++0x [temp.arg.explicit]p9. |
| 240 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 241 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 242 | /// the expanded form of the corresponding pack expansion. This is both an |
| 243 | /// input and an output parameter, which can be set by the caller if the |
| 244 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 245 | /// and will be set by the callee when the number of expansions is known. |
| 246 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 247 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 248 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 249 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 250 | /// are to be instantiated with arguments of different lengths), false |
| 251 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | /// must be set. |
| 253 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 254 | SourceRange PatternRange, |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 255 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 256 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 257 | bool &RetainExpansion, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 258 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 259 | ShouldExpand = false; |
| 260 | return false; |
| 261 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 263 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 264 | /// when performing an instantiation that must preserve the parameter pack |
| 265 | /// use. |
| 266 | /// |
| 267 | /// This routine is meant to be overridden by the template instantiator. |
| 268 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 269 | return TemplateArgument(); |
| 270 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 272 | /// \brief "Remember" the partially-substituted pack template argument |
| 273 | /// after performing an instantiation that must preserve the parameter pack |
| 274 | /// use. |
| 275 | /// |
| 276 | /// This routine is meant to be overridden by the template instantiator. |
| 277 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 279 | /// \brief Note to the derived class when a function parameter pack is |
| 280 | /// being expanded. |
| 281 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transforms the given type into another type. |
| 284 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 285 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 286 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 287 | /// function. This is expensive, but we don't mind, because |
| 288 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 289 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 290 | /// |
| 291 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 292 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 294 | /// \brief Transforms the given type-with-location into a new |
| 295 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 296 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 297 | /// By default, this routine transforms a type by delegating to the |
| 298 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 299 | /// may override this function (to take over all type |
| 300 | /// transformations) or some set of the TransformXXXType functions |
| 301 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 302 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 303 | |
| 304 | /// \brief Transform the given type-with-location into a new |
| 305 | /// type, collecting location information in the given builder |
| 306 | /// as necessary. |
| 307 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 308 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 310 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 311 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 313 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 314 | /// statement or the TransformExpr() function to transform an expression. |
| 315 | /// Subclasses may override this function to transform statements using some |
| 316 | /// other mechanism. |
| 317 | /// |
| 318 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 319 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 320 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 321 | /// \brief Transform the given statement. |
| 322 | /// |
| 323 | /// By default, this routine transforms a statement by delegating to the |
| 324 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 325 | /// of clause. Subclasses may override this function to transform statements |
| 326 | /// using some other mechanism. |
| 327 | /// |
| 328 | /// \returns the transformed OpenMP clause. |
| 329 | OMPClause *TransformOMPClause(OMPClause *S); |
| 330 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 331 | /// \brief Transform the given expression. |
| 332 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 333 | /// By default, this routine transforms an expression by delegating to the |
| 334 | /// appropriate TransformXXXExpr function to build a new expression. |
| 335 | /// Subclasses may override this function to transform expressions using some |
| 336 | /// other mechanism. |
| 337 | /// |
| 338 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 339 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 341 | /// \brief Transform the given initializer. |
| 342 | /// |
| 343 | /// By default, this routine transforms an initializer by stripping off the |
| 344 | /// semantic nodes added by initialization, then passing the result to |
| 345 | /// TransformExpr or TransformExprs. |
| 346 | /// |
| 347 | /// \returns the transformed initializer. |
| 348 | ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit); |
| 349 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 350 | /// \brief Transform the given list of expressions. |
| 351 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 352 | /// This routine transforms a list of expressions by invoking |
| 353 | /// \c TransformExpr() for each subexpression. However, it also provides |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 354 | /// support for variadic templates by expanding any pack expansions (if the |
| 355 | /// derived class permits such expansion) along the way. When pack expansions |
| 356 | /// are present, the number of outputs may not equal the number of inputs. |
| 357 | /// |
| 358 | /// \param Inputs The set of expressions to be transformed. |
| 359 | /// |
| 360 | /// \param NumInputs The number of expressions in \c Inputs. |
| 361 | /// |
| 362 | /// \param IsCall If \c true, then this transform is being performed on |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 363 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 364 | /// be. |
| 365 | /// |
| 366 | /// \param Outputs The transformed input expressions will be added to this |
| 367 | /// vector. |
| 368 | /// |
| 369 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 370 | /// due to transformation. |
| 371 | /// |
| 372 | /// \returns true if an error occurred, false otherwise. |
| 373 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 374 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 375 | bool *ArgChanged = 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 376 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 377 | /// \brief Transform the given declaration, which is referenced from a type |
| 378 | /// or expression. |
| 379 | /// |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 380 | /// By default, acts as the identity function on declarations, unless the |
| 381 | /// transformer has had to transform the declaration itself. Subclasses |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 382 | /// may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 383 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 384 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 385 | = TransformedLocalDecls.find(D); |
| 386 | if (Known != TransformedLocalDecls.end()) |
| 387 | return Known->second; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 388 | |
| 389 | return D; |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 390 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 391 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 392 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 393 | /// place them on the new declaration. |
| 394 | /// |
| 395 | /// By default, this operation does nothing. Subclasses may override this |
| 396 | /// behavior to transform attributes. |
| 397 | void transformAttrs(Decl *Old, Decl *New) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 399 | /// \brief Note that a local declaration has been transformed by this |
| 400 | /// transformer. |
| 401 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 402 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 403 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 404 | /// the transformer itself has to transform the declarations. This routine |
| 405 | /// can be overridden by a subclass that keeps track of such mappings. |
| 406 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 407 | TransformedLocalDecls[Old] = New; |
| 408 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 409 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 410 | /// \brief Transform the definition of the given declaration. |
| 411 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 413 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 414 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 415 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 418 | /// \brief Transform the given declaration, which was the first part of a |
| 419 | /// nested-name-specifier in a member access expression. |
| 420 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 421 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 422 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 423 | /// the \c T in \c x->T::member |
| 424 | /// |
| 425 | /// By default, invokes TransformDecl() to transform the declaration. |
| 426 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 427 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 428 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 429 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 430 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 431 | /// \brief Transform the given nested-name-specifier with source-location |
| 432 | /// information. |
| 433 | /// |
| 434 | /// By default, transforms all of the types and declarations within the |
| 435 | /// nested-name-specifier. Subclasses may override this function to provide |
| 436 | /// alternate behavior. |
| 437 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 438 | NestedNameSpecifierLoc NNS, |
| 439 | QualType ObjectType = QualType(), |
| 440 | NamedDecl *FirstQualifierInScope = 0); |
| 441 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 442 | /// \brief Transform the given declaration name. |
| 443 | /// |
| 444 | /// By default, transforms the types of conversion function, constructor, |
| 445 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 446 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 447 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 448 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 449 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 451 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | /// |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 453 | /// \param SS The nested-name-specifier that qualifies the template |
| 454 | /// name. This nested-name-specifier must already have been transformed. |
| 455 | /// |
| 456 | /// \param Name The template name to transform. |
| 457 | /// |
| 458 | /// \param NameLoc The source location of the template name. |
| 459 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 460 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 461 | /// access expression, this is the type of the object whose member template |
| 462 | /// is being referenced. |
| 463 | /// |
| 464 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 465 | /// also refers to a name within the current (lexical) scope, this is the |
| 466 | /// declaration it refers to. |
| 467 | /// |
| 468 | /// By default, transforms the template name by transforming the declarations |
| 469 | /// and nested-name-specifiers that occur within the template name. |
| 470 | /// Subclasses may override this function to provide alternate behavior. |
| 471 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 472 | TemplateName Name, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 473 | SourceLocation NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 474 | QualType ObjectType = QualType(), |
| 475 | NamedDecl *FirstQualifierInScope = 0); |
| 476 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 477 | /// \brief Transform the given template argument. |
| 478 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | /// By default, this operation transforms the type, expression, or |
| 480 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 481 | /// new template argument from the transformed result. Subclasses may |
| 482 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 483 | /// |
| 484 | /// Returns true if there was an error. |
| 485 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 486 | TemplateArgumentLoc &Output); |
| 487 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 488 | /// \brief Transform the given set of template arguments. |
| 489 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 490 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 491 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 492 | /// the transformed arguments to the output list. |
| 493 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 494 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 495 | /// a convenience function. Subclasses that wish to override this behavior |
| 496 | /// should override the iterator-based member template version. |
| 497 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 498 | /// \param Inputs The set of template arguments to be transformed. |
| 499 | /// |
| 500 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 501 | /// |
| 502 | /// \param Outputs The set of transformed template arguments output by this |
| 503 | /// routine. |
| 504 | /// |
| 505 | /// Returns true if an error occurred. |
| 506 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 507 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 508 | TemplateArgumentListInfo &Outputs) { |
| 509 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 510 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 511 | |
| 512 | /// \brief Transform the given set of template arguments. |
| 513 | /// |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 514 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 515 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 516 | /// the transformed arguments to the output list. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 517 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 518 | /// \param First An iterator to the first template argument. |
| 519 | /// |
| 520 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 521 | /// |
| 522 | /// \param Outputs The set of transformed template arguments output by this |
| 523 | /// routine. |
| 524 | /// |
| 525 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 526 | template<typename InputIterator> |
| 527 | bool TransformTemplateArguments(InputIterator First, |
| 528 | InputIterator Last, |
| 529 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 530 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 531 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 532 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 533 | TemplateArgumentLoc &ArgLoc); |
| 534 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 535 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 536 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 537 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 538 | getDerived().getBaseLocation()); |
| 539 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 541 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 542 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 543 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 544 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 545 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 546 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 547 | FunctionProtoTypeLoc TL, |
| 548 | CXXRecordDecl *ThisContext, |
| 549 | unsigned ThisTypeQuals); |
| 550 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 551 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 552 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 553 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 554 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 555 | TemplateSpecializationTypeLoc TL, |
| 556 | TemplateName Template); |
| 557 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 558 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 559 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 560 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 561 | TemplateName Template, |
| 562 | CXXScopeSpec &SS); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 563 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 564 | QualType |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 565 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 566 | DependentTemplateSpecializationTypeLoc TL, |
| 567 | NestedNameSpecifierLoc QualifierLoc); |
| 568 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 569 | /// \brief Transforms the parameters of a function type into the |
| 570 | /// given vectors. |
| 571 | /// |
| 572 | /// The result vectors should be kept in sync; null entries in the |
| 573 | /// variables vector are acceptable. |
| 574 | /// |
| 575 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 576 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 577 | ParmVarDecl **Params, unsigned NumParams, |
| 578 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 579 | SmallVectorImpl<QualType> &PTypes, |
| 580 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 581 | |
| 582 | /// \brief Transforms a single function-type parameter. Return null |
| 583 | /// on error. |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 584 | /// |
| 585 | /// \param indexAdjustment - A number to add to the parameter's |
| 586 | /// scope index; can be negative |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 587 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 588 | int indexAdjustment, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 589 | Optional<unsigned> NumExpansions, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 590 | bool ExpectParameterPack); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 591 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 592 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 593 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 594 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 595 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 596 | |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 597 | /// \brief Transform the captures and body of a lambda expression. |
| 598 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); |
| 599 | |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 600 | TemplateParameterList *TransformTemplateParameterList( |
| 601 | TemplateParameterList *TPL) { |
| 602 | return TPL; |
| 603 | } |
| 604 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 605 | ExprResult TransformAddressOfOperand(Expr *E); |
| 606 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 607 | bool IsAddressOfOperand); |
| 608 | |
Eli Friedman | 1ac6c93 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 609 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 610 | // amount of stack usage with clang. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 611 | #define STMT(Node, Parent) \ |
Eli Friedman | 1ac6c93 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 612 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 613 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 614 | #define EXPR(Node, Parent) \ |
Eli Friedman | 1ac6c93 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 615 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 616 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 617 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 618 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 620 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | 1ac6c93 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 621 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 622 | OMPClause *Transform ## Class(Class *S); |
| 623 | #include "clang/Basic/OpenMPKinds.def" |
| 624 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 625 | /// \brief Build a new pointer type given its pointee type. |
| 626 | /// |
| 627 | /// By default, performs semantic analysis when building the pointer type. |
| 628 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 629 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 630 | |
| 631 | /// \brief Build a new block pointer type given its pointee type. |
| 632 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 634 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 635 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 636 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 637 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 638 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 639 | /// By default, performs semantic analysis when building the |
| 640 | /// reference type. Subclasses may override this routine to provide |
| 641 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 642 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 643 | /// \param LValue whether the type was written with an lvalue sigil |
| 644 | /// or an rvalue sigil. |
| 645 | QualType RebuildReferenceType(QualType ReferentType, |
| 646 | bool LValue, |
| 647 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 649 | /// \brief Build a new member pointer type given the pointee type and the |
| 650 | /// class type it refers into. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the member pointer |
| 653 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 654 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 655 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 657 | /// \brief Build a new array type given the element type, size |
| 658 | /// modifier, size of the array (if known), size expression, and index type |
| 659 | /// 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 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 664 | QualType RebuildArrayType(QualType ElementType, |
| 665 | ArrayType::ArraySizeModifier SizeMod, |
| 666 | const llvm::APInt *Size, |
| 667 | Expr *SizeExpr, |
| 668 | unsigned IndexTypeQuals, |
| 669 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 670 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 671 | /// \brief Build a new constant array type given the element type, size |
| 672 | /// modifier, (known) size of the array, and index type qualifiers. |
| 673 | /// |
| 674 | /// By default, performs semantic analysis when building the array type. |
| 675 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 677 | ArrayType::ArraySizeModifier SizeMod, |
| 678 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 679 | unsigned IndexTypeQuals, |
| 680 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 682 | /// \brief Build a new incomplete array type given the element type, size |
| 683 | /// modifier, and index type qualifiers. |
| 684 | /// |
| 685 | /// By default, performs semantic analysis when building the array type. |
| 686 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 688 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 689 | unsigned IndexTypeQuals, |
| 690 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 691 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 693 | /// size modifier, size expression, and index type qualifiers. |
| 694 | /// |
| 695 | /// By default, performs semantic analysis when building the array type. |
| 696 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 698 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 699 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 700 | unsigned IndexTypeQuals, |
| 701 | SourceRange BracketsRange); |
| 702 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 704 | /// size modifier, size expression, and index type qualifiers. |
| 705 | /// |
| 706 | /// By default, performs semantic analysis when building the array type. |
| 707 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 709 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 710 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 711 | unsigned IndexTypeQuals, |
| 712 | SourceRange BracketsRange); |
| 713 | |
| 714 | /// \brief Build a new vector type given the element type and |
| 715 | /// number of elements. |
| 716 | /// |
| 717 | /// By default, performs semantic analysis when building the vector type. |
| 718 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 719 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 720 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 722 | /// \brief Build a new extended vector type given the element type and |
| 723 | /// number of elements. |
| 724 | /// |
| 725 | /// By default, performs semantic analysis when building the vector type. |
| 726 | /// Subclasses may override this routine to provide different behavior. |
| 727 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 728 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | |
| 730 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 731 | /// given the element type and number of elements. |
| 732 | /// |
| 733 | /// By default, performs semantic analysis when building the vector type. |
| 734 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 736 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 737 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 739 | /// \brief Build a new function type. |
| 740 | /// |
| 741 | /// By default, performs semantic analysis when building the function type. |
| 742 | /// Subclasses may override this routine to provide different behavior. |
| 743 | QualType RebuildFunctionProtoType(QualType T, |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 744 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 745 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 747 | /// \brief Build a new unprototyped function type. |
| 748 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 749 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 750 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 751 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 752 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 753 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 754 | /// \brief Build a new typedef type. |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 755 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 756 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 757 | } |
| 758 | |
| 759 | /// \brief Build a new class/struct/union type. |
| 760 | QualType RebuildRecordType(RecordDecl *Record) { |
| 761 | return SemaRef.Context.getTypeDeclType(Record); |
| 762 | } |
| 763 | |
| 764 | /// \brief Build a new Enum type. |
| 765 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 766 | return SemaRef.Context.getTypeDeclType(Enum); |
| 767 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 768 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 770 | /// |
| 771 | /// By default, performs semantic analysis when building the typeof type. |
| 772 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 773 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 774 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 776 | /// |
| 777 | /// By default, builds a new TypeOfType with the given underlying type. |
| 778 | QualType RebuildTypeOfType(QualType Underlying); |
| 779 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 780 | /// \brief Build a new unary transform type. |
| 781 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 782 | UnaryTransformType::UTTKind UKind, |
| 783 | SourceLocation Loc); |
| 784 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 785 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 786 | /// |
| 787 | /// By default, performs semantic analysis when building the decltype type. |
| 788 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 789 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 791 | /// \brief Build a new C++11 auto type. |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 792 | /// |
| 793 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 794 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 795 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 796 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 797 | // that we'll retry deduction after the transformation. |
Faisal Vali | fad9e13 | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 798 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 799 | /*IsDependent*/ false); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 802 | /// \brief Build a new template specialization type. |
| 803 | /// |
| 804 | /// By default, performs semantic analysis when building the template |
| 805 | /// specialization type. Subclasses may override this routine to provide |
| 806 | /// different behavior. |
| 807 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 808 | SourceLocation TemplateLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 809 | TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 810 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 811 | /// \brief Build a new parenthesized type. |
| 812 | /// |
| 813 | /// By default, builds a new ParenType type from the inner type. |
| 814 | /// Subclasses may override this routine to provide different behavior. |
| 815 | QualType RebuildParenType(QualType InnerType) { |
| 816 | return SemaRef.Context.getParenType(InnerType); |
| 817 | } |
| 818 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 819 | /// \brief Build a new qualified name type. |
| 820 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 821 | /// By default, builds a new ElaboratedType type from the keyword, |
| 822 | /// the nested-name-specifier and the named type. |
| 823 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 824 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 825 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 826 | NestedNameSpecifierLoc QualifierLoc, |
| 827 | QualType Named) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 828 | return SemaRef.Context.getElaboratedType(Keyword, |
| 829 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 830 | Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 832 | |
| 833 | /// \brief Build a new typename type that refers to a template-id. |
| 834 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 835 | /// By default, builds a new DependentNameType type from the |
| 836 | /// nested-name-specifier and the given type. Subclasses may override |
| 837 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 838 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 839 | ElaboratedTypeKeyword Keyword, |
| 840 | NestedNameSpecifierLoc QualifierLoc, |
| 841 | const IdentifierInfo *Name, |
| 842 | SourceLocation NameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 843 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 844 | // Rebuild the template name. |
| 845 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 846 | CXXScopeSpec SS; |
| 847 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 848 | TemplateName InstName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 849 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 850 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 851 | if (InstName.isNull()) |
| 852 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 854 | // If it's still dependent, make a dependent specialization. |
| 855 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 856 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 857 | QualifierLoc.getNestedNameSpecifier(), |
| 858 | Name, |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 859 | Args); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 860 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 861 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 862 | // specialization. |
| 863 | QualType T = |
| 864 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 865 | if (T.isNull()) return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 866 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 867 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 868 | return T; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 869 | |
| 870 | return SemaRef.Context.getElaboratedType(Keyword, |
| 871 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 872 | T); |
| 873 | } |
| 874 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 875 | /// \brief Build a new typename type that refers to an identifier. |
| 876 | /// |
| 877 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 878 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 879 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 880 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 881 | SourceLocation KeywordLoc, |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 882 | NestedNameSpecifierLoc QualifierLoc, |
| 883 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 884 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 885 | CXXScopeSpec SS; |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 886 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 887 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 888 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 889 | // If the name is still dependent, just build a new dependent name type. |
| 890 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 891 | return SemaRef.Context.getDependentNameType(Keyword, |
| 892 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 893 | Id); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 896 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 897 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | e29425b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 898 | *Id, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 899 | |
| 900 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 901 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 902 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 903 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 904 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 905 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 906 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 907 | if (!DC) |
| 908 | return QualType(); |
| 909 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 910 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 911 | return QualType(); |
| 912 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 913 | TagDecl *Tag = 0; |
| 914 | SemaRef.LookupQualifiedName(Result, DC); |
| 915 | switch (Result.getResultKind()) { |
| 916 | case LookupResult::NotFound: |
| 917 | case LookupResult::NotFoundInCurrentInstantiation: |
| 918 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 919 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 920 | case LookupResult::Found: |
| 921 | Tag = Result.getAsSingle<TagDecl>(); |
| 922 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 923 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 924 | case LookupResult::FoundOverloaded: |
| 925 | case LookupResult::FoundUnresolvedValue: |
| 926 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 928 | case LookupResult::Ambiguous: |
| 929 | // Let the LookupResult structure handle ambiguities. |
| 930 | return QualType(); |
| 931 | } |
| 932 | |
| 933 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 934 | // Check where the name exists but isn't a tag type and use that to emit |
| 935 | // better diagnostics. |
| 936 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 937 | SemaRef.LookupQualifiedName(Result, DC); |
| 938 | switch (Result.getResultKind()) { |
| 939 | case LookupResult::Found: |
| 940 | case LookupResult::FoundOverloaded: |
| 941 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 942 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 943 | unsigned Kind = 0; |
| 944 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 945 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 946 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 947 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 948 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 949 | break; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 950 | } |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 951 | default: |
| 952 | // FIXME: Would be nice to highlight just the source range. |
| 953 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 954 | << Kind << Id << DC; |
| 955 | break; |
| 956 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 957 | return QualType(); |
| 958 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 959 | |
Richard Trieu | bbf34c0 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 960 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 961 | IdLoc, *Id)) { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 962 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 963 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 964 | return QualType(); |
| 965 | } |
| 966 | |
| 967 | // Build the elaborated-type-specifier type. |
| 968 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 969 | return SemaRef.Context.getElaboratedType(Keyword, |
| 970 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 971 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 974 | /// \brief Build a new pack expansion type. |
| 975 | /// |
| 976 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 977 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 978 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 979 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 980 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 981 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 982 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 983 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 986 | /// \brief Build a new atomic type given its value type. |
| 987 | /// |
| 988 | /// By default, performs semantic analysis when building the atomic type. |
| 989 | /// Subclasses may override this routine to provide different behavior. |
| 990 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 991 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 992 | /// \brief Build a new template name given a nested name specifier, a flag |
| 993 | /// indicating whether the "template" keyword was provided, and the template |
| 994 | /// that the template name refers to. |
| 995 | /// |
| 996 | /// By default, builds the new template name directly. Subclasses may override |
| 997 | /// this routine to provide different behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 998 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 999 | bool TemplateKW, |
| 1000 | TemplateDecl *Template); |
| 1001 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1002 | /// \brief Build a new template name given a nested name specifier and the |
| 1003 | /// name that is referred to as a template. |
| 1004 | /// |
| 1005 | /// By default, performs semantic analysis to determine whether the name can |
| 1006 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1007 | /// template name. Subclasses may override this routine to provide different |
| 1008 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1009 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1010 | const IdentifierInfo &Name, |
| 1011 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1012 | QualType ObjectType, |
| 1013 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1015 | /// \brief Build a new template name given a nested name specifier and the |
| 1016 | /// overloaded operator name that is referred to as a template. |
| 1017 | /// |
| 1018 | /// By default, performs semantic analysis to determine whether the name can |
| 1019 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1020 | /// template name. Subclasses may override this routine to provide different |
| 1021 | /// behavior. |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1022 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1023 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1024 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1025 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1026 | |
| 1027 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1028 | /// and the |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1029 | /// |
| 1030 | /// By default, performs semantic analysis to determine whether the name can |
| 1031 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1032 | /// template name. Subclasses may override this routine to provide different |
| 1033 | /// behavior. |
| 1034 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1035 | const TemplateArgument &ArgPack) { |
| 1036 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1037 | } |
| 1038 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1039 | /// \brief Build a new compound statement. |
| 1040 | /// |
| 1041 | /// By default, performs semantic analysis to build the new statement. |
| 1042 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1043 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1044 | MultiStmtArg Statements, |
| 1045 | SourceLocation RBraceLoc, |
| 1046 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1047 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1048 | IsStmtExpr); |
| 1049 | } |
| 1050 | |
| 1051 | /// \brief Build a new case statement. |
| 1052 | /// |
| 1053 | /// By default, performs semantic analysis to build the new statement. |
| 1054 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1055 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1056 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1057 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1058 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1060 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1061 | ColonLoc); |
| 1062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1064 | /// \brief Attach the body to a new case statement. |
| 1065 | /// |
| 1066 | /// By default, performs semantic analysis to build the new statement. |
| 1067 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1068 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1069 | getSema().ActOnCaseStmtBody(S, Body); |
| 1070 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | /// \brief Build a new default statement. |
| 1074 | /// |
| 1075 | /// By default, performs semantic analysis to build the new statement. |
| 1076 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1077 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1078 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1079 | Stmt *SubStmt) { |
| 1080 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1081 | /*CurScope=*/0); |
| 1082 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1084 | /// \brief Build a new label statement. |
| 1085 | /// |
| 1086 | /// By default, performs semantic analysis to build the new statement. |
| 1087 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1088 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1089 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1090 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1091 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1093 | /// \brief Build a new label statement. |
| 1094 | /// |
| 1095 | /// By default, performs semantic analysis to build the new statement. |
| 1096 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1097 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1098 | ArrayRef<const Attr*> Attrs, |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1099 | Stmt *SubStmt) { |
| 1100 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1101 | } |
| 1102 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1103 | /// \brief Build a new "if" statement. |
| 1104 | /// |
| 1105 | /// By default, performs semantic analysis to build the new statement. |
| 1106 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1107 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1108 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1109 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1110 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1111 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1113 | /// \brief Start building a new switch statement. |
| 1114 | /// |
| 1115 | /// By default, performs semantic analysis to build the new statement. |
| 1116 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1117 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1118 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1119 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1120 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1123 | /// \brief Attach the body to the switch statement. |
| 1124 | /// |
| 1125 | /// By default, performs semantic analysis to build the new statement. |
| 1126 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1127 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1128 | Stmt *Switch, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1129 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /// \brief Build a new while statement. |
| 1133 | /// |
| 1134 | /// By default, performs semantic analysis to build the new statement. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1136 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1137 | VarDecl *CondVar, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1138 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1139 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1141 | /// \brief Build a new do-while statement. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new statement. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1145 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1146 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1147 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1148 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1149 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /// \brief Build a new for statement. |
| 1153 | /// |
| 1154 | /// By default, performs semantic analysis to build the new statement. |
| 1155 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1156 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1157 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1158 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1159 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1160 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1161 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1164 | /// \brief Build a new goto statement. |
| 1165 | /// |
| 1166 | /// By default, performs semantic analysis to build the new statement. |
| 1167 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1168 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1169 | LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1170 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /// \brief Build a new indirect goto statement. |
| 1174 | /// |
| 1175 | /// By default, performs semantic analysis to build the new statement. |
| 1176 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1177 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1178 | SourceLocation StarLoc, |
| 1179 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1180 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1181 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1183 | /// \brief Build a new return statement. |
| 1184 | /// |
| 1185 | /// By default, performs semantic analysis to build the new statement. |
| 1186 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1187 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1188 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1189 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1191 | /// \brief Build a new declaration statement. |
| 1192 | /// |
| 1193 | /// By default, performs semantic analysis to build the new statement. |
| 1194 | /// Subclasses may override this routine to provide different behavior. |
Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1195 | StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls, |
| 1196 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1197 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 406c38e | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1198 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1199 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1200 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1201 | /// \brief Build a new inline asm statement. |
| 1202 | /// |
| 1203 | /// By default, performs semantic analysis to build the new statement. |
| 1204 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1205 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1206 | bool IsVolatile, unsigned NumOutputs, |
| 1207 | unsigned NumInputs, IdentifierInfo **Names, |
| 1208 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1209 | Expr *AsmString, MultiExprArg Clobbers, |
| 1210 | SourceLocation RParenLoc) { |
| 1211 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1212 | NumInputs, Names, Constraints, Exprs, |
| 1213 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1214 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1215 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1216 | /// \brief Build a new MS style inline asm statement. |
| 1217 | /// |
| 1218 | /// By default, performs semantic analysis to build the new statement. |
| 1219 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1220 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1221 | ArrayRef<Token> AsmToks, |
| 1222 | StringRef AsmString, |
| 1223 | unsigned NumOutputs, unsigned NumInputs, |
| 1224 | ArrayRef<StringRef> Constraints, |
| 1225 | ArrayRef<StringRef> Clobbers, |
| 1226 | ArrayRef<Expr*> Exprs, |
| 1227 | SourceLocation EndLoc) { |
| 1228 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1229 | NumOutputs, NumInputs, |
| 1230 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1233 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1234 | /// |
| 1235 | /// By default, performs semantic analysis to build the new statement. |
| 1236 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1237 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1238 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1239 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1240 | Stmt *Finally) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1241 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1242 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1245 | /// \brief Rebuild an Objective-C exception declaration. |
| 1246 | /// |
| 1247 | /// By default, performs semantic analysis to build the new declaration. |
| 1248 | /// Subclasses may override this routine to provide different behavior. |
| 1249 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1250 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1251 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1252 | ExceptionDecl->getInnerLocStart(), |
| 1253 | ExceptionDecl->getLocation(), |
| 1254 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1255 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1256 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1257 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1258 | /// |
| 1259 | /// By default, performs semantic analysis to build the new statement. |
| 1260 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1261 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1262 | SourceLocation RParenLoc, |
| 1263 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1264 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1265 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1266 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1267 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1268 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1269 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1270 | /// |
| 1271 | /// By default, performs semantic analysis to build the new statement. |
| 1272 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1273 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1274 | Stmt *Body) { |
| 1275 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1276 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1277 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1278 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1279 | /// |
| 1280 | /// By default, performs semantic analysis to build the new statement. |
| 1281 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1282 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1283 | Expr *Operand) { |
| 1284 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1285 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1286 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1287 | /// \brief Build a new OpenMP parallel directive. |
| 1288 | /// |
| 1289 | /// By default, performs semantic analysis to build the new statement. |
| 1290 | /// Subclasses may override this routine to provide different behavior. |
| 1291 | StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1292 | Stmt *AStmt, |
| 1293 | SourceLocation StartLoc, |
| 1294 | SourceLocation EndLoc) { |
| 1295 | return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt, |
| 1296 | StartLoc, EndLoc); |
| 1297 | } |
| 1298 | |
| 1299 | /// \brief Build a new OpenMP 'default' clause. |
| 1300 | /// |
| 1301 | /// By default, performs semantic analysis to build the new statement. |
| 1302 | /// Subclasses may override this routine to provide different behavior. |
| 1303 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1304 | SourceLocation KindKwLoc, |
| 1305 | SourceLocation StartLoc, |
| 1306 | SourceLocation LParenLoc, |
| 1307 | SourceLocation EndLoc) { |
| 1308 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1309 | StartLoc, LParenLoc, EndLoc); |
| 1310 | } |
| 1311 | |
| 1312 | /// \brief Build a new OpenMP 'private' clause. |
| 1313 | /// |
| 1314 | /// By default, performs semantic analysis to build the new statement. |
| 1315 | /// Subclasses may override this routine to provide different behavior. |
| 1316 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1317 | SourceLocation StartLoc, |
| 1318 | SourceLocation LParenLoc, |
| 1319 | SourceLocation EndLoc) { |
| 1320 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1321 | EndLoc); |
| 1322 | } |
| 1323 | |
Alexey Bataev | d195bc3 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1324 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1325 | /// |
| 1326 | /// By default, performs semantic analysis to build the new statement. |
| 1327 | /// Subclasses may override this routine to provide different behavior. |
| 1328 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1329 | SourceLocation StartLoc, |
| 1330 | SourceLocation LParenLoc, |
| 1331 | SourceLocation EndLoc) { |
| 1332 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1333 | EndLoc); |
| 1334 | } |
| 1335 | |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1336 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1337 | SourceLocation StartLoc, |
| 1338 | SourceLocation LParenLoc, |
| 1339 | SourceLocation EndLoc) { |
| 1340 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1341 | EndLoc); |
| 1342 | } |
| 1343 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1344 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1345 | /// |
| 1346 | /// By default, performs semantic analysis to build the new statement. |
| 1347 | /// Subclasses may override this routine to provide different behavior. |
| 1348 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1349 | Expr *object) { |
| 1350 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1351 | } |
| 1352 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1353 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1354 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1355 | /// By default, performs semantic analysis to build the new statement. |
| 1356 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1357 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1358 | Expr *Object, Stmt *Body) { |
| 1359 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1360 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1361 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1362 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1363 | /// |
| 1364 | /// By default, performs semantic analysis to build the new statement. |
| 1365 | /// Subclasses may override this routine to provide different behavior. |
| 1366 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1367 | Stmt *Body) { |
| 1368 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1369 | } |
John McCall | 990567c | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1370 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1371 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1372 | /// |
| 1373 | /// By default, performs semantic analysis to build the new statement. |
| 1374 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1375 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1376 | Stmt *Element, |
| 1377 | Expr *Collection, |
| 1378 | SourceLocation RParenLoc, |
| 1379 | Stmt *Body) { |
Sam Panzer | bc20bbb | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1380 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1381 | Element, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1382 | Collection, |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1383 | RParenLoc); |
| 1384 | if (ForEachStmt.isInvalid()) |
| 1385 | return StmtError(); |
| 1386 | |
| 1387 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1388 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1389 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1390 | /// \brief Build a new C++ exception declaration. |
| 1391 | /// |
| 1392 | /// By default, performs semantic analysis to build the new decaration. |
| 1393 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1394 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1395 | TypeSourceInfo *Declarator, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1396 | SourceLocation StartLoc, |
| 1397 | SourceLocation IdLoc, |
| 1398 | IdentifierInfo *Id) { |
Douglas Gregor | efdf988 | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1399 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1400 | StartLoc, IdLoc, Id); |
| 1401 | if (Var) |
| 1402 | getSema().CurContext->addDecl(Var); |
| 1403 | return Var; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /// \brief Build a new C++ catch statement. |
| 1407 | /// |
| 1408 | /// By default, performs semantic analysis to build the new statement. |
| 1409 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1410 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1411 | VarDecl *ExceptionDecl, |
| 1412 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1413 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1414 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1415 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1417 | /// \brief Build a new C++ try statement. |
| 1418 | /// |
| 1419 | /// By default, performs semantic analysis to build the new statement. |
| 1420 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | 21adb0c | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1421 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1422 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1423 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1426 | /// \brief Build a new C++0x range-based for statement. |
| 1427 | /// |
| 1428 | /// By default, performs semantic analysis to build the new statement. |
| 1429 | /// Subclasses may override this routine to provide different behavior. |
| 1430 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1431 | SourceLocation ColonLoc, |
| 1432 | Stmt *Range, Stmt *BeginEnd, |
| 1433 | Expr *Cond, Expr *Inc, |
| 1434 | Stmt *LoopVar, |
| 1435 | SourceLocation RParenLoc) { |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1436 | // If we've just learned that the range is actually an Objective-C |
| 1437 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1438 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1439 | if (RangeStmt->isSingleDecl()) { |
| 1440 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1441 | if (RangeVar->isInvalidDecl()) |
| 1442 | return StmtError(); |
| 1443 | |
Douglas Gregor | 6f96f4b | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1444 | Expr *RangeExpr = RangeVar->getInit(); |
| 1445 | if (!RangeExpr->isTypeDependent() && |
| 1446 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1447 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1448 | RParenLoc); |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1453 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | 8b533d9 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1454 | Cond, Inc, LoopVar, RParenLoc, |
| 1455 | Sema::BFRK_Rebuild); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1456 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1457 | |
| 1458 | /// \brief Build a new C++0x range-based for statement. |
| 1459 | /// |
| 1460 | /// By default, performs semantic analysis to build the new statement. |
| 1461 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1462 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1463 | bool IsIfExists, |
| 1464 | NestedNameSpecifierLoc QualifierLoc, |
| 1465 | DeclarationNameInfo NameInfo, |
| 1466 | Stmt *Nested) { |
| 1467 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1468 | QualifierLoc, NameInfo, Nested); |
| 1469 | } |
| 1470 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1471 | /// \brief Attach body to a C++0x range-based for statement. |
| 1472 | /// |
| 1473 | /// By default, performs semantic analysis to finish the new statement. |
| 1474 | /// Subclasses may override this routine to provide different behavior. |
| 1475 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1476 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1477 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1478 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1479 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| 1480 | Stmt *TryBlock, Stmt *Handler) { |
| 1481 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1484 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1485 | Stmt *Block) { |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1486 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1489 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 1490 | return getSema().ActOnSEHFinallyBlock(Loc, Block); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | /// \brief Build a new expression that references a declaration. |
| 1494 | /// |
| 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1497 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1498 | LookupResult &R, |
| 1499 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1500 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1501 | } |
| 1502 | |
| 1503 | |
| 1504 | /// \brief Build a new expression that references a declaration. |
| 1505 | /// |
| 1506 | /// By default, performs semantic analysis to build the new expression. |
| 1507 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1508 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1509 | ValueDecl *VD, |
| 1510 | const DeclarationNameInfo &NameInfo, |
| 1511 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1512 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1513 | SS.Adopt(QualifierLoc); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1514 | |
| 1515 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1516 | |
| 1517 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1520 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1521 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1522 | /// By default, performs semantic analysis to build the new expression. |
| 1523 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1524 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1526 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1529 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1530 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1531 | /// By default, performs semantic analysis to build the new expression. |
| 1532 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1533 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1534 | SourceLocation OperatorLoc, |
| 1535 | bool isArrow, |
| 1536 | CXXScopeSpec &SS, |
| 1537 | TypeSourceInfo *ScopeType, |
| 1538 | SourceLocation CCLoc, |
| 1539 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1540 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1541 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1542 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1543 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | /// By default, performs semantic analysis to build the new expression. |
| 1545 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1546 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1547 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1548 | Expr *SubExpr) { |
| 1549 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1551 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1552 | /// \brief Build a new builtin offsetof expression. |
| 1553 | /// |
| 1554 | /// By default, performs semantic analysis to build the new expression. |
| 1555 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1556 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1557 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1558 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1559 | unsigned NumComponents, |
| 1560 | SourceLocation RParenLoc) { |
| 1561 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1562 | NumComponents, RParenLoc); |
| 1563 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1564 | |
| 1565 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1566 | /// type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1567 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | /// By default, performs semantic analysis to build the new expression. |
| 1569 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1570 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1571 | SourceLocation OpLoc, |
| 1572 | UnaryExprOrTypeTrait ExprKind, |
| 1573 | SourceRange R) { |
| 1574 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1577 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1578 | /// expression argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1579 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1580 | /// By default, performs semantic analysis to build the new expression. |
| 1581 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1582 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1583 | UnaryExprOrTypeTrait ExprKind, |
| 1584 | SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1585 | ExprResult Result |
Chandler Carruth | e72c55b | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1586 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1588 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1589 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1590 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1594 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | /// By default, performs semantic analysis to build the new expression. |
| 1596 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1597 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1598 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1599 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1601 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1602 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | RBracketLoc); |
| 1604 | } |
| 1605 | |
| 1606 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | /// By default, performs semantic analysis to build the new expression. |
| 1609 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1610 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1612 | SourceLocation RParenLoc, |
| 1613 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1614 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1615 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1619 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1620 | /// By default, performs semantic analysis to build the new expression. |
| 1621 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1622 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1623 | bool isArrow, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1624 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1625 | SourceLocation TemplateKWLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1626 | const DeclarationNameInfo &MemberNameInfo, |
| 1627 | ValueDecl *Member, |
| 1628 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1629 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1630 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1631 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1632 | isArrow); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1633 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1634 | // We have a reference to an unnamed field. This is always the |
| 1635 | // base of an anonymous struct/union member access, i.e. the |
| 1636 | // field is always of record type. |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1637 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1638 | assert(Member->getType()->isRecordType() && |
| 1639 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1641 | BaseResult = |
| 1642 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1643 | QualifierLoc.getNestedNameSpecifier(), |
| 1644 | FoundDecl, Member); |
| 1645 | if (BaseResult.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1646 | return ExprError(); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1647 | Base = BaseResult.take(); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1648 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1650 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1651 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1652 | cast<FieldDecl>(Member)->getType(), |
| 1653 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1654 | return getSema().Owned(ME); |
| 1655 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1656 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1657 | CXXScopeSpec SS; |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1658 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1659 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1660 | Base = BaseResult.take(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1661 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1662 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1663 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1664 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1665 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1666 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1667 | R.resolveKind(); |
| 1668 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1669 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1670 | SS, TemplateKWLoc, |
| 1671 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1672 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | /// By default, performs semantic analysis to build the new expression. |
| 1678 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1679 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1680 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1681 | Expr *LHS, Expr *RHS) { |
| 1682 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1686 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | /// By default, performs semantic analysis to build the new expression. |
| 1688 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1689 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1690 | SourceLocation QuestionLoc, |
| 1691 | Expr *LHS, |
| 1692 | SourceLocation ColonLoc, |
| 1693 | Expr *RHS) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1694 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1695 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1699 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1700 | /// By default, performs semantic analysis to build the new expression. |
| 1701 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1702 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1703 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1705 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1706 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1707 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1709 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | /// \brief Build a new compound literal expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1713 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1714 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1715 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1716 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1717 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1718 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1719 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1723 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1724 | /// By default, performs semantic analysis to build the new expression. |
| 1725 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1726 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1727 | SourceLocation OpLoc, |
| 1728 | SourceLocation AccessorLoc, |
| 1729 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1730 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1731 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1732 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1733 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1734 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1735 | SS, SourceLocation(), |
| 1736 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1737 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1738 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1739 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1741 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1742 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1743 | /// By default, performs semantic analysis to build the new expression. |
| 1744 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1745 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1746 | MultiExprArg Inits, |
| 1747 | SourceLocation RBraceLoc, |
| 1748 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1749 | ExprResult Result |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1750 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1751 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1752 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1753 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1754 | // Patch in the result type we were given, which may have been computed |
| 1755 | // when the initial InitListExpr was built. |
| 1756 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1757 | ILE->setType(ResultTy); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1758 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1761 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1762 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1763 | /// By default, performs semantic analysis to build the new expression. |
| 1764 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1765 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1766 | MultiExprArg ArrayExprs, |
| 1767 | SourceLocation EqualOrColonLoc, |
| 1768 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1769 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1770 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1771 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1772 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1774 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1775 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1776 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | /// \brief Build a new value-initialized expression. |
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 | /// By default, builds the implicit value initialization without performing |
| 1782 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1783 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1784 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1786 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1787 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | /// By default, performs semantic analysis to build the new expression. |
| 1791 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1792 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1793 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1794 | SourceLocation RParenLoc) { |
| 1795 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1796 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1797 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1801 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1802 | /// By default, performs semantic analysis to build the new expression. |
| 1803 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1804 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | 5b9cc5d | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1805 | MultiExprArg SubExprs, |
| 1806 | SourceLocation RParenLoc) { |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1807 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1808 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1810 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | /// |
| 1812 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1813 | /// rather than attempting to map the label statement itself. |
| 1814 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1815 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1816 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1817 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1820 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1821 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1822 | /// By default, performs semantic analysis to build the new expression. |
| 1823 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1824 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1825 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1826 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1827 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1830 | /// \brief Build a new __builtin_choose_expr expression. |
| 1831 | /// |
| 1832 | /// By default, performs semantic analysis to build the new expression. |
| 1833 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1834 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1835 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1836 | SourceLocation RParenLoc) { |
| 1837 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1838 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1839 | RParenLoc); |
| 1840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1842 | /// \brief Build a new generic selection expression. |
| 1843 | /// |
| 1844 | /// By default, performs semantic analysis to build the new expression. |
| 1845 | /// Subclasses may override this routine to provide different behavior. |
| 1846 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1847 | SourceLocation DefaultLoc, |
| 1848 | SourceLocation RParenLoc, |
| 1849 | Expr *ControllingExpr, |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1850 | ArrayRef<TypeSourceInfo *> Types, |
| 1851 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1852 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1853 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1856 | /// \brief Build a new overloaded operator call expression. |
| 1857 | /// |
| 1858 | /// By default, performs semantic analysis to build the new expression. |
| 1859 | /// The semantic analysis provides the behavior of template instantiation, |
| 1860 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1862 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1863 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1864 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1865 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1866 | Expr *Callee, |
| 1867 | Expr *First, |
| 1868 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1869 | |
| 1870 | /// \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] | 1871 | /// reinterpret_cast. |
| 1872 | /// |
| 1873 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1875 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1876 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1877 | Stmt::StmtClass Class, |
| 1878 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1879 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1880 | SourceLocation RAngleLoc, |
| 1881 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1882 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1883 | SourceLocation RParenLoc) { |
| 1884 | switch (Class) { |
| 1885 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1886 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1888 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1889 | |
| 1890 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1891 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1893 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1895 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1896 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1897 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1898 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1899 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1900 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1901 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1902 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1903 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1904 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1906 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1907 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1908 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1910 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1911 | /// \brief Build a new C++ static_cast expression. |
| 1912 | /// |
| 1913 | /// By default, performs semantic analysis to build the new expression. |
| 1914 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1915 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1916 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1917 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1918 | SourceLocation RAngleLoc, |
| 1919 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1920 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1922 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1923 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1924 | SourceRange(LAngleLoc, RAngleLoc), |
| 1925 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | /// \brief Build a new C++ dynamic_cast expression. |
| 1929 | /// |
| 1930 | /// By default, performs semantic analysis to build the new expression. |
| 1931 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1932 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1933 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1934 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1935 | SourceLocation RAngleLoc, |
| 1936 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1937 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1938 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1939 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1940 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1941 | SourceRange(LAngleLoc, RAngleLoc), |
| 1942 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1946 | /// |
| 1947 | /// By default, performs semantic analysis to build the new expression. |
| 1948 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1949 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1950 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1951 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | SourceLocation RAngleLoc, |
| 1953 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1954 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1955 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1956 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1957 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1958 | SourceRange(LAngleLoc, RAngleLoc), |
| 1959 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /// \brief Build a new C++ const_cast expression. |
| 1963 | /// |
| 1964 | /// By default, performs semantic analysis to build the new expression. |
| 1965 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1966 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1967 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1968 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1969 | SourceLocation RAngleLoc, |
| 1970 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1971 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1972 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1973 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1974 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1975 | SourceRange(LAngleLoc, RAngleLoc), |
| 1976 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1979 | /// \brief Build a new C++ functional-style cast expression. |
| 1980 | /// |
| 1981 | /// By default, performs semantic analysis to build the new expression. |
| 1982 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1983 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1984 | SourceLocation LParenLoc, |
| 1985 | Expr *Sub, |
| 1986 | SourceLocation RParenLoc) { |
| 1987 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1988 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1989 | RParenLoc); |
| 1990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1991 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1992 | /// \brief Build a new C++ typeid(type) expression. |
| 1993 | /// |
| 1994 | /// By default, performs semantic analysis to build the new expression. |
| 1995 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1996 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1997 | SourceLocation TypeidLoc, |
| 1998 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1999 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2000 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2001 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2004 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2005 | /// \brief Build a new C++ typeid(expr) expression. |
| 2006 | /// |
| 2007 | /// By default, performs semantic analysis to build the new expression. |
| 2008 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2009 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2010 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2011 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2012 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2013 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2014 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2017 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2018 | /// |
| 2019 | /// By default, performs semantic analysis to build the new expression. |
| 2020 | /// Subclasses may override this routine to provide different behavior. |
| 2021 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2022 | SourceLocation TypeidLoc, |
| 2023 | TypeSourceInfo *Operand, |
| 2024 | SourceLocation RParenLoc) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2025 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2026 | RParenLoc); |
| 2027 | } |
| 2028 | |
| 2029 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2030 | /// |
| 2031 | /// By default, performs semantic analysis to build the new expression. |
| 2032 | /// Subclasses may override this routine to provide different behavior. |
| 2033 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2034 | SourceLocation TypeidLoc, |
| 2035 | Expr *Operand, |
| 2036 | SourceLocation RParenLoc) { |
| 2037 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2038 | RParenLoc); |
| 2039 | } |
| 2040 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2041 | /// \brief Build a new C++ "this" expression. |
| 2042 | /// |
| 2043 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2045 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2046 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2047 | QualType ThisType, |
| 2048 | bool isImplicit) { |
Eli Friedman | b69b42c | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2049 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2050 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 2051 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 2052 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | /// \brief Build a new C++ throw expression. |
| 2056 | /// |
| 2057 | /// By default, performs semantic analysis to build the new expression. |
| 2058 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2059 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2060 | bool IsThrownVariableInScope) { |
| 2061 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | /// \brief Build a new C++ default-argument expression. |
| 2065 | /// |
| 2066 | /// By default, builds a new default-argument expression, which does not |
| 2067 | /// require any semantic analysis. Subclasses may override this routine to |
| 2068 | /// provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2069 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2070 | ParmVarDecl *Param) { |
| 2071 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 2072 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2075 | /// \brief Build a new C++11 default-initialization expression. |
| 2076 | /// |
| 2077 | /// By default, builds a new default field initialization expression, which |
| 2078 | /// does not require any semantic analysis. Subclasses may override this |
| 2079 | /// routine to provide different behavior. |
| 2080 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2081 | FieldDecl *Field) { |
| 2082 | return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc, |
| 2083 | Field)); |
| 2084 | } |
| 2085 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2086 | /// \brief Build a new C++ zero-initialization expression. |
| 2087 | /// |
| 2088 | /// By default, performs semantic analysis to build the new expression. |
| 2089 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2090 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2091 | SourceLocation LParenLoc, |
| 2092 | SourceLocation RParenLoc) { |
| 2093 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2094 | None, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2096 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2097 | /// \brief Build a new C++ "new" expression. |
| 2098 | /// |
| 2099 | /// By default, performs semantic analysis to build the new expression. |
| 2100 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2101 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2102 | bool UseGlobal, |
| 2103 | SourceLocation PlacementLParen, |
| 2104 | MultiExprArg PlacementArgs, |
| 2105 | SourceLocation PlacementRParen, |
| 2106 | SourceRange TypeIdParens, |
| 2107 | QualType AllocatedType, |
| 2108 | TypeSourceInfo *AllocatedTypeInfo, |
| 2109 | Expr *ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2110 | SourceRange DirectInitRange, |
| 2111 | Expr *Initializer) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2112 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2113 | PlacementLParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2114 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2115 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2116 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2117 | AllocatedType, |
| 2118 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2119 | ArraySize, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2120 | DirectInitRange, |
| 2121 | Initializer); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2122 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2123 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2124 | /// \brief Build a new C++ "delete" expression. |
| 2125 | /// |
| 2126 | /// By default, performs semantic analysis to build the new expression. |
| 2127 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2128 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | bool IsGlobalDelete, |
| 2130 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2131 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2132 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2133 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2136 | /// \brief Build a new unary type trait expression. |
| 2137 | /// |
| 2138 | /// By default, performs semantic analysis to build the new expression. |
| 2139 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2140 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 2141 | SourceLocation StartLoc, |
| 2142 | TypeSourceInfo *T, |
| 2143 | SourceLocation RParenLoc) { |
| 2144 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2147 | /// \brief Build a new binary type trait expression. |
| 2148 | /// |
| 2149 | /// By default, performs semantic analysis to build the new expression. |
| 2150 | /// Subclasses may override this routine to provide different behavior. |
| 2151 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 2152 | SourceLocation StartLoc, |
| 2153 | TypeSourceInfo *LhsT, |
| 2154 | TypeSourceInfo *RhsT, |
| 2155 | SourceLocation RParenLoc) { |
| 2156 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 2157 | } |
| 2158 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2159 | /// \brief Build a new type trait expression. |
| 2160 | /// |
| 2161 | /// By default, performs semantic analysis to build the new expression. |
| 2162 | /// Subclasses may override this routine to provide different behavior. |
| 2163 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2164 | SourceLocation StartLoc, |
| 2165 | ArrayRef<TypeSourceInfo *> Args, |
| 2166 | SourceLocation RParenLoc) { |
| 2167 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2168 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2169 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2170 | /// \brief Build a new array type trait expression. |
| 2171 | /// |
| 2172 | /// By default, performs semantic analysis to build the new expression. |
| 2173 | /// Subclasses may override this routine to provide different behavior. |
| 2174 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2175 | SourceLocation StartLoc, |
| 2176 | TypeSourceInfo *TSInfo, |
| 2177 | Expr *DimExpr, |
| 2178 | SourceLocation RParenLoc) { |
| 2179 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2180 | } |
| 2181 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2182 | /// \brief Build a new expression trait expression. |
| 2183 | /// |
| 2184 | /// By default, performs semantic analysis to build the new expression. |
| 2185 | /// Subclasses may override this routine to provide different behavior. |
| 2186 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2187 | SourceLocation StartLoc, |
| 2188 | Expr *Queried, |
| 2189 | SourceLocation RParenLoc) { |
| 2190 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2191 | } |
| 2192 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2194 | /// expression. |
| 2195 | /// |
| 2196 | /// By default, performs semantic analysis to build the new expression. |
| 2197 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2198 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2199 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2200 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2201 | const DeclarationNameInfo &NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2202 | const TemplateArgumentListInfo *TemplateArgs, |
| 2203 | bool IsAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2204 | CXXScopeSpec SS; |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2205 | SS.Adopt(QualifierLoc); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2206 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2207 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2208 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2209 | NameInfo, TemplateArgs); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2210 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2211 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, |
| 2212 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | /// \brief Build a new template-id expression. |
| 2216 | /// |
| 2217 | /// By default, performs semantic analysis to build the new expression. |
| 2218 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2219 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2220 | SourceLocation TemplateKWLoc, |
| 2221 | LookupResult &R, |
| 2222 | bool RequiresADL, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2223 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2224 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2225 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | /// \brief Build a new object-construction expression. |
| 2229 | /// |
| 2230 | /// By default, performs semantic analysis to build the new expression. |
| 2231 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2232 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2233 | SourceLocation Loc, |
| 2234 | CXXConstructorDecl *Constructor, |
| 2235 | bool IsElidable, |
| 2236 | MultiExprArg Args, |
| 2237 | bool HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2238 | bool ListInitialization, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2239 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2240 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2241 | SourceRange ParenRange) { |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2242 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2243 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2244 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2245 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2246 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2247 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2248 | ConvertedArgs, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2249 | HadMultipleCandidates, |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2250 | ListInitialization, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2251 | RequiresZeroInit, ConstructKind, |
| 2252 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | /// \brief Build a new object-construction expression. |
| 2256 | /// |
| 2257 | /// By default, performs semantic analysis to build the new expression. |
| 2258 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2259 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2260 | SourceLocation LParenLoc, |
| 2261 | MultiExprArg Args, |
| 2262 | SourceLocation RParenLoc) { |
| 2263 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2264 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2265 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2266 | RParenLoc); |
| 2267 | } |
| 2268 | |
| 2269 | /// \brief Build a new object-construction expression. |
| 2270 | /// |
| 2271 | /// By default, performs semantic analysis to build the new expression. |
| 2272 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2273 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2274 | SourceLocation LParenLoc, |
| 2275 | MultiExprArg Args, |
| 2276 | SourceLocation RParenLoc) { |
| 2277 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2278 | LParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2279 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2280 | RParenLoc); |
| 2281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2282 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2283 | /// \brief Build a new member reference expression. |
| 2284 | /// |
| 2285 | /// By default, performs semantic analysis to build the new expression. |
| 2286 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2287 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2288 | QualType BaseType, |
| 2289 | bool IsArrow, |
| 2290 | SourceLocation OperatorLoc, |
| 2291 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2292 | SourceLocation TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2293 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2294 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2295 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2296 | CXXScopeSpec SS; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2297 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2299 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2300 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2301 | SS, TemplateKWLoc, |
| 2302 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2303 | MemberNameInfo, |
| 2304 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2307 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2308 | /// |
| 2309 | /// By default, performs semantic analysis to build the new expression. |
| 2310 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2311 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2312 | SourceLocation OperatorLoc, |
| 2313 | bool IsArrow, |
| 2314 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2315 | SourceLocation TemplateKWLoc, |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2316 | NamedDecl *FirstQualifierInScope, |
| 2317 | LookupResult &R, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2318 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2319 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2320 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2321 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2322 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2323 | OperatorLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2324 | SS, TemplateKWLoc, |
| 2325 | FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2326 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2328 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2329 | /// \brief Build a new noexcept expression. |
| 2330 | /// |
| 2331 | /// By default, performs semantic analysis to build the new expression. |
| 2332 | /// Subclasses may override this routine to provide different behavior. |
| 2333 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2334 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2335 | } |
| 2336 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2337 | /// \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] | 2338 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2339 | SourceLocation PackLoc, |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2340 | SourceLocation RParenLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2341 | Optional<unsigned> Length) { |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2342 | if (Length) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2343 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2344 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2345 | RParenLoc, *Length); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2346 | |
| 2347 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2348 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2349 | RParenLoc); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2350 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2351 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2352 | /// \brief Build a new Objective-C boxed expression. |
| 2353 | /// |
| 2354 | /// By default, performs semantic analysis to build the new expression. |
| 2355 | /// Subclasses may override this routine to provide different behavior. |
| 2356 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2357 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2358 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2359 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2360 | /// \brief Build a new Objective-C array literal. |
| 2361 | /// |
| 2362 | /// By default, performs semantic analysis to build the new expression. |
| 2363 | /// Subclasses may override this routine to provide different behavior. |
| 2364 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2365 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2366 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2367 | MultiExprArg(Elements, NumElements)); |
| 2368 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2369 | |
| 2370 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2371 | Expr *Base, Expr *Key, |
| 2372 | ObjCMethodDecl *getterMethod, |
| 2373 | ObjCMethodDecl *setterMethod) { |
| 2374 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2375 | getterMethod, setterMethod); |
| 2376 | } |
| 2377 | |
| 2378 | /// \brief Build a new Objective-C dictionary literal. |
| 2379 | /// |
| 2380 | /// By default, performs semantic analysis to build the new expression. |
| 2381 | /// Subclasses may override this routine to provide different behavior. |
| 2382 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2383 | ObjCDictionaryElement *Elements, |
| 2384 | unsigned NumElements) { |
| 2385 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2386 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2387 | |
James Dennett | 699c904 | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2388 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2389 | /// |
| 2390 | /// By default, performs semantic analysis to build the new expression. |
| 2391 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2392 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2393 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2394 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2395 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2396 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2397 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2398 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2399 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2400 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2401 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2402 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2403 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2404 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2405 | MultiExprArg Args, |
| 2406 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2407 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2408 | ReceiverTypeInfo->getType(), |
| 2409 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2410 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2411 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2415 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2416 | Selector Sel, |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2417 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2418 | ObjCMethodDecl *Method, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2419 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2420 | MultiExprArg Args, |
| 2421 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2422 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2423 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2424 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2425 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2426 | RBracLoc, Args); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2429 | /// \brief Build a new Objective-C ivar reference expression. |
| 2430 | /// |
| 2431 | /// By default, performs semantic analysis to build the new expression. |
| 2432 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2433 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2434 | SourceLocation IvarLoc, |
| 2435 | bool IsArrow, bool IsFreeIvar) { |
| 2436 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2437 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2438 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2439 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2440 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2441 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2442 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2443 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2444 | 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 | f9b9eab | 2010-04-26 20:11:03 +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(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2452 | /*FIXME:*/IvarLoc, IsArrow, |
| 2453 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2454 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2455 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2456 | /*TemplateArgs=*/0); |
| 2457 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2458 | |
| 2459 | /// \brief Build a new Objective-C property reference expression. |
| 2460 | /// |
| 2461 | /// By default, performs semantic analysis to build the new expression. |
| 2462 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2463 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2464 | ObjCPropertyDecl *Property, |
| 2465 | SourceLocation PropertyLoc) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2466 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2467 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2468 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2469 | Sema::LookupMemberName); |
| 2470 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2471 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2472 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2473 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2474 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2475 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2476 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2477 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2478 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2479 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2480 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2481 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2482 | SS, SourceLocation(), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2483 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2484 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2485 | /*TemplateArgs=*/0); |
| 2486 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2487 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2488 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2489 | /// |
| 2490 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2491 | /// Subclasses may override this routine to provide different behavior. |
| 2492 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2493 | ObjCMethodDecl *Getter, |
| 2494 | ObjCMethodDecl *Setter, |
| 2495 | SourceLocation PropertyLoc) { |
| 2496 | // Since these expressions can only be value-dependent, we do not |
| 2497 | // need to perform semantic analysis again. |
| 2498 | return Owned( |
| 2499 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2500 | VK_LValue, OK_ObjCProperty, |
| 2501 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2504 | /// \brief Build a new Objective-C "isa" expression. |
| 2505 | /// |
| 2506 | /// By default, performs semantic analysis to build the new expression. |
| 2507 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2508 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2509 | SourceLocation OpLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2510 | bool IsArrow) { |
| 2511 | CXXScopeSpec SS; |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2512 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2513 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2514 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2515 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2516 | OpLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2517 | SS, 0, false); |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2518 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2519 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2520 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2521 | if (Result.get()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2522 | return Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2523 | |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2524 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2525 | OpLoc, IsArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2526 | SS, SourceLocation(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2527 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2528 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2529 | /*TemplateArgs=*/0); |
| 2530 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2531 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2532 | /// \brief Build a new shuffle vector expression. |
| 2533 | /// |
| 2534 | /// By default, performs semantic analysis to build the new expression. |
| 2535 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2536 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2537 | MultiExprArg SubExprs, |
| 2538 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2539 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2540 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2541 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2542 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2543 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2544 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2545 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2546 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2547 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2548 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2549 | SemaRef.Context.BuiltinFnTy, |
| 2550 | VK_RValue, BuiltinLoc); |
| 2551 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2552 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 2553 | CK_BuiltinFnToFnPtr).take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2554 | |
| 2555 | // Build the CallExpr |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2556 | ExprResult TheCall = SemaRef.Owned( |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2557 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs, |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2558 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2559 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2560 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2562 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 429bb27 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2563 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2564 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2565 | |
Hal Finkel | 414a1bd | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2566 | /// \brief Build a new convert vector expression. |
| 2567 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2568 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2569 | SourceLocation RParenLoc) { |
| 2570 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2571 | BuiltinLoc, RParenLoc); |
| 2572 | } |
| 2573 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2574 | /// \brief Build a new template argument pack expansion. |
| 2575 | /// |
| 2576 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2577 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2578 | /// different behavior. |
| 2579 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2580 | SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2581 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2582 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2583 | case TemplateArgument::Expression: { |
| 2584 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2585 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2586 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2587 | if (Result.isInvalid()) |
| 2588 | return TemplateArgumentLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2589 | |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2590 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2591 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2592 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2593 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2594 | return TemplateArgumentLoc(TemplateArgument( |
| 2595 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2596 | NumExpansions), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2597 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2598 | Pattern.getTemplateNameLoc(), |
| 2599 | EllipsisLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2600 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2601 | case TemplateArgument::Null: |
| 2602 | case TemplateArgument::Integral: |
| 2603 | case TemplateArgument::Declaration: |
| 2604 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2605 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2606 | case TemplateArgument::NullPtr: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2607 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2608 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2609 | case TemplateArgument::Type: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2610 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2611 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2612 | EllipsisLoc, |
| 2613 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2614 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2615 | Expansion); |
| 2616 | break; |
| 2617 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2618 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2619 | return TemplateArgumentLoc(); |
| 2620 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2621 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2622 | /// \brief Build a new expression pack expansion. |
| 2623 | /// |
| 2624 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2625 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2626 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2627 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2628 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2629 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2630 | } |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2631 | |
| 2632 | /// \brief Build a new atomic operation expression. |
| 2633 | /// |
| 2634 | /// By default, performs semantic analysis to build the new expression. |
| 2635 | /// Subclasses may override this routine to provide different behavior. |
| 2636 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2637 | MultiExprArg SubExprs, |
| 2638 | QualType RetTy, |
| 2639 | AtomicExpr::AtomicOp Op, |
| 2640 | SourceLocation RParenLoc) { |
| 2641 | // Just create the expression; there is not any interesting semantic |
| 2642 | // analysis here because we can't actually build an AtomicExpr until |
| 2643 | // we are sure it is semantically sound. |
Benjamin Kramer | 3b6bef9 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2644 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2645 | RParenLoc); |
| 2646 | } |
| 2647 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2648 | private: |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2649 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2650 | QualType ObjectType, |
| 2651 | NamedDecl *FirstQualifierInScope, |
| 2652 | CXXScopeSpec &SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2653 | |
| 2654 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2655 | QualType ObjectType, |
| 2656 | NamedDecl *FirstQualifierInScope, |
| 2657 | CXXScopeSpec &SS); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2658 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2659 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2660 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2661 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2662 | if (!S) |
| 2663 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2664 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2665 | switch (S->getStmtClass()) { |
| 2666 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2668 | // Transform individual statement nodes |
| 2669 | #define STMT(Node, Parent) \ |
| 2670 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2671 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2672 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2673 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2674 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2675 | // Transform expressions by calling TransformExpr. |
| 2676 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2677 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2678 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2679 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2680 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2681 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2682 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2683 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2684 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2685 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2686 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2689 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2690 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2692 | template<typename Derived> |
| 2693 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2694 | if (!S) |
| 2695 | return S; |
| 2696 | |
| 2697 | switch (S->getClauseKind()) { |
| 2698 | default: break; |
| 2699 | // Transform individual clause nodes |
| 2700 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2701 | case OMPC_ ## Name : \ |
| 2702 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2703 | #include "clang/Basic/OpenMPKinds.def" |
| 2704 | } |
| 2705 | |
| 2706 | return S; |
| 2707 | } |
| 2708 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2709 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2710 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2711 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2712 | if (!E) |
| 2713 | return SemaRef.Owned(E); |
| 2714 | |
| 2715 | switch (E->getStmtClass()) { |
| 2716 | case Stmt::NoStmtClass: break; |
| 2717 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2718 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2719 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2720 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2721 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2724 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | template<typename Derived> |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2728 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2729 | bool CXXDirectInit) { |
| 2730 | // Initializers are instantiated like expressions, except that various outer |
| 2731 | // layers are stripped. |
| 2732 | if (!Init) |
| 2733 | return SemaRef.Owned(Init); |
| 2734 | |
| 2735 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2736 | Init = ExprTemp->getSubExpr(); |
| 2737 | |
Richard Smith | 858c2c3 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2738 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2739 | Init = MTE->GetTemporaryExpr(); |
| 2740 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2741 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2742 | Init = Binder->getSubExpr(); |
| 2743 | |
| 2744 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2745 | Init = ICE->getSubExprAsWritten(); |
| 2746 | |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2747 | if (CXXStdInitializerListExpr *ILE = |
| 2748 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 2749 | return TransformInitializer(ILE->getSubExpr(), CXXDirectInit); |
| 2750 | |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2751 | // If this is not a direct-initializer, we only need to reconstruct |
| 2752 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2753 | // the initializer is already the right type. |
| 2754 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2755 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2756 | return getDerived().TransformExpr(Init); |
| 2757 | |
| 2758 | // Revert value-initialization back to empty parens. |
| 2759 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2760 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2761 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2762 | Parens.getEnd()); |
| 2763 | } |
| 2764 | |
| 2765 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2766 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 62ed889 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2767 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 5cf1589 | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2768 | SourceLocation()); |
| 2769 | |
| 2770 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2771 | // of expressions. Any other form of initializer can just be reused directly. |
| 2772 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2773 | return getDerived().TransformExpr(Init); |
| 2774 | |
| 2775 | SmallVector<Expr*, 8> NewArgs; |
| 2776 | bool ArgChanged = false; |
| 2777 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2778 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2779 | return ExprError(); |
| 2780 | |
| 2781 | // If this was list initialization, revert to list form. |
| 2782 | if (Construct->isListInitialization()) |
| 2783 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2784 | Construct->getLocEnd(), |
| 2785 | Construct->getType()); |
| 2786 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2787 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 1245a54 | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 2788 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2789 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2790 | Parens.getEnd()); |
| 2791 | } |
| 2792 | |
| 2793 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2794 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2795 | unsigned NumInputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2796 | bool IsCall, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2797 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2798 | bool *ArgChanged) { |
| 2799 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2800 | // If requested, drop call arguments that need to be dropped. |
| 2801 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2802 | if (ArgChanged) |
| 2803 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2804 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2805 | break; |
| 2806 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2808 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2809 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2810 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2811 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2812 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2813 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2814 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2815 | // Determine whether the set of unexpanded parameter packs can and should |
| 2816 | // be expanded. |
| 2817 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2818 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2819 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2820 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2821 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2822 | Pattern->getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2823 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2824 | Expand, RetainExpansion, |
| 2825 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2826 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2827 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2828 | if (!Expand) { |
| 2829 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2830 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2831 | // expansion. |
| 2832 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2833 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2834 | if (OutPattern.isInvalid()) |
| 2835 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2836 | |
| 2837 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2838 | Expansion->getEllipsisLoc(), |
| 2839 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2840 | if (Out.isInvalid()) |
| 2841 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2842 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2843 | if (ArgChanged) |
| 2844 | *ArgChanged = true; |
| 2845 | Outputs.push_back(Out.get()); |
| 2846 | continue; |
| 2847 | } |
John McCall | c8fc90a | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2848 | |
| 2849 | // Record right away that the argument was changed. This needs |
| 2850 | // to happen even if the array expands to nothing. |
| 2851 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2852 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2853 | // The transform has determined that we should perform an elementwise |
| 2854 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2855 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2856 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2857 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2858 | if (Out.isInvalid()) |
| 2859 | return true; |
| 2860 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2861 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2862 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2863 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2864 | if (Out.isInvalid()) |
| 2865 | return true; |
| 2866 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2867 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2868 | Outputs.push_back(Out.get()); |
| 2869 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2870 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2871 | continue; |
| 2872 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2873 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2874 | ExprResult Result = |
| 2875 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 2876 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2877 | if (Result.isInvalid()) |
| 2878 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2879 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2880 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2881 | *ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2882 | |
| 2883 | Outputs.push_back(Result.get()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2884 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2885 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2886 | return false; |
| 2887 | } |
| 2888 | |
| 2889 | template<typename Derived> |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2890 | NestedNameSpecifierLoc |
| 2891 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2892 | NestedNameSpecifierLoc NNS, |
| 2893 | QualType ObjectType, |
| 2894 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2895 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2896 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2897 | Qualifier = Qualifier.getPrefix()) |
| 2898 | Qualifiers.push_back(Qualifier); |
| 2899 | |
| 2900 | CXXScopeSpec SS; |
| 2901 | while (!Qualifiers.empty()) { |
| 2902 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2903 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2904 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2905 | switch (QNNS->getKind()) { |
| 2906 | case NestedNameSpecifier::Identifier: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2907 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2908 | *QNNS->getAsIdentifier(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2909 | Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2910 | Q.getLocalEndLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2911 | ObjectType, false, SS, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2912 | FirstQualifierInScope, false)) |
| 2913 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2914 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2915 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2916 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2917 | case NestedNameSpecifier::Namespace: { |
| 2918 | NamespaceDecl *NS |
| 2919 | = cast_or_null<NamespaceDecl>( |
| 2920 | getDerived().TransformDecl( |
| 2921 | Q.getLocalBeginLoc(), |
| 2922 | QNNS->getAsNamespace())); |
| 2923 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2924 | break; |
| 2925 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2926 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2927 | case NestedNameSpecifier::NamespaceAlias: { |
| 2928 | NamespaceAliasDecl *Alias |
| 2929 | = cast_or_null<NamespaceAliasDecl>( |
| 2930 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2931 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2932 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2933 | Q.getLocalEndLoc()); |
| 2934 | break; |
| 2935 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2936 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2937 | case NestedNameSpecifier::Global: |
| 2938 | // There is no meaningful transformation that one could perform on the |
| 2939 | // global scope. |
| 2940 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2941 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2942 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2943 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2944 | case NestedNameSpecifier::TypeSpec: { |
| 2945 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2946 | FirstQualifierInScope, SS); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2947 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2948 | if (!TL) |
| 2949 | return NestedNameSpecifierLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2950 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2951 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2952 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2953 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2954 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2955 | "Can't get cv-qualifiers here"); |
Richard Smith | 95aafb2 | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2956 | if (TL.getType()->isEnumeralType()) |
| 2957 | SemaRef.Diag(TL.getBeginLoc(), |
| 2958 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2959 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2960 | Q.getLocalEndLoc()); |
| 2961 | break; |
| 2962 | } |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2963 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2964 | // error because a previous error should have already been emitted. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 2965 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 2966 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2967 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | 00c93a1 | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2968 | << TL.getType() << SS.getRange(); |
| 2969 | } |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2970 | return NestedNameSpecifierLoc(); |
| 2971 | } |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2972 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2973 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2974 | // 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] | 2975 | FirstQualifierInScope = 0; |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2976 | ObjectType = QualType(); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2977 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2978 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2979 | // 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] | 2980 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2981 | !getDerived().AlwaysRebuild()) |
| 2982 | return NNS; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2983 | |
| 2984 | // If we can re-use the source-location data from the original |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2985 | // nested-name-specifier, do so. |
| 2986 | if (SS.location_size() == NNS.getDataLength() && |
| 2987 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2988 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2989 | |
| 2990 | // Allocate new nested-name-specifier location information. |
| 2991 | return SS.getWithLocInContext(SemaRef.Context); |
| 2992 | } |
| 2993 | |
| 2994 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2995 | DeclarationNameInfo |
| 2996 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2997 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2998 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2999 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3000 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3001 | |
| 3002 | switch (Name.getNameKind()) { |
| 3003 | case DeclarationName::Identifier: |
| 3004 | case DeclarationName::ObjCZeroArgSelector: |
| 3005 | case DeclarationName::ObjCOneArgSelector: |
| 3006 | case DeclarationName::ObjCMultiArgSelector: |
| 3007 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3008 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3009 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3010 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3012 | case DeclarationName::CXXConstructorName: |
| 3013 | case DeclarationName::CXXDestructorName: |
| 3014 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3015 | TypeSourceInfo *NewTInfo; |
| 3016 | CanQualType NewCanTy; |
| 3017 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3018 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3019 | if (!NewTInfo) |
| 3020 | return DeclarationNameInfo(); |
| 3021 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3022 | } |
| 3023 | else { |
| 3024 | NewTInfo = 0; |
| 3025 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3026 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3027 | if (NewT.isNull()) |
| 3028 | return DeclarationNameInfo(); |
| 3029 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3032 | DeclarationName NewName |
| 3033 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3034 | NewCanTy); |
| 3035 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3036 | NewNameInfo.setName(NewName); |
| 3037 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3038 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3039 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3042 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3047 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3048 | TemplateName Name, |
| 3049 | SourceLocation NameLoc, |
| 3050 | QualType ObjectType, |
| 3051 | NamedDecl *FirstQualifierInScope) { |
| 3052 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3053 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3054 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3055 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3056 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3057 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3058 | Template)); |
| 3059 | if (!TransTemplate) |
| 3060 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3061 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3062 | if (!getDerived().AlwaysRebuild() && |
| 3063 | SS.getScopeRep() == QTN->getQualifier() && |
| 3064 | TransTemplate == Template) |
| 3065 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3066 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3067 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3068 | TransTemplate); |
| 3069 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3070 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3071 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3072 | if (SS.getScopeRep()) { |
| 3073 | // These apply to the scope specifier, not the template. |
| 3074 | ObjectType = QualType(); |
| 3075 | FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3078 | if (!getDerived().AlwaysRebuild() && |
| 3079 | SS.getScopeRep() == DTN->getQualifier() && |
| 3080 | ObjectType.isNull()) |
| 3081 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3082 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3083 | if (DTN->isIdentifier()) { |
| 3084 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3085 | *DTN->getIdentifier(), |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3086 | NameLoc, |
| 3087 | ObjectType, |
| 3088 | FirstQualifierInScope); |
| 3089 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3090 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3091 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3092 | ObjectType); |
| 3093 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3094 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3095 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3096 | TemplateDecl *TransTemplate |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3097 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3098 | Template)); |
| 3099 | if (!TransTemplate) |
| 3100 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3101 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3102 | if (!getDerived().AlwaysRebuild() && |
| 3103 | TransTemplate == Template) |
| 3104 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3105 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3106 | return TemplateName(TransTemplate); |
| 3107 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3108 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3109 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3110 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3111 | TemplateTemplateParmDecl *TransParam |
| 3112 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3113 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3114 | if (!TransParam) |
| 3115 | return TemplateName(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3117 | if (!getDerived().AlwaysRebuild() && |
| 3118 | TransParam == SubstPack->getParameterPack()) |
| 3119 | return Name; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3120 | |
| 3121 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3122 | SubstPack->getArgumentPack()); |
| 3123 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3124 | |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3125 | // These should be getting filtered out before they reach the AST. |
| 3126 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3130 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3131 | const TemplateArgument &Arg, |
| 3132 | TemplateArgumentLoc &Output) { |
| 3133 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3134 | switch (Arg.getKind()) { |
| 3135 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3136 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3137 | break; |
| 3138 | |
| 3139 | case TemplateArgument::Type: |
| 3140 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3141 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3142 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3143 | break; |
| 3144 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3145 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3146 | case TemplateArgument::TemplateExpansion: { |
| 3147 | NestedNameSpecifierLocBuilder Builder; |
| 3148 | TemplateName Template = Arg.getAsTemplate(); |
| 3149 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3150 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3151 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3152 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3153 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3154 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3155 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3156 | Builder.getWithLocInContext(SemaRef.Context), |
| 3157 | Loc); |
| 3158 | else |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3159 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3160 | Builder.getWithLocInContext(SemaRef.Context), |
| 3161 | Loc, Loc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3163 | break; |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3164 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3165 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3166 | case TemplateArgument::Expression: |
| 3167 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3168 | break; |
| 3169 | |
| 3170 | case TemplateArgument::Declaration: |
| 3171 | case TemplateArgument::Integral: |
| 3172 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3173 | case TemplateArgument::NullPtr: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3174 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3175 | break; |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | template<typename Derived> |
| 3180 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3181 | const TemplateArgumentLoc &Input, |
| 3182 | TemplateArgumentLoc &Output) { |
| 3183 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3184 | switch (Arg.getKind()) { |
| 3185 | case TemplateArgument::Null: |
| 3186 | case TemplateArgument::Integral: |
Eli Friedman | 511e3ae | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3187 | case TemplateArgument::Pack: |
| 3188 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3189 | case TemplateArgument::NullPtr: |
| 3190 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3192 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3193 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3194 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3195 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3196 | |
| 3197 | DI = getDerived().TransformType(DI); |
| 3198 | if (!DI) return true; |
| 3199 | |
| 3200 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3201 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3204 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3205 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3206 | if (QualifierLoc) { |
| 3207 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3208 | if (!QualifierLoc) |
| 3209 | return true; |
| 3210 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3211 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3212 | CXXScopeSpec SS; |
| 3213 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3214 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3215 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3216 | Input.getTemplateNameLoc()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3217 | if (Template.isNull()) |
| 3218 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3219 | |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3220 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3221 | Input.getTemplateNameLoc()); |
| 3222 | return false; |
| 3223 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3224 | |
| 3225 | case TemplateArgument::TemplateExpansion: |
| 3226 | llvm_unreachable("Caller should expand pack expansions"); |
| 3227 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3228 | case TemplateArgument::Expression: { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3229 | // Template argument expressions are constant expressions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3231 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3232 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3233 | Expr *InputExpr = Input.getSourceExpression(); |
| 3234 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3235 | |
Chris Lattner | 223de24 | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3236 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3237 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3238 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3239 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3240 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3241 | } |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3242 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3243 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3244 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3245 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3248 | /// \brief Iterator adaptor that invents template argument location information |
| 3249 | /// for each of the template arguments in its underlying iterator. |
| 3250 | template<typename Derived, typename InputIterator> |
| 3251 | class TemplateArgumentLocInventIterator { |
| 3252 | TreeTransform<Derived> &Self; |
| 3253 | InputIterator Iter; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3255 | public: |
| 3256 | typedef TemplateArgumentLoc value_type; |
| 3257 | typedef TemplateArgumentLoc reference; |
| 3258 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3259 | difference_type; |
| 3260 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3261 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3262 | class pointer { |
| 3263 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3264 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3265 | public: |
| 3266 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3267 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3268 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3269 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3270 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3271 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3272 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3273 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3274 | InputIterator Iter) |
| 3275 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3276 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3277 | TemplateArgumentLocInventIterator &operator++() { |
| 3278 | ++Iter; |
| 3279 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3280 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3281 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3282 | TemplateArgumentLocInventIterator operator++(int) { |
| 3283 | TemplateArgumentLocInventIterator Old(*this); |
| 3284 | ++(*this); |
| 3285 | return Old; |
| 3286 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3287 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3288 | reference operator*() const { |
| 3289 | TemplateArgumentLoc Result; |
| 3290 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3291 | return Result; |
| 3292 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3293 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3294 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3296 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3297 | const TemplateArgumentLocInventIterator &Y) { |
| 3298 | return X.Iter == Y.Iter; |
| 3299 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3300 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3301 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3302 | const TemplateArgumentLocInventIterator &Y) { |
| 3303 | return X.Iter != Y.Iter; |
| 3304 | } |
| 3305 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3306 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3307 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3308 | template<typename InputIterator> |
| 3309 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3310 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3311 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3312 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3313 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3314 | TemplateArgumentLoc In = *First; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3315 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3316 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3317 | // Unpack argument packs, which we translate them into separate |
| 3318 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3319 | // FIXME: We could do much better if we could guarantee that the |
| 3320 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3321 | // all of the template arguments in the argument pack. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3322 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3323 | TemplateArgument::pack_iterator> |
| 3324 | PackLocIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3325 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3326 | In.getArgument().pack_begin()), |
| 3327 | PackLocIterator(*this, |
| 3328 | In.getArgument().pack_end()), |
| 3329 | Outputs)) |
| 3330 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3331 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3332 | continue; |
| 3333 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3335 | if (In.getArgument().isPackExpansion()) { |
| 3336 | // We have a pack expansion, for which we will be substituting into |
| 3337 | // the pattern. |
| 3338 | SourceLocation Ellipsis; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3339 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3340 | TemplateArgumentLoc Pattern |
Eli Friedman | 850cf51 | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3341 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3342 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3343 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3344 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3345 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3346 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3347 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3348 | // Determine whether the set of unexpanded parameter packs can and should |
| 3349 | // be expanded. |
| 3350 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3351 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3352 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3353 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3354 | Pattern.getSourceRange(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3355 | Unexpanded, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3356 | Expand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3357 | RetainExpansion, |
| 3358 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3359 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3361 | if (!Expand) { |
| 3362 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3363 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3364 | // expansion. |
| 3365 | TemplateArgumentLoc OutPattern; |
| 3366 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3367 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3368 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3369 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3370 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3371 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3372 | if (Out.getArgument().isNull()) |
| 3373 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3374 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3375 | Outputs.addArgument(Out); |
| 3376 | continue; |
| 3377 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3378 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3379 | // The transform has determined that we should perform an elementwise |
| 3380 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3381 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3382 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3383 | |
| 3384 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3385 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3387 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3388 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3389 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3390 | if (Out.getArgument().isNull()) |
| 3391 | return true; |
| 3392 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3393 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3394 | Outputs.addArgument(Out); |
| 3395 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3396 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3397 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3398 | // forgetting the partially-substituted parameter pack. |
| 3399 | if (RetainExpansion) { |
| 3400 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3401 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3402 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3403 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3404 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3405 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3406 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3407 | if (Out.getArgument().isNull()) |
| 3408 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3410 | Outputs.addArgument(Out); |
| 3411 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3412 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3413 | continue; |
| 3414 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3415 | |
| 3416 | // The simple case: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3417 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3418 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3420 | Outputs.addArgument(Out); |
| 3421 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3422 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3423 | return false; |
| 3424 | |
| 3425 | } |
| 3426 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3427 | //===----------------------------------------------------------------------===// |
| 3428 | // Type transformation |
| 3429 | //===----------------------------------------------------------------------===// |
| 3430 | |
| 3431 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3432 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3433 | if (getDerived().AlreadyTransformed(T)) |
| 3434 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3436 | // Temporary workaround. All of these transformations should |
| 3437 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3438 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3439 | getDerived().getBaseLocation()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3440 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3441 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3442 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3443 | if (!NewDI) |
| 3444 | return QualType(); |
| 3445 | |
| 3446 | return NewDI->getType(); |
| 3447 | } |
| 3448 | |
| 3449 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3450 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3451 | // Refine the base location to the type's location. |
| 3452 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3453 | getDerived().getBaseEntity()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3454 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3455 | return DI; |
| 3456 | |
| 3457 | TypeLocBuilder TLB; |
| 3458 | |
| 3459 | TypeLoc TL = DI->getTypeLoc(); |
| 3460 | TLB.reserve(TL.getFullDataSize()); |
| 3461 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3462 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3463 | if (Result.isNull()) |
| 3464 | return 0; |
| 3465 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3466 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | template<typename Derived> |
| 3470 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3471 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3472 | switch (T.getTypeLocClass()) { |
| 3473 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3474 | #define TYPELOC(CLASS, PARENT) \ |
| 3475 | case TypeLoc::CLASS: \ |
| 3476 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3477 | T.castAs<CLASS##TypeLoc>()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3478 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3481 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3485 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3486 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3487 | /// types). This is the right thing for template instantiation, but |
| 3488 | /// probably not for other clients. |
| 3489 | template<typename Derived> |
| 3490 | QualType |
| 3491 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3492 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3493 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3494 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3495 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3496 | if (Result.isNull()) |
| 3497 | return QualType(); |
| 3498 | |
| 3499 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3500 | // FIXME: this is the right thing for template instantiation, but |
| 3501 | // probably not for other clients. |
| 3502 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3503 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3504 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3505 | // 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] | 3506 | // resulting type. |
| 3507 | if (Quals.hasObjCLifetime()) { |
| 3508 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3509 | Quals.removeObjCLifetime(); |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3510 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3511 | // Objective-C ARC: |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3512 | // A lifetime qualifier applied to a substituted template parameter |
| 3513 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3514 | const AutoType *AutoTy; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3515 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3516 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3517 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3518 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3519 | Qs.removeObjCLifetime(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3520 | Replacement |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3521 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3522 | Qs); |
| 3523 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3524 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3525 | Replacement); |
| 3526 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3527 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3528 | // 'auto' types behave the same way as template parameters. |
| 3529 | QualType Deduced = AutoTy->getDeducedType(); |
| 3530 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3531 | Qs.removeObjCLifetime(); |
| 3532 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3533 | Qs); |
Faisal Vali | fad9e13 | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3534 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3535 | AutoTy->isDependentType()); |
Douglas Gregor | 92d1387 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3536 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3537 | } else { |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3538 | // Otherwise, complain about the addition of a qualifier to an |
| 3539 | // already-qualified type. |
Eli Friedman | 44ee0a7 | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3540 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3541 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | 4020cae | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3542 | << Result << R; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3543 | |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3544 | Quals.removeObjCLifetime(); |
| 3545 | } |
| 3546 | } |
| 3547 | } |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3548 | if (!Quals.empty()) { |
| 3549 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | 9807a2e | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3550 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3551 | if (Result.hasLocalQualifiers()) |
| 3552 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3553 | // No location information to preserve. |
| 3554 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3555 | |
| 3556 | return Result; |
| 3557 | } |
| 3558 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3559 | template<typename Derived> |
| 3560 | TypeLoc |
| 3561 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3562 | QualType ObjectType, |
| 3563 | NamedDecl *UnqualLookup, |
| 3564 | CXXScopeSpec &SS) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3565 | QualType T = TL.getType(); |
| 3566 | if (getDerived().AlreadyTransformed(T)) |
| 3567 | return TL; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3568 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3569 | TypeLocBuilder TLB; |
| 3570 | QualType Result; |
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 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3573 | TemplateSpecializationTypeLoc SpecTL = |
| 3574 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3575 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3576 | TemplateName Template = |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3577 | getDerived().TransformTemplateName(SS, |
| 3578 | SpecTL.getTypePtr()->getTemplateName(), |
| 3579 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3580 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3581 | if (Template.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3582 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3583 | |
| 3584 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3585 | Template); |
| 3586 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3587 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3588 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3589 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3590 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3591 | = getDerived().RebuildTemplateName(SS, |
| 3592 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3593 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3594 | ObjectType, UnqualLookup); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3595 | if (Template.isNull()) |
| 3596 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3597 | |
| 3598 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3599 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3600 | Template, |
| 3601 | SS); |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3602 | } else { |
| 3603 | // Nothing special needs to be done for these. |
| 3604 | Result = getDerived().TransformType(TLB, TL); |
| 3605 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3606 | |
| 3607 | if (Result.isNull()) |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3608 | return TypeLoc(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3609 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3610 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3611 | } |
| 3612 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3613 | template<typename Derived> |
| 3614 | TypeSourceInfo * |
| 3615 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3616 | QualType ObjectType, |
| 3617 | NamedDecl *UnqualLookup, |
| 3618 | CXXScopeSpec &SS) { |
| 3619 | // FIXME: Painfully copy-paste from the above! |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3620 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3621 | QualType T = TSInfo->getType(); |
| 3622 | if (getDerived().AlreadyTransformed(T)) |
| 3623 | return TSInfo; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3624 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3625 | TypeLocBuilder TLB; |
| 3626 | QualType Result; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3627 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3628 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3629 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3630 | TemplateSpecializationTypeLoc SpecTL = |
| 3631 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3633 | TemplateName Template |
| 3634 | = getDerived().TransformTemplateName(SS, |
| 3635 | SpecTL.getTypePtr()->getTemplateName(), |
| 3636 | SpecTL.getTemplateNameLoc(), |
| 3637 | ObjectType, UnqualLookup); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3638 | if (Template.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3639 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3640 | |
| 3641 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3642 | Template); |
| 3643 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3644 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3645 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3646 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3647 | TemplateName Template |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3648 | = getDerived().RebuildTemplateName(SS, |
| 3649 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3650 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3651 | ObjectType, UnqualLookup); |
| 3652 | if (Template.isNull()) |
| 3653 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3654 | |
| 3655 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3656 | SpecTL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3657 | Template, |
| 3658 | SS); |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3659 | } else { |
| 3660 | // Nothing special needs to be done for these. |
| 3661 | Result = getDerived().TransformType(TLB, TL); |
| 3662 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3663 | |
| 3664 | if (Result.isNull()) |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3665 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3666 | |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3667 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3668 | } |
| 3669 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3670 | template <class TyLoc> static inline |
| 3671 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3672 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3673 | NewT.setNameLoc(T.getNameLoc()); |
| 3674 | return T.getType(); |
| 3675 | } |
| 3676 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3677 | template<typename Derived> |
| 3678 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3679 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3680 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3681 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3682 | if (T.needsExtraLocalData()) |
| 3683 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3684 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3685 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3687 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3688 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3689 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3690 | // FIXME: recurse? |
| 3691 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3693 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3694 | template<typename Derived> |
Reid Kleckner | 12df246 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3695 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3696 | DecayedTypeLoc TL) { |
| 3697 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3698 | if (OriginalType.isNull()) |
| 3699 | return QualType(); |
| 3700 | |
| 3701 | QualType Result = TL.getType(); |
| 3702 | if (getDerived().AlwaysRebuild() || |
| 3703 | OriginalType != TL.getOriginalLoc().getType()) |
| 3704 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3705 | TLB.push<DecayedTypeLoc>(Result); |
| 3706 | // Nothing to set for DecayedTypeLoc. |
| 3707 | return Result; |
| 3708 | } |
| 3709 | |
| 3710 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3711 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3712 | PointerTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3713 | QualType PointeeType |
| 3714 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3715 | if (PointeeType.isNull()) |
| 3716 | return QualType(); |
| 3717 | |
| 3718 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3719 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3720 | // A dependent pointer type 'T *' has is being transformed such |
| 3721 | // that an Objective-C class type is being replaced for 'T'. The |
| 3722 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3723 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3724 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3725 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3726 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3727 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3728 | return Result; |
| 3729 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3730 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3731 | if (getDerived().AlwaysRebuild() || |
| 3732 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3733 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3734 | if (Result.isNull()) |
| 3735 | return QualType(); |
| 3736 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3737 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3738 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3739 | // pointing to. |
| 3740 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3741 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3742 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3743 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3744 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3745 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3746 | |
| 3747 | template<typename Derived> |
| 3748 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3749 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3750 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3751 | QualType PointeeType |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3752 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3753 | if (PointeeType.isNull()) |
| 3754 | return QualType(); |
| 3755 | |
| 3756 | QualType Result = TL.getType(); |
| 3757 | if (getDerived().AlwaysRebuild() || |
| 3758 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3759 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3760 | TL.getSigilLoc()); |
| 3761 | if (Result.isNull()) |
| 3762 | return QualType(); |
| 3763 | } |
| 3764 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3765 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3766 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3767 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3768 | } |
| 3769 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3770 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3771 | /// don't care whether the type itself is an l-value type or an r-value |
| 3772 | /// type; we only care if the type was *written* as an l-value type |
| 3773 | /// or an r-value type. |
| 3774 | template<typename Derived> |
| 3775 | QualType |
| 3776 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3777 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3778 | const ReferenceType *T = TL.getTypePtr(); |
| 3779 | |
| 3780 | // Note that this works with the pointee-as-written. |
| 3781 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3782 | if (PointeeType.isNull()) |
| 3783 | return QualType(); |
| 3784 | |
| 3785 | QualType Result = TL.getType(); |
| 3786 | if (getDerived().AlwaysRebuild() || |
| 3787 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3788 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3789 | T->isSpelledAsLValue(), |
| 3790 | TL.getSigilLoc()); |
| 3791 | if (Result.isNull()) |
| 3792 | return QualType(); |
| 3793 | } |
| 3794 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3795 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3796 | // referring to. |
| 3797 | TLB.TypeWasModifiedSafely( |
| 3798 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3799 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3800 | // r-value references can be rebuilt as l-value references. |
| 3801 | ReferenceTypeLoc NewTL; |
| 3802 | if (isa<LValueReferenceType>(Result)) |
| 3803 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3804 | else |
| 3805 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3806 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3807 | |
| 3808 | return Result; |
| 3809 | } |
| 3810 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | template<typename Derived> |
| 3812 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3813 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3814 | LValueReferenceTypeLoc TL) { |
| 3815 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3818 | template<typename Derived> |
| 3819 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3820 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3821 | RValueReferenceTypeLoc TL) { |
| 3822 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3823 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3824 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3825 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3826 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3827 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3828 | MemberPointerTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3829 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3830 | if (PointeeType.isNull()) |
| 3831 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3833 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3834 | TypeSourceInfo* NewClsTInfo = 0; |
| 3835 | if (OldClsTInfo) { |
| 3836 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3837 | if (!NewClsTInfo) |
| 3838 | return QualType(); |
| 3839 | } |
| 3840 | |
| 3841 | const MemberPointerType *T = TL.getTypePtr(); |
| 3842 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3843 | QualType NewClsType; |
| 3844 | if (NewClsTInfo) |
| 3845 | NewClsType = NewClsTInfo->getType(); |
| 3846 | else { |
| 3847 | NewClsType = getDerived().TransformType(OldClsType); |
| 3848 | if (NewClsType.isNull()) |
| 3849 | return QualType(); |
| 3850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3851 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3852 | QualType Result = TL.getType(); |
| 3853 | if (getDerived().AlwaysRebuild() || |
| 3854 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3855 | NewClsType != OldClsType) { |
| 3856 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3857 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3858 | if (Result.isNull()) |
| 3859 | return QualType(); |
| 3860 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3861 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3862 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3863 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3864 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3865 | |
| 3866 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3869 | template<typename Derived> |
| 3870 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3871 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3872 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3873 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3874 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3875 | if (ElementType.isNull()) |
| 3876 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3878 | QualType Result = TL.getType(); |
| 3879 | if (getDerived().AlwaysRebuild() || |
| 3880 | ElementType != T->getElementType()) { |
| 3881 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3882 | T->getSizeModifier(), |
| 3883 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3884 | T->getIndexTypeCVRQualifiers(), |
| 3885 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3886 | if (Result.isNull()) |
| 3887 | return QualType(); |
| 3888 | } |
Eli Friedman | 457a377 | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3889 | |
| 3890 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3891 | // a ConstantArrayType is allowed to have an element type which is a |
| 3892 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3893 | // types have the same location layout. |
| 3894 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3895 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3896 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3898 | Expr *Size = TL.getSizeExpr(); |
| 3899 | if (Size) { |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3900 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3901 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3902 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3903 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3904 | } |
| 3905 | NewTL.setSizeExpr(Size); |
| 3906 | |
| 3907 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3908 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3909 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3910 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3911 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3912 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3913 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3914 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3915 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3916 | if (ElementType.isNull()) |
| 3917 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3919 | QualType Result = TL.getType(); |
| 3920 | if (getDerived().AlwaysRebuild() || |
| 3921 | ElementType != T->getElementType()) { |
| 3922 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3923 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3924 | T->getIndexTypeCVRQualifiers(), |
| 3925 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3926 | if (Result.isNull()) |
| 3927 | return QualType(); |
| 3928 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3929 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3930 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3931 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3932 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3933 | NewTL.setSizeExpr(0); |
| 3934 | |
| 3935 | return Result; |
| 3936 | } |
| 3937 | |
| 3938 | template<typename Derived> |
| 3939 | QualType |
| 3940 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3941 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3942 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3943 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3944 | if (ElementType.isNull()) |
| 3945 | return QualType(); |
| 3946 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3947 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3948 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3949 | if (SizeResult.isInvalid()) |
| 3950 | return QualType(); |
| 3951 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3952 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3953 | |
| 3954 | QualType Result = TL.getType(); |
| 3955 | if (getDerived().AlwaysRebuild() || |
| 3956 | ElementType != T->getElementType() || |
| 3957 | Size != T->getSizeExpr()) { |
| 3958 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3959 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3960 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3961 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3962 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3963 | if (Result.isNull()) |
| 3964 | return QualType(); |
| 3965 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3966 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3967 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3968 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3969 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3970 | NewTL.setSizeExpr(Size); |
| 3971 | |
| 3972 | return Result; |
| 3973 | } |
| 3974 | |
| 3975 | template<typename Derived> |
| 3976 | QualType |
| 3977 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3978 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3979 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3980 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3981 | if (ElementType.isNull()) |
| 3982 | return QualType(); |
| 3983 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3984 | // Array bounds are constant expressions. |
| 3985 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3986 | Sema::ConstantEvaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3987 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3988 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3989 | Expr *origSize = TL.getSizeExpr(); |
| 3990 | if (!origSize) origSize = T->getSizeExpr(); |
| 3991 | |
| 3992 | ExprResult sizeResult |
| 3993 | = getDerived().TransformExpr(origSize); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3994 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3995 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3996 | return QualType(); |
| 3997 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3998 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3999 | |
| 4000 | QualType Result = TL.getType(); |
| 4001 | if (getDerived().AlwaysRebuild() || |
| 4002 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4003 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4004 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4005 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4006 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4007 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4008 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4009 | if (Result.isNull()) |
| 4010 | return QualType(); |
| 4011 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4012 | |
| 4013 | // We might have any sort of array type now, but fortunately they |
| 4014 | // all have the same location layout. |
| 4015 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4016 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4017 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4018 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4019 | |
| 4020 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | |
| 4023 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4024 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4025 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4026 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4027 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4028 | |
| 4029 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4030 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4031 | if (ElementType.isNull()) |
| 4032 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4033 | |
Richard Smith | f6702a3 | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4034 | // Vector sizes are constant expressions. |
| 4035 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4036 | Sema::ConstantEvaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4037 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4038 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4039 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4040 | if (Size.isInvalid()) |
| 4041 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4042 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4043 | QualType Result = TL.getType(); |
| 4044 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4045 | ElementType != T->getElementType() || |
| 4046 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4047 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4048 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4049 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4050 | if (Result.isNull()) |
| 4051 | return QualType(); |
| 4052 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4053 | |
| 4054 | // Result might be dependent or not. |
| 4055 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4056 | DependentSizedExtVectorTypeLoc NewTL |
| 4057 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4058 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4059 | } else { |
| 4060 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4061 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4062 | } |
| 4063 | |
| 4064 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | |
| 4067 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4068 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4069 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4070 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4071 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4072 | if (ElementType.isNull()) |
| 4073 | return QualType(); |
| 4074 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4075 | QualType Result = TL.getType(); |
| 4076 | if (getDerived().AlwaysRebuild() || |
| 4077 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4078 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4079 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4080 | if (Result.isNull()) |
| 4081 | return QualType(); |
| 4082 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4083 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4084 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4085 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4086 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4087 | return Result; |
| 4088 | } |
| 4089 | |
| 4090 | template<typename Derived> |
| 4091 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4092 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4093 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4094 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4095 | if (ElementType.isNull()) |
| 4096 | return QualType(); |
| 4097 | |
| 4098 | QualType Result = TL.getType(); |
| 4099 | if (getDerived().AlwaysRebuild() || |
| 4100 | ElementType != T->getElementType()) { |
| 4101 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4102 | T->getNumElements(), |
| 4103 | /*FIXME*/ SourceLocation()); |
| 4104 | if (Result.isNull()) |
| 4105 | return QualType(); |
| 4106 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4107 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4108 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4109 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4110 | |
| 4111 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4114 | template <typename Derived> |
| 4115 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4116 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4117 | bool ExpectParameterPack) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4118 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4119 | TypeSourceInfo *NewDI = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4120 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4121 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4122 | // 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] | 4123 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4124 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4125 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4126 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4127 | TypeLocBuilder TLB; |
| 4128 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4129 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4130 | |
| 4131 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4132 | OldExpansionTL.getPatternLoc()); |
| 4133 | if (Result.isNull()) |
| 4134 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4135 | |
| 4136 | Result = RebuildPackExpansionType(Result, |
| 4137 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4138 | OldExpansionTL.getEllipsisLoc(), |
| 4139 | NumExpansions); |
| 4140 | if (Result.isNull()) |
| 4141 | return 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4142 | |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4143 | PackExpansionTypeLoc NewExpansionTL |
| 4144 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4145 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4146 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4147 | } else |
| 4148 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4149 | if (!NewDI) |
| 4150 | return 0; |
| 4151 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4152 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4153 | return OldParm; |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4154 | |
| 4155 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4156 | OldParm->getDeclContext(), |
| 4157 | OldParm->getInnerLocStart(), |
| 4158 | OldParm->getLocation(), |
| 4159 | OldParm->getIdentifier(), |
| 4160 | NewDI->getType(), |
| 4161 | NewDI, |
| 4162 | OldParm->getStorageClass(), |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4163 | /* DefArg */ NULL); |
| 4164 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4165 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4166 | return newParm; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | template<typename Derived> |
| 4170 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4171 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4172 | ParmVarDecl **Params, unsigned NumParams, |
| 4173 | const QualType *ParamTypes, |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4174 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4175 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4176 | int indexAdjustment = 0; |
| 4177 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4178 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4179 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4180 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4181 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4182 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4183 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4184 | if (OldParm->isParameterPack()) { |
| 4185 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4186 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4187 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4188 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4189 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4190 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4191 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4192 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4193 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4194 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4195 | // Determine whether we should expand the parameter packs. |
| 4196 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4197 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4198 | Optional<unsigned> OrigNumExpansions = |
| 4199 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4200 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4201 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4202 | Pattern.getSourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4203 | Unexpanded, |
| 4204 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4205 | RetainExpansion, |
| 4206 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4207 | return true; |
| 4208 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4209 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4210 | if (ShouldExpand) { |
| 4211 | // Expand the function parameter pack into multiple, separate |
| 4212 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4213 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4214 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4215 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4216 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4217 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4218 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4219 | OrigNumExpansions, |
| 4220 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4221 | if (!NewParm) |
| 4222 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4223 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4224 | OutParamTypes.push_back(NewParm->getType()); |
| 4225 | if (PVars) |
| 4226 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4227 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4228 | |
| 4229 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4230 | // forgetting the partially-substituted parameter pack. |
| 4231 | if (RetainExpansion) { |
| 4232 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4233 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4234 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4235 | indexAdjustment++, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4236 | OrigNumExpansions, |
| 4237 | /*ExpectParameterPack=*/false); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4238 | if (!NewParm) |
| 4239 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4241 | OutParamTypes.push_back(NewParm->getType()); |
| 4242 | if (PVars) |
| 4243 | PVars->push_back(NewParm); |
| 4244 | } |
| 4245 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4246 | // The next parameter should have the same adjustment as the |
| 4247 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4248 | // on every push. Also, if we push nothing, the adjustment should |
| 4249 | // go down by one. |
| 4250 | indexAdjustment--; |
| 4251 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4252 | // We're done with the pack expansion. |
| 4253 | continue; |
| 4254 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4255 | |
| 4256 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4257 | // expansion. |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4258 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4259 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4260 | indexAdjustment, |
Douglas Gregor | d1bb4ae | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4261 | NumExpansions, |
| 4262 | /*ExpectParameterPack=*/true); |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4263 | } else { |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4264 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4265 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4266 | } |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4267 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4268 | if (!NewParm) |
| 4269 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4270 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4271 | OutParamTypes.push_back(NewParm->getType()); |
| 4272 | if (PVars) |
| 4273 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4274 | continue; |
| 4275 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4276 | |
| 4277 | // Deal with the possibility that we don't have a parameter |
| 4278 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4279 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4280 | bool IsPackExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4281 | Optional<unsigned> NumExpansions; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4282 | QualType NewType; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4283 | if (const PackExpansionType *Expansion |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4284 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4285 | // We have a function parameter pack that may need to be expanded. |
| 4286 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4287 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4288 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4289 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4290 | // Determine whether we should expand the parameter packs. |
| 4291 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4292 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4293 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4294 | Unexpanded, |
| 4295 | ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4296 | RetainExpansion, |
| 4297 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4298 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4299 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4300 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4301 | if (ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4302 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4303 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4304 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4305 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4306 | QualType NewType = getDerived().TransformType(Pattern); |
| 4307 | if (NewType.isNull()) |
| 4308 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4309 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4310 | OutParamTypes.push_back(NewType); |
| 4311 | if (PVars) |
| 4312 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4313 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4314 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4315 | // We're done with the pack expansion. |
| 4316 | continue; |
| 4317 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4319 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4320 | // forgetting the partially-substituted parameter pack. |
| 4321 | if (RetainExpansion) { |
| 4322 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4323 | QualType NewType = getDerived().TransformType(Pattern); |
| 4324 | if (NewType.isNull()) |
| 4325 | return true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4326 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4327 | OutParamTypes.push_back(NewType); |
| 4328 | if (PVars) |
| 4329 | PVars->push_back(0); |
| 4330 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4331 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4332 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4333 | // expansion. |
| 4334 | OldType = Expansion->getPattern(); |
| 4335 | IsPackExpansion = true; |
Douglas Gregor | 406f98f | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4336 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4337 | NewType = getDerived().TransformType(OldType); |
| 4338 | } else { |
| 4339 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4340 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4341 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4342 | if (NewType.isNull()) |
| 4343 | return true; |
| 4344 | |
| 4345 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4346 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4347 | NumExpansions); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4348 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4349 | OutParamTypes.push_back(NewType); |
| 4350 | if (PVars) |
| 4351 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4352 | } |
| 4353 | |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4354 | #ifndef NDEBUG |
| 4355 | if (PVars) { |
| 4356 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4357 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4358 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4359 | } |
John McCall | fb44de9 | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4360 | #endif |
| 4361 | |
| 4362 | return false; |
| 4363 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4364 | |
| 4365 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4367 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4368 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4369 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4370 | } |
| 4371 | |
| 4372 | template<typename Derived> |
| 4373 | QualType |
| 4374 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4375 | FunctionProtoTypeLoc TL, |
| 4376 | CXXRecordDecl *ThisContext, |
| 4377 | unsigned ThisTypeQuals) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4378 | // Transform the parameters and return type. |
| 4379 | // |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4380 | // 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] | 4381 | // When the function has a trailing return type, we instantiate the |
| 4382 | // parameters before the return type, since the return type can then refer |
| 4383 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4384 | // |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4385 | SmallVector<QualType, 4> ParamTypes; |
| 4386 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4387 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4388 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4389 | QualType ResultType; |
| 4390 | |
Richard Smith | 9fbf327 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4391 | if (T->hasTrailingReturn()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4392 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4393 | TL.getParmArray(), |
| 4394 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4395 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4396 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4397 | return QualType(); |
| 4398 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4399 | { |
| 4400 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4401 | // If a declaration declares a member function or member function |
| 4402 | // 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] | 4403 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4404 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4405 | // declarator. |
| 4406 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | cefc3af | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4408 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4409 | if (ResultType.isNull()) |
| 4410 | return QualType(); |
| 4411 | } |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4412 | } |
| 4413 | else { |
| 4414 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4415 | if (ResultType.isNull()) |
| 4416 | return QualType(); |
| 4417 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4418 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4419 | TL.getParmArray(), |
| 4420 | TL.getNumArgs(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4421 | TL.getTypePtr()->arg_type_begin(), |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4422 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4423 | return QualType(); |
| 4424 | } |
| 4425 | |
Richard Smith | e6975e9 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4426 | // FIXME: Need to transform the exception-specification too. |
| 4427 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4428 | QualType Result = TL.getType(); |
| 4429 | if (getDerived().AlwaysRebuild() || |
| 4430 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4431 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4432 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4433 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4434 | T->getExtProtoInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4435 | if (Result.isNull()) |
| 4436 | return QualType(); |
| 4437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4439 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4440 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4441 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4442 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4443 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4444 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4445 | NewTL.setArg(i, ParamDecls[i]); |
| 4446 | |
| 4447 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4448 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4450 | template<typename Derived> |
| 4451 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4452 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4453 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4454 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4455 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4456 | if (ResultType.isNull()) |
| 4457 | return QualType(); |
| 4458 | |
| 4459 | QualType Result = TL.getType(); |
| 4460 | if (getDerived().AlwaysRebuild() || |
| 4461 | ResultType != T->getResultType()) |
| 4462 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4463 | |
| 4464 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4465 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4466 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4467 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4468 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4469 | |
| 4470 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4471 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4472 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4473 | template<typename Derived> QualType |
| 4474 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4475 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4476 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4477 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4478 | if (!D) |
| 4479 | return QualType(); |
| 4480 | |
| 4481 | QualType Result = TL.getType(); |
| 4482 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4483 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4484 | if (Result.isNull()) |
| 4485 | return QualType(); |
| 4486 | } |
| 4487 | |
| 4488 | // We might get an arbitrary type spec type back. We should at |
| 4489 | // least always get a type spec type, though. |
| 4490 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4491 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4492 | |
| 4493 | return Result; |
| 4494 | } |
| 4495 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4496 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4497 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4498 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4499 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4500 | TypedefNameDecl *Typedef |
| 4501 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4502 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4503 | if (!Typedef) |
| 4504 | return QualType(); |
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 | QualType Result = TL.getType(); |
| 4507 | if (getDerived().AlwaysRebuild() || |
| 4508 | Typedef != T->getDecl()) { |
| 4509 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4510 | if (Result.isNull()) |
| 4511 | return QualType(); |
| 4512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4514 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4515 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4516 | |
| 4517 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4520 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4521 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4522 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4523 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4524 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4525 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4526 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4527 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4528 | if (E.isInvalid()) |
| 4529 | return QualType(); |
| 4530 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4531 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4532 | if (E.isInvalid()) |
| 4533 | return QualType(); |
| 4534 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4535 | QualType Result = TL.getType(); |
| 4536 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4537 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4538 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4539 | if (Result.isNull()) |
| 4540 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4541 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4542 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4544 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4545 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4546 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4547 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4548 | |
| 4549 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | |
| 4552 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4553 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4554 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4555 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4556 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4557 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4558 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4559 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4560 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4561 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4562 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4563 | if (Result.isNull()) |
| 4564 | return QualType(); |
| 4565 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4567 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4568 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4569 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4570 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4571 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4572 | |
| 4573 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4574 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | |
| 4576 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4577 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4578 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4579 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4581 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4582 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4583 | /*IsDecltype=*/ true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4585 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4586 | if (E.isInvalid()) |
| 4587 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4589 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4590 | if (E.isInvalid()) |
| 4591 | return QualType(); |
| 4592 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4593 | QualType Result = TL.getType(); |
| 4594 | if (getDerived().AlwaysRebuild() || |
| 4595 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4596 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4597 | if (Result.isNull()) |
| 4598 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4599 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4600 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4602 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4603 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4604 | |
| 4605 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4609 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4610 | TypeLocBuilder &TLB, |
| 4611 | UnaryTransformTypeLoc TL) { |
| 4612 | QualType Result = TL.getType(); |
| 4613 | if (Result->isDependentType()) { |
| 4614 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4615 | QualType NewBase = |
| 4616 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4617 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4618 | T->getUTTKind(), |
| 4619 | TL.getKWLoc()); |
| 4620 | if (Result.isNull()) |
| 4621 | return QualType(); |
| 4622 | } |
| 4623 | |
| 4624 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4625 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4626 | NewTL.setParensRange(TL.getParensRange()); |
| 4627 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4628 | return Result; |
| 4629 | } |
| 4630 | |
| 4631 | template<typename Derived> |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4632 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4633 | AutoTypeLoc TL) { |
| 4634 | const AutoType *T = TL.getTypePtr(); |
| 4635 | QualType OldDeduced = T->getDeducedType(); |
| 4636 | QualType NewDeduced; |
| 4637 | if (!OldDeduced.isNull()) { |
| 4638 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4639 | if (NewDeduced.isNull()) |
| 4640 | return QualType(); |
| 4641 | } |
| 4642 | |
| 4643 | QualType Result = TL.getType(); |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4644 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4645 | T->isDependentType()) { |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4646 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4647 | if (Result.isNull()) |
| 4648 | return QualType(); |
| 4649 | } |
| 4650 | |
| 4651 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4652 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4653 | |
| 4654 | return Result; |
| 4655 | } |
| 4656 | |
| 4657 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4658 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4659 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4660 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4661 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4662 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4663 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4664 | if (!Record) |
| 4665 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4666 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4667 | QualType Result = TL.getType(); |
| 4668 | if (getDerived().AlwaysRebuild() || |
| 4669 | Record != T->getDecl()) { |
| 4670 | Result = getDerived().RebuildRecordType(Record); |
| 4671 | if (Result.isNull()) |
| 4672 | return QualType(); |
| 4673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4674 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4675 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4676 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4677 | |
| 4678 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | |
| 4681 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4682 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4683 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4684 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4685 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4686 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4687 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4688 | if (!Enum) |
| 4689 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4690 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4691 | QualType Result = TL.getType(); |
| 4692 | if (getDerived().AlwaysRebuild() || |
| 4693 | Enum != T->getDecl()) { |
| 4694 | Result = getDerived().RebuildEnumType(Enum); |
| 4695 | if (Result.isNull()) |
| 4696 | return QualType(); |
| 4697 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4699 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4700 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4701 | |
| 4702 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4703 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4704 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4705 | template<typename Derived> |
| 4706 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4707 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4708 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4709 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4710 | TL.getTypePtr()->getDecl()); |
| 4711 | if (!D) return QualType(); |
| 4712 | |
| 4713 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4714 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4715 | return T; |
| 4716 | } |
| 4717 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4718 | template<typename Derived> |
| 4719 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4720 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4721 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4722 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4723 | } |
| 4724 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4725 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4726 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4727 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4728 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4729 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4730 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4731 | // Substitute into the replacement type, which itself might involve something |
| 4732 | // that needs to be transformed. This only tends to occur with default |
| 4733 | // template arguments of template template parameters. |
| 4734 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4735 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4736 | if (Replacement.isNull()) |
| 4737 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4738 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4739 | // Always canonicalize the replacement type. |
| 4740 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4741 | QualType Result |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4742 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4743 | Replacement); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4744 | |
Douglas Gregor | 0b4bcb6 | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4745 | // Propagate type-source information. |
| 4746 | SubstTemplateTypeParmTypeLoc NewTL |
| 4747 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4748 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4749 | return Result; |
| 4750 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4754 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4755 | TypeLocBuilder &TLB, |
| 4756 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4757 | return TransformTypeSpecType(TLB, TL); |
| 4758 | } |
| 4759 | |
| 4760 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4761 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4762 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4763 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4764 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4765 | |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4766 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4767 | // because we can't have a dependent nested-name-specifier anyway. |
| 4768 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4769 | TemplateName Template |
Douglas Gregor | 1d752d7 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4770 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4771 | TL.getTemplateNameLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4772 | if (Template.isNull()) |
| 4773 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4775 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4776 | } |
| 4777 | |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4778 | template<typename Derived> |
| 4779 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4780 | AtomicTypeLoc TL) { |
| 4781 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4782 | if (ValueType.isNull()) |
| 4783 | return QualType(); |
| 4784 | |
| 4785 | QualType Result = TL.getType(); |
| 4786 | if (getDerived().AlwaysRebuild() || |
| 4787 | ValueType != TL.getValueLoc().getType()) { |
| 4788 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4789 | if (Result.isNull()) |
| 4790 | return QualType(); |
| 4791 | } |
| 4792 | |
| 4793 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4794 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4795 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4796 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4797 | |
| 4798 | return Result; |
| 4799 | } |
| 4800 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4801 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4802 | /// container that provides a \c getArgLoc() member function. |
| 4803 | /// |
| 4804 | /// This iterator is intended to be used with the iterator form of |
| 4805 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4806 | template<typename ArgLocContainer> |
| 4807 | class TemplateArgumentLocContainerIterator { |
| 4808 | ArgLocContainer *Container; |
| 4809 | unsigned Index; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4810 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4811 | public: |
| 4812 | typedef TemplateArgumentLoc value_type; |
| 4813 | typedef TemplateArgumentLoc reference; |
| 4814 | typedef int difference_type; |
| 4815 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4816 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4817 | class pointer { |
| 4818 | TemplateArgumentLoc Arg; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4819 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4820 | public: |
| 4821 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4822 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4823 | const TemplateArgumentLoc *operator->() const { |
| 4824 | return &Arg; |
| 4825 | } |
| 4826 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4827 | |
| 4828 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4829 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4830 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4831 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4832 | unsigned Index) |
| 4833 | : Container(&Container), Index(Index) { } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4834 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4835 | TemplateArgumentLocContainerIterator &operator++() { |
| 4836 | ++Index; |
| 4837 | return *this; |
| 4838 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4840 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4841 | TemplateArgumentLocContainerIterator Old(*this); |
| 4842 | ++(*this); |
| 4843 | return Old; |
| 4844 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4845 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4846 | TemplateArgumentLoc operator*() const { |
| 4847 | return Container->getArgLoc(Index); |
| 4848 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4849 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4850 | pointer operator->() const { |
| 4851 | return pointer(Container->getArgLoc(Index)); |
| 4852 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4853 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4854 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4855 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4856 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4857 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4859 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4860 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4861 | return !(X == Y); |
| 4862 | } |
| 4863 | }; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4864 | |
| 4865 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4866 | template <typename Derived> |
| 4867 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4868 | TypeLocBuilder &TLB, |
| 4869 | TemplateSpecializationTypeLoc TL, |
| 4870 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4871 | TemplateArgumentListInfo NewTemplateArgs; |
| 4872 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4873 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4874 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4875 | ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4876 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4877 | ArgIterator(TL, TL.getNumArgs()), |
| 4878 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4879 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4880 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4881 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4882 | |
| 4883 | QualType Result = |
| 4884 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4885 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4886 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4887 | |
| 4888 | if (!Result.isNull()) { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4889 | // Specializations of template template parameters are represented as |
| 4890 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4891 | // within a dependent context can transform them into |
| 4892 | // DependentTemplateSpecializationTypes. |
| 4893 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4894 | DependentTemplateSpecializationTypeLoc NewTL |
| 4895 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4896 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4897 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4898 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4899 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4900 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4901 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4902 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4903 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4904 | return Result; |
| 4905 | } |
| 4906 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4907 | TemplateSpecializationTypeLoc NewTL |
| 4908 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4909 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4910 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4911 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4912 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4913 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4914 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4917 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4918 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4919 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4920 | template <typename Derived> |
| 4921 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4922 | TypeLocBuilder &TLB, |
| 4923 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 087eb5a | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4924 | TemplateName Template, |
| 4925 | CXXScopeSpec &SS) { |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4926 | TemplateArgumentListInfo NewTemplateArgs; |
| 4927 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4928 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4929 | typedef TemplateArgumentLocContainerIterator< |
| 4930 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4931 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4932 | ArgIterator(TL, TL.getNumArgs()), |
| 4933 | NewTemplateArgs)) |
| 4934 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4935 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4936 | // 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] | 4937 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4938 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4939 | QualType Result |
| 4940 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4941 | TL.getTypePtr()->getKeyword(), |
| 4942 | DTN->getQualifier(), |
| 4943 | DTN->getIdentifier(), |
| 4944 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4945 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4946 | DependentTemplateSpecializationTypeLoc NewTL |
| 4947 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4948 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4949 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4950 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4951 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4952 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4953 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4954 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4955 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4956 | return Result; |
| 4957 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4958 | |
| 4959 | QualType Result |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4960 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4961 | TL.getTemplateNameLoc(), |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4962 | NewTemplateArgs); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4963 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4964 | if (!Result.isNull()) { |
| 4965 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4966 | TemplateSpecializationTypeLoc NewTL |
| 4967 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4968 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4969 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4970 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4971 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4972 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4973 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4974 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4975 | |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4976 | return Result; |
| 4977 | } |
| 4978 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4980 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4981 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4982 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4983 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4984 | |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4985 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4986 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4987 | if (TL.getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4988 | QualifierLoc |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4989 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4990 | if (!QualifierLoc) |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4991 | return QualType(); |
| 4992 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4994 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4995 | if (NamedT.isNull()) |
| 4996 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4997 | |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4998 | // C++0x [dcl.type.elab]p2: |
| 4999 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 5000 | // resolves to an alias template specialization, the |
| 5001 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 1804174 | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 5002 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 5003 | if (const TemplateSpecializationType *TST = |
| 5004 | NamedT->getAs<TemplateSpecializationType>()) { |
| 5005 | TemplateName Template = TST->getTemplateName(); |
| 5006 | if (TypeAliasTemplateDecl *TAT = |
| 5007 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 5008 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 5009 | diag::err_tag_reference_non_tag) << 4; |
| 5010 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 5011 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5015 | QualType Result = TL.getType(); |
| 5016 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5017 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5018 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5019 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5020 | T->getKeyword(), |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5021 | QualifierLoc, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5022 | if (Result.isNull()) |
| 5023 | return QualType(); |
| 5024 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5025 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5026 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5027 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5028 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5029 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | |
| 5032 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5033 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5034 | TypeLocBuilder &TLB, |
| 5035 | AttributedTypeLoc TL) { |
| 5036 | const AttributedType *oldType = TL.getTypePtr(); |
| 5037 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5038 | if (modifiedType.isNull()) |
| 5039 | return QualType(); |
| 5040 | |
| 5041 | QualType result = TL.getType(); |
| 5042 | |
| 5043 | // FIXME: dependent operand expressions? |
| 5044 | if (getDerived().AlwaysRebuild() || |
| 5045 | modifiedType != oldType->getModifiedType()) { |
| 5046 | // TODO: this is really lame; we should really be rebuilding the |
| 5047 | // equivalent type from first principles. |
| 5048 | QualType equivalentType |
| 5049 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5050 | if (equivalentType.isNull()) |
| 5051 | return QualType(); |
| 5052 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5053 | modifiedType, |
| 5054 | equivalentType); |
| 5055 | } |
| 5056 | |
| 5057 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5058 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5059 | if (TL.hasAttrOperand()) |
| 5060 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5061 | if (TL.hasAttrExprOperand()) |
| 5062 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5063 | else if (TL.hasAttrEnumOperand()) |
| 5064 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5065 | |
| 5066 | return result; |
| 5067 | } |
| 5068 | |
| 5069 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5070 | QualType |
| 5071 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5072 | ParenTypeLoc TL) { |
| 5073 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5074 | if (Inner.isNull()) |
| 5075 | return QualType(); |
| 5076 | |
| 5077 | QualType Result = TL.getType(); |
| 5078 | if (getDerived().AlwaysRebuild() || |
| 5079 | Inner != TL.getInnerLoc().getType()) { |
| 5080 | Result = getDerived().RebuildParenType(Inner); |
| 5081 | if (Result.isNull()) |
| 5082 | return QualType(); |
| 5083 | } |
| 5084 | |
| 5085 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5086 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5087 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5088 | return Result; |
| 5089 | } |
| 5090 | |
| 5091 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5092 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5093 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5094 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5095 | |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5096 | NestedNameSpecifierLoc QualifierLoc |
| 5097 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5098 | if (!QualifierLoc) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5099 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5100 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5101 | QualType Result |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5102 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5103 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5104 | QualifierLoc, |
| 5105 | T->getIdentifier(), |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5106 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5107 | if (Result.isNull()) |
| 5108 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5109 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5110 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5111 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5112 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5113 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5114 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5115 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5116 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5117 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5118 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5119 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5120 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5121 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5122 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5123 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5125 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5126 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5127 | QualType TreeTransform<Derived>:: |
| 5128 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5129 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5130 | NestedNameSpecifierLoc QualifierLoc; |
| 5131 | if (TL.getQualifierLoc()) { |
| 5132 | QualifierLoc |
| 5133 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5134 | if (!QualifierLoc) |
Douglas Gregor | a88f09f | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5135 | return QualType(); |
| 5136 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5137 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5138 | return getDerived() |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5139 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | template<typename Derived> |
| 5143 | QualType TreeTransform<Derived>:: |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5144 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5145 | DependentTemplateSpecializationTypeLoc TL, |
| 5146 | NestedNameSpecifierLoc QualifierLoc) { |
| 5147 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5148 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5149 | TemplateArgumentListInfo NewTemplateArgs; |
| 5150 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5151 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5152 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5153 | typedef TemplateArgumentLocContainerIterator< |
| 5154 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5155 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5156 | ArgIterator(TL, TL.getNumArgs()), |
| 5157 | NewTemplateArgs)) |
| 5158 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5159 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5160 | QualType Result |
| 5161 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5162 | QualifierLoc, |
| 5163 | T->getIdentifier(), |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5164 | TL.getTemplateNameLoc(), |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5165 | NewTemplateArgs); |
| 5166 | if (Result.isNull()) |
| 5167 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5168 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5169 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5170 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5171 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5172 | // Copy information relevant to the template specialization. |
| 5173 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5174 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5175 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5176 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5177 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5178 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5179 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5180 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5181 | |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5182 | // Copy information relevant to the elaborated type. |
| 5183 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5184 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5185 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5186 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5187 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5188 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5189 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5190 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5191 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5192 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5193 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5194 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5195 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5196 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5197 | } else { |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5198 | TemplateSpecializationTypeLoc SpecTL |
| 5199 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5200 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5201 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5202 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5203 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 944cdae | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5204 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 0a0367a | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5205 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5206 | } |
| 5207 | return Result; |
| 5208 | } |
| 5209 | |
| 5210 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5211 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5212 | PackExpansionTypeLoc TL) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5213 | QualType Pattern |
| 5214 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5215 | if (Pattern.isNull()) |
| 5216 | return QualType(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5217 | |
| 5218 | QualType Result = TL.getType(); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5219 | if (getDerived().AlwaysRebuild() || |
| 5220 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5221 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5222 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5223 | TL.getEllipsisLoc(), |
| 5224 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5225 | if (Result.isNull()) |
| 5226 | return QualType(); |
| 5227 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5229 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5230 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5231 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5235 | QualType |
| 5236 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5237 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5238 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5239 | TLB.pushFullCopy(TL); |
| 5240 | return TL.getType(); |
| 5241 | } |
| 5242 | |
| 5243 | template<typename Derived> |
| 5244 | QualType |
| 5245 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5246 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5247 | // ObjCObjectType is never dependent. |
| 5248 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5249 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5251 | |
| 5252 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5253 | QualType |
| 5254 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5255 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5256 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5257 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5258 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5259 | } |
| 5260 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5261 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5262 | // Statement transformation |
| 5263 | //===----------------------------------------------------------------------===// |
| 5264 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5265 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5267 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5271 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5272 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5273 | return getDerived().TransformCompoundStmt(S, false); |
| 5274 | } |
| 5275 | |
| 5276 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5277 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5279 | bool IsStmtExpr) { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5280 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5281 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5282 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5283 | bool SubStmtChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5284 | SmallVector<Stmt*, 8> Statements; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5285 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5286 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5287 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5288 | if (Result.isInvalid()) { |
| 5289 | // Immediately fail if this was a DeclStmt, since it's very |
| 5290 | // likely that this will cause problems for future statements. |
| 5291 | if (isa<DeclStmt>(*B)) |
| 5292 | return StmtError(); |
| 5293 | |
| 5294 | // Otherwise, just keep processing substatements and fail later. |
| 5295 | SubStmtInvalid = true; |
| 5296 | continue; |
| 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 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5300 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5303 | if (SubStmtInvalid) |
| 5304 | return StmtError(); |
| 5305 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5306 | if (!getDerived().AlwaysRebuild() && |
| 5307 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5308 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5309 | |
| 5310 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5311 | Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5312 | S->getRBracLoc(), |
| 5313 | IsStmtExpr); |
| 5314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5315 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5316 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5317 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5318 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5319 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5320 | { |
Eli Friedman | 6b3014b | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5321 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5322 | Sema::ConstantEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5324 | // Transform the left-hand case value. |
| 5325 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5326 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5327 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5328 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5329 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5330 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5331 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | ac62601 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5332 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5333 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5334 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5335 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5336 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5337 | // Build the case statement. |
| 5338 | // Case statements are always rebuilt so that they will attached to their |
| 5339 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5340 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5341 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5342 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5343 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5344 | S->getColonLoc()); |
| 5345 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5346 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5347 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5348 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5349 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5350 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5351 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5353 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5354 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5358 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5359 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5360 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5361 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5362 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5363 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5365 | // Default statements are always rebuilt |
| 5366 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5367 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5369 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5370 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5371 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5373 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5374 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5375 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5377 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5378 | S->getDecl()); |
| 5379 | if (!LD) |
| 5380 | return StmtError(); |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5381 | |
| 5382 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5383 | // FIXME: Pass the real colon location in. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5384 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5385 | cast<LabelDecl>(LD), SourceLocation(), |
| 5386 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5388 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5389 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5390 | StmtResult |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5391 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5392 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5393 | if (SubStmt.isInvalid()) |
| 5394 | return StmtError(); |
| 5395 | |
| 5396 | // TODO: transform attributes |
| 5397 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5398 | return S; |
| 5399 | |
| 5400 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5401 | S->getAttrs(), |
| 5402 | SubStmt.get()); |
| 5403 | } |
| 5404 | |
| 5405 | template<typename Derived> |
| 5406 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5407 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5408 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5409 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5410 | VarDecl *ConditionVar = 0; |
| 5411 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5412 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5413 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5414 | getDerived().TransformDefinition( |
| 5415 | S->getConditionVariable()->getLocation(), |
| 5416 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5417 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5418 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5419 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5420 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5421 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5422 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5423 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5425 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5426 | if (S->getCond()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5427 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5428 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5429 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5430 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5431 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5432 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5433 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5434 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5435 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5436 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5437 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5438 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5439 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5440 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5441 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5442 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5443 | return StmtError(); |
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 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5446 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5447 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5448 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5450 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5451 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5452 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5453 | Then.get() == S->getThen() && |
| 5454 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5455 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5457 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5458 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5459 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5460 | } |
| 5461 | |
| 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>::TransformSwitchStmt(SwitchStmt *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 | d3d5301 | 2009-11-24 17:07:59 +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 | d3d5301 | 2009-11-24 17:07:59 +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 | d3d5301 | 2009-11-24 17:07:59 +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 | d3d5301 | 2009-11-24 17:07:59 +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 | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5481 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5482 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5483 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5484 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5485 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5486 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5487 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5488 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5489 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5490 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5491 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5492 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5493 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5494 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5495 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5496 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5497 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5498 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5499 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5500 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5501 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5502 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5503 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5504 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5505 | VarDecl *ConditionVar = 0; |
| 5506 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5507 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5508 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5509 | getDerived().TransformDefinition( |
| 5510 | S->getConditionVariable()->getLocation(), |
| 5511 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5512 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5513 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5514 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5515 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5516 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5517 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5518 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5519 | |
| 5520 | if (S->getCond()) { |
| 5521 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5522 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5523 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5524 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5525 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5526 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5527 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5529 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5530 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5531 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5532 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5533 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5534 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5535 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5536 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5537 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5538 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5539 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5540 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5541 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5542 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5543 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5544 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5545 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5546 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5547 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5549 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5550 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5551 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5552 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5553 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5554 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5555 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5556 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5557 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5558 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5559 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5560 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5561 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5562 | if (!getDerived().AlwaysRebuild() && |
| 5563 | Cond.get() == S->getCond() && |
| 5564 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5565 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5566 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5567 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5568 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5569 | S->getRParenLoc()); |
| 5570 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5571 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5572 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5573 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5575 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5576 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5577 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5578 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5579 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5580 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5581 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5582 | VarDecl *ConditionVar = 0; |
| 5583 | if (S->getConditionVariable()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5584 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5585 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5586 | getDerived().TransformDefinition( |
| 5587 | S->getConditionVariable()->getLocation(), |
| 5588 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5589 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5590 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5591 | } else { |
| 5592 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5593 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5594 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5595 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5596 | |
| 5597 | if (S->getCond()) { |
| 5598 | // Convert the condition to a boolean value. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5599 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5600 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5601 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5602 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5603 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5604 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5605 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5606 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5608 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5609 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5610 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5611 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5612 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5613 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5614 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5615 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | |
Richard Smith | 4195637 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5617 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5618 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5619 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5620 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5621 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5622 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5623 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5624 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5625 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5626 | if (!getDerived().AlwaysRebuild() && |
| 5627 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5628 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5629 | Inc.get() == S->getInc() && |
| 5630 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5631 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5632 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5633 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5634 | Init.get(), FullCond, ConditionVar, |
| 5635 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5639 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5640 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5641 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5642 | S->getLabel()); |
| 5643 | if (!LD) |
| 5644 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5645 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5646 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5647 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5648 | cast<LabelDecl>(LD)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5652 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5654 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5655 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5656 | return StmtError(); |
Eli Friedman | d29975f | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5657 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5659 | if (!getDerived().AlwaysRebuild() && |
| 5660 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5661 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5662 | |
| 5663 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5664 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5668 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5669 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5670 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5671 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5672 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5673 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5674 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5675 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5676 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5677 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5679 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5680 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5681 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5682 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5683 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5684 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5685 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5687 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5688 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5689 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5690 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5691 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5692 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5694 | bool DeclChanged = false; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5695 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5696 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5697 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5698 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5699 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5700 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5701 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5703 | if (Transformed != *D) |
| 5704 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5705 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5706 | Decls.push_back(Transformed); |
| 5707 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5708 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5709 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5710 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5711 | |
Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5712 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5713 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5714 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5715 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5716 | StmtResult |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5717 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5718 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5719 | SmallVector<Expr*, 8> Constraints; |
| 5720 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5721 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5722 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5723 | ExprResult AsmString; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5724 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5725 | |
| 5726 | bool ExprsChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5727 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5728 | // Go through the outputs. |
| 5729 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5730 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5731 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5732 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5733 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5734 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5735 | // Transform the output expr. |
| 5736 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5737 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5738 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5739 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5740 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5741 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5742 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5743 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5744 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5745 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5746 | // Go through the inputs. |
| 5747 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5748 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5749 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5750 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5751 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5752 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5753 | // Transform the input expr. |
| 5754 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5755 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5756 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5757 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5758 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5759 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5760 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5761 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5762 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5763 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5764 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5765 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5766 | |
| 5767 | // Go through the clobbers. |
| 5768 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | 5c7f594 | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5769 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5770 | |
| 5771 | // No need to transform the asm string literal. |
| 5772 | AsmString = SemaRef.Owned(S->getAsmString()); |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5773 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5774 | S->isVolatile(), S->getNumOutputs(), |
| 5775 | S->getNumInputs(), Names.data(), |
| 5776 | Constraints, Exprs, AsmString.get(), |
| 5777 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5778 | } |
| 5779 | |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5780 | template<typename Derived> |
| 5781 | StmtResult |
| 5782 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5783 | ArrayRef<Token> AsmToks = |
| 5784 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5785 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5786 | bool HadError = false, HadChange = false; |
| 5787 | |
| 5788 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5789 | SmallVector<Expr*, 8> TransformedExprs; |
| 5790 | TransformedExprs.reserve(SrcExprs.size()); |
| 5791 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5792 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5793 | if (!Result.isUsable()) { |
| 5794 | HadError = true; |
| 5795 | } else { |
| 5796 | HadChange |= (Result.get() != SrcExprs[i]); |
| 5797 | TransformedExprs.push_back(Result.take()); |
| 5798 | } |
| 5799 | } |
| 5800 | |
| 5801 | if (HadError) return StmtError(); |
| 5802 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 5803 | return Owned(S); |
| 5804 | |
Chad Rosier | 7bd092b | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5805 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5806 | AsmToks, S->getAsmString(), |
| 5807 | S->getNumOutputs(), S->getNumInputs(), |
| 5808 | S->getAllConstraints(), S->getClobbers(), |
| 5809 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5810 | } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5811 | |
| 5812 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5813 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5814 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5815 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5816 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5817 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5818 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5819 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5820 | // Transform the @catch statements (if present). |
| 5821 | bool AnyCatchChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5822 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5823 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5824 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5825 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5826 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5827 | if (Catch.get() != S->getCatchStmt(I)) |
| 5828 | AnyCatchChanged = true; |
| 5829 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5830 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5831 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5832 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5833 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5834 | if (S->getFinallyStmt()) { |
| 5835 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5836 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5837 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | // If nothing changed, just retain this statement. |
| 5841 | if (!getDerived().AlwaysRebuild() && |
| 5842 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5843 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5844 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5845 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5846 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5847 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5848 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5849 | CatchStmts, Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5852 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5853 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5854 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5855 | // Transform the @catch parameter, if there is one. |
| 5856 | VarDecl *Var = 0; |
| 5857 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5858 | TypeSourceInfo *TSInfo = 0; |
| 5859 | if (FromVar->getTypeSourceInfo()) { |
| 5860 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5861 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5862 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5863 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5864 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5865 | QualType T; |
| 5866 | if (TSInfo) |
| 5867 | T = TSInfo->getType(); |
| 5868 | else { |
| 5869 | T = getDerived().TransformType(FromVar->getType()); |
| 5870 | if (T.isNull()) |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5871 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5872 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5873 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5874 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5875 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5876 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5877 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5878 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5879 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5880 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5881 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5882 | |
| 5883 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5884 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5885 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5886 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5887 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5888 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5889 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5890 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5891 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5892 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5893 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5894 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5895 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5896 | // If nothing changed, just retain this statement. |
| 5897 | if (!getDerived().AlwaysRebuild() && |
| 5898 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5899 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5900 | |
| 5901 | // Build a new statement. |
| 5902 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5903 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5904 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5905 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5906 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5907 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5908 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5909 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5910 | if (S->getThrowExpr()) { |
| 5911 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5912 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5913 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5914 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5915 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5916 | if (!getDerived().AlwaysRebuild() && |
| 5917 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5918 | return getSema().Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5919 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5920 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5921 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5922 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5923 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5924 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5925 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5926 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5927 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5928 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5929 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5930 | return StmtError(); |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5931 | Object = |
| 5932 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5933 | Object.get()); |
| 5934 | if (Object.isInvalid()) |
| 5935 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5936 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5937 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5938 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5939 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5940 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5941 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5942 | // If nothing change, just retain the current statement. |
| 5943 | if (!getDerived().AlwaysRebuild() && |
| 5944 | Object.get() == S->getSynchExpr() && |
| 5945 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5946 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5947 | |
| 5948 | // Build a new statement. |
| 5949 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5950 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5954 | StmtResult |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5955 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5956 | ObjCAutoreleasePoolStmt *S) { |
| 5957 | // Transform the body. |
| 5958 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5959 | if (Body.isInvalid()) |
| 5960 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5961 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5962 | // If nothing changed, just retain this statement. |
| 5963 | if (!getDerived().AlwaysRebuild() && |
| 5964 | Body.get() == S->getSubStmt()) |
| 5965 | return SemaRef.Owned(S); |
| 5966 | |
| 5967 | // Build a new statement. |
| 5968 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5969 | S->getAtLoc(), Body.get()); |
| 5970 | } |
| 5971 | |
| 5972 | template<typename Derived> |
| 5973 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5974 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5975 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5976 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5977 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5978 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5979 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5980 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5981 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5982 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5983 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5984 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5985 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5986 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5987 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5988 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5989 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5990 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5991 | // If nothing changed, just retain this statement. |
| 5992 | if (!getDerived().AlwaysRebuild() && |
| 5993 | Element.get() == S->getElement() && |
| 5994 | Collection.get() == S->getCollection() && |
| 5995 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5996 | return SemaRef.Owned(S); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5997 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5998 | // Build a new statement. |
| 5999 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6000 | Element.get(), |
| 6001 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 6002 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6003 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6006 | template <typename Derived> |
| 6007 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6008 | // Transform the exception declaration, if any. |
| 6009 | VarDecl *Var = 0; |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6010 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 6011 | TypeSourceInfo *T = |
| 6012 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 6013 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6014 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6015 | |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6016 | Var = getDerived().RebuildExceptionDecl( |
| 6017 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 6018 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6019 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6020 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6022 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6023 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6024 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 6025 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6026 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6027 | |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6028 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6029 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6030 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6031 | |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6032 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
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 | |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6035 | template <typename Derived> |
| 6036 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6037 | // Transform the try block itself. |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6038 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6039 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6040 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6041 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6042 | // Transform the handlers. |
| 6043 | bool HandlerChanged = false; |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6044 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6045 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6046 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6047 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6048 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6049 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6050 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 6051 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 6052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6053 | |
David Majnemer | 2c4a01d | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6054 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6055 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6056 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6057 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6058 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6059 | Handlers); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6060 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6061 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6062 | template<typename Derived> |
| 6063 | StmtResult |
| 6064 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6065 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6066 | if (Range.isInvalid()) |
| 6067 | return StmtError(); |
| 6068 | |
| 6069 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6070 | if (BeginEnd.isInvalid()) |
| 6071 | return StmtError(); |
| 6072 | |
| 6073 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6074 | if (Cond.isInvalid()) |
| 6075 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6076 | if (Cond.get()) |
| 6077 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 6078 | if (Cond.isInvalid()) |
| 6079 | return StmtError(); |
| 6080 | if (Cond.get()) |
| 6081 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6082 | |
| 6083 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6084 | if (Inc.isInvalid()) |
| 6085 | return StmtError(); |
Eli Friedman | c6c14e5 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6086 | if (Inc.get()) |
| 6087 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6088 | |
| 6089 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6090 | if (LoopVar.isInvalid()) |
| 6091 | return StmtError(); |
| 6092 | |
| 6093 | StmtResult NewStmt = S; |
| 6094 | if (getDerived().AlwaysRebuild() || |
| 6095 | Range.get() != S->getRangeStmt() || |
| 6096 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6097 | Cond.get() != S->getCond() || |
| 6098 | Inc.get() != S->getInc() || |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6099 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6100 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6101 | S->getColonLoc(), Range.get(), |
| 6102 | BeginEnd.get(), Cond.get(), |
| 6103 | Inc.get(), LoopVar.get(), |
| 6104 | S->getRParenLoc()); |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6105 | if (NewStmt.isInvalid()) |
| 6106 | return StmtError(); |
| 6107 | } |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6108 | |
| 6109 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6110 | if (Body.isInvalid()) |
| 6111 | return StmtError(); |
| 6112 | |
| 6113 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6114 | // 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] | 6115 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6116 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6117 | S->getColonLoc(), Range.get(), |
| 6118 | BeginEnd.get(), Cond.get(), |
| 6119 | Inc.get(), LoopVar.get(), |
| 6120 | S->getRParenLoc()); |
Douglas Gregor | 39b60dc | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6121 | if (NewStmt.isInvalid()) |
| 6122 | return StmtError(); |
| 6123 | } |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6124 | |
| 6125 | if (NewStmt.get() == S) |
| 6126 | return SemaRef.Owned(S); |
| 6127 | |
| 6128 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6129 | } |
| 6130 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6131 | template<typename Derived> |
| 6132 | StmtResult |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6133 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6134 | MSDependentExistsStmt *S) { |
| 6135 | // Transform the nested-name-specifier, if any. |
| 6136 | NestedNameSpecifierLoc QualifierLoc; |
| 6137 | if (S->getQualifierLoc()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6138 | QualifierLoc |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6139 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6140 | if (!QualifierLoc) |
| 6141 | return StmtError(); |
| 6142 | } |
| 6143 | |
| 6144 | // Transform the declaration name. |
| 6145 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6146 | if (NameInfo.getName()) { |
| 6147 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6148 | if (!NameInfo.getName()) |
| 6149 | return StmtError(); |
| 6150 | } |
| 6151 | |
| 6152 | // Check whether anything changed. |
| 6153 | if (!getDerived().AlwaysRebuild() && |
| 6154 | QualifierLoc == S->getQualifierLoc() && |
| 6155 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6156 | return S; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6157 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6158 | // Determine whether this name exists, if we can. |
| 6159 | CXXScopeSpec SS; |
| 6160 | SS.Adopt(QualifierLoc); |
| 6161 | bool Dependent = false; |
| 6162 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 6163 | case Sema::IER_Exists: |
| 6164 | if (S->isIfExists()) |
| 6165 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6166 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6167 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6168 | |
| 6169 | case Sema::IER_DoesNotExist: |
| 6170 | if (S->isIfNotExists()) |
| 6171 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6172 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6173 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6174 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6175 | case Sema::IER_Dependent: |
| 6176 | Dependent = true; |
| 6177 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6178 | |
Douglas Gregor | 65019ac | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6179 | case Sema::IER_Error: |
| 6180 | return StmtError(); |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6181 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6182 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6183 | // We need to continue with the instantiation, so do so now. |
| 6184 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6185 | if (SubStmt.isInvalid()) |
| 6186 | return StmtError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6187 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6188 | // If we have resolved the name, just transform to the substatement. |
| 6189 | if (!Dependent) |
| 6190 | return SubStmt; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6191 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6192 | // The name is still dependent, so build a dependent expression again. |
| 6193 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6194 | S->isIfExists(), |
| 6195 | QualifierLoc, |
| 6196 | NameInfo, |
| 6197 | SubStmt.get()); |
| 6198 | } |
| 6199 | |
| 6200 | template<typename Derived> |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6201 | ExprResult |
| 6202 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6203 | NestedNameSpecifierLoc QualifierLoc; |
| 6204 | if (E->getQualifierLoc()) { |
| 6205 | QualifierLoc |
| 6206 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6207 | if (!QualifierLoc) |
| 6208 | return ExprError(); |
| 6209 | } |
| 6210 | |
| 6211 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6212 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6213 | if (!PD) |
| 6214 | return ExprError(); |
| 6215 | |
| 6216 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6217 | if (Base.isInvalid()) |
| 6218 | return ExprError(); |
| 6219 | |
| 6220 | return new (SemaRef.getASTContext()) |
| 6221 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6222 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6223 | QualifierLoc, E->getMemberLoc()); |
| 6224 | } |
| 6225 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6226 | template <typename Derived> |
| 6227 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7752a74 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6228 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6229 | if (TryBlock.isInvalid()) |
| 6230 | return StmtError(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6231 | |
| 6232 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7752a74 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6233 | if (Handler.isInvalid()) |
| 6234 | return StmtError(); |
| 6235 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6236 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6237 | Handler.get() == S->getHandler()) |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6238 | return SemaRef.Owned(S); |
| 6239 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6240 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 6241 | TryBlock.take(), Handler.take()); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6242 | } |
| 6243 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6244 | template <typename Derived> |
| 6245 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7752a74 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6246 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6247 | if (Block.isInvalid()) |
| 6248 | return StmtError(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6249 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6250 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take()); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6251 | } |
| 6252 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6253 | template <typename Derived> |
| 6254 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6255 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6256 | if (FilterExpr.isInvalid()) |
| 6257 | return StmtError(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6258 | |
David Majnemer | 7752a74 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6259 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6260 | if (Block.isInvalid()) |
| 6261 | return StmtError(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6262 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6263 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(), |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6264 | Block.take()); |
| 6265 | } |
| 6266 | |
David Majnemer | fc21049 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6267 | template <typename Derived> |
| 6268 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6269 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6270 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6271 | else |
| 6272 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6273 | } |
| 6274 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6275 | template<typename Derived> |
| 6276 | StmtResult |
| 6277 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6278 | DeclarationNameInfo DirName; |
| 6279 | getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0); |
| 6280 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6281 | // Transform the clauses |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6282 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6283 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6284 | TClauses.reserve(Clauses.size()); |
| 6285 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6286 | I != E; ++I) { |
| 6287 | if (*I) { |
| 6288 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6289 | if (!Clause) { |
| 6290 | getSema().EndOpenMPDSABlock(0); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6291 | return StmtError(); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6292 | } |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6293 | TClauses.push_back(Clause); |
| 6294 | } |
| 6295 | else { |
| 6296 | TClauses.push_back(0); |
| 6297 | } |
| 6298 | } |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6299 | if (!D->getAssociatedStmt()) { |
| 6300 | getSema().EndOpenMPDSABlock(0); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6301 | return StmtError(); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6302 | } |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6303 | StmtResult AssociatedStmt = |
| 6304 | getDerived().TransformStmt(D->getAssociatedStmt()); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6305 | if (AssociatedStmt.isInvalid()) { |
| 6306 | getSema().EndOpenMPDSABlock(0); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6307 | return StmtError(); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6308 | } |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6309 | |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6310 | StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses, |
| 6311 | AssociatedStmt.take(), |
| 6312 | D->getLocStart(), |
| 6313 | D->getLocEnd()); |
| 6314 | getSema().EndOpenMPDSABlock(Res.get()); |
| 6315 | return Res; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | template<typename Derived> |
| 6319 | OMPClause * |
| 6320 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| 6321 | return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(), |
| 6322 | C->getDefaultKindKwLoc(), |
| 6323 | C->getLocStart(), |
| 6324 | C->getLParenLoc(), |
| 6325 | C->getLocEnd()); |
| 6326 | } |
| 6327 | |
| 6328 | template<typename Derived> |
| 6329 | OMPClause * |
| 6330 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6331 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6332 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 543c4ae | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 6333 | for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(), |
| 6334 | E = C->varlist_end(); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6335 | I != E; ++I) { |
| 6336 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6337 | if (EVar.isInvalid()) |
| 6338 | return 0; |
| 6339 | Vars.push_back(EVar.take()); |
| 6340 | } |
| 6341 | return getDerived().RebuildOMPPrivateClause(Vars, |
| 6342 | C->getLocStart(), |
| 6343 | C->getLParenLoc(), |
| 6344 | C->getLocEnd()); |
| 6345 | } |
| 6346 | |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6347 | template<typename Derived> |
| 6348 | OMPClause * |
Alexey Bataev | d195bc3 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6349 | TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 6350 | OMPFirstprivateClause *C) { |
| 6351 | llvm::SmallVector<Expr *, 16> Vars; |
| 6352 | Vars.reserve(C->varlist_size()); |
| 6353 | for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(), |
| 6354 | E = C->varlist_end(); |
| 6355 | I != E; ++I) { |
| 6356 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6357 | if (EVar.isInvalid()) |
| 6358 | return 0; |
| 6359 | Vars.push_back(EVar.take()); |
| 6360 | } |
| 6361 | return getDerived().RebuildOMPFirstprivateClause(Vars, |
| 6362 | C->getLocStart(), |
| 6363 | C->getLParenLoc(), |
| 6364 | C->getLocEnd()); |
| 6365 | } |
| 6366 | |
| 6367 | template<typename Derived> |
| 6368 | OMPClause * |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6369 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 6370 | llvm::SmallVector<Expr *, 16> Vars; |
| 6371 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 543c4ae | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 6372 | for (OMPSharedClause::varlist_iterator I = C->varlist_begin(), |
| 6373 | E = C->varlist_end(); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6374 | I != E; ++I) { |
| 6375 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6376 | if (EVar.isInvalid()) |
| 6377 | return 0; |
| 6378 | Vars.push_back(EVar.take()); |
| 6379 | } |
| 6380 | return getDerived().RebuildOMPSharedClause(Vars, |
| 6381 | C->getLocStart(), |
| 6382 | C->getLParenLoc(), |
| 6383 | C->getLocEnd()); |
| 6384 | } |
| 6385 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6386 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6387 | // Expression transformation |
| 6388 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6389 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6390 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6391 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6392 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6393 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6394 | |
| 6395 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6396 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6397 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6398 | NestedNameSpecifierLoc QualifierLoc; |
| 6399 | if (E->getQualifierLoc()) { |
| 6400 | QualifierLoc |
| 6401 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6402 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6403 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6404 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6405 | |
| 6406 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6407 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6408 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6409 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6410 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6411 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6412 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6413 | if (NameInfo.getName()) { |
| 6414 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6415 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6416 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6417 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6418 | |
| 6419 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6420 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6421 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6422 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6423 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6424 | |
| 6425 | // Mark it referenced in the new context regardless. |
| 6426 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6427 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6428 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6429 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6430 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6431 | |
| 6432 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6433 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6434 | TemplateArgs = &TransArgs; |
| 6435 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6436 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6437 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6438 | E->getNumTemplateArgs(), |
| 6439 | TransArgs)) |
| 6440 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6441 | } |
| 6442 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6443 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6444 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6445 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6446 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6447 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6448 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6449 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6450 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6451 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6452 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6453 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6454 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6455 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6456 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6457 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6458 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6460 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6461 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6462 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6463 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6464 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6465 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6466 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6467 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6468 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6470 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +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>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6474 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6478 | ExprResult |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6479 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 391ca9f | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6480 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6481 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6482 | return SemaRef.MaybeBindToTemporary(E); |
| 6483 | } |
| 6484 | |
| 6485 | template<typename Derived> |
| 6486 | ExprResult |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6487 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6488 | ExprResult ControllingExpr = |
| 6489 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6490 | if (ControllingExpr.isInvalid()) |
| 6491 | return ExprError(); |
| 6492 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6493 | SmallVector<Expr *, 4> AssocExprs; |
| 6494 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6495 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6496 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6497 | if (TS) { |
| 6498 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6499 | if (!AssocType) |
| 6500 | return ExprError(); |
| 6501 | AssocTypes.push_back(AssocType); |
| 6502 | } else { |
| 6503 | AssocTypes.push_back(0); |
| 6504 | } |
| 6505 | |
| 6506 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6507 | if (AssocExpr.isInvalid()) |
| 6508 | return ExprError(); |
| 6509 | AssocExprs.push_back(AssocExpr.release()); |
| 6510 | } |
| 6511 | |
| 6512 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6513 | E->getDefaultLoc(), |
| 6514 | E->getRParenLoc(), |
| 6515 | ControllingExpr.release(), |
Dmitri Gribenko | 8061322 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 6516 | AssocTypes, |
| 6517 | AssocExprs); |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6518 | } |
| 6519 | |
| 6520 | template<typename Derived> |
| 6521 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6522 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6523 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6524 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6525 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6526 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6527 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6528 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6529 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6530 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6531 | E->getRParen()); |
| 6532 | } |
| 6533 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6534 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6535 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6536 | /// object available. |
| 6537 | template<typename Derived> |
| 6538 | ExprResult |
| 6539 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6540 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 6541 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); |
| 6542 | else |
| 6543 | return getDerived().TransformExpr(E); |
| 6544 | } |
| 6545 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6546 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6547 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6548 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | 82b0001 | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 6549 | ExprResult SubExpr; |
| 6550 | if (E->getOpcode() == UO_AddrOf) |
| 6551 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 6552 | else |
| 6553 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6554 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6555 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6557 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6558 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6559 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6560 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6561 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6562 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6565 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6566 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6567 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6568 | // Transform the type. |
| 6569 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6570 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6571 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6572 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6573 | // Transform all of the components into components similar to what the |
| 6574 | // parser uses. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6575 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6576 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6577 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6578 | // template code that we don't care. |
| 6579 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6580 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6581 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6582 | SmallVector<Component, 4> Components; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6583 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6584 | const Node &ON = E->getComponent(I); |
| 6585 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6586 | Comp.isBrackets = true; |
Abramo Bagnara | 06dec89 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6587 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6588 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6589 | switch (ON.getKind()) { |
| 6590 | case Node::Array: { |
| 6591 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6592 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6593 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6594 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6595 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6596 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6597 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6598 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6599 | break; |
| 6600 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6601 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6602 | case Node::Field: |
| 6603 | case Node::Identifier: |
| 6604 | Comp.isBrackets = false; |
| 6605 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6606 | if (!Comp.U.IdentInfo) |
| 6607 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6608 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6609 | break; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6610 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6611 | case Node::Base: |
| 6612 | // Will be recomputed during the rebuild. |
| 6613 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6614 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6615 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6616 | Components.push_back(Comp); |
| 6617 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6618 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6619 | // If nothing changed, retain the existing expression. |
| 6620 | if (!getDerived().AlwaysRebuild() && |
| 6621 | Type == E->getTypeSourceInfo() && |
| 6622 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6623 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6624 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6625 | // Build a new offsetof expression. |
| 6626 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6627 | Components.data(), Components.size(), |
| 6628 | E->getRParenLoc()); |
| 6629 | } |
| 6630 | |
| 6631 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6632 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6633 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6634 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6635 | "opaque value expression requires transformation"); |
| 6636 | return SemaRef.Owned(E); |
| 6637 | } |
| 6638 | |
| 6639 | template<typename Derived> |
| 6640 | ExprResult |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6641 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | 01e19be | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6642 | // Rebuild the syntactic form. The original syntactic form has |
| 6643 | // opaque-value expressions in it, so strip those away and rebuild |
| 6644 | // the result. This is a really awful way of doing this, but the |
| 6645 | // better solution (rebuilding the semantic expressions and |
| 6646 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6647 | // TreeTransform to not strip away implicit conversions. |
| 6648 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6649 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6650 | if (result.isInvalid()) return ExprError(); |
| 6651 | |
| 6652 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6653 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6654 | // should reapply. |
| 6655 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6656 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6657 | |
| 6658 | return result; |
| 6659 | } |
| 6660 | |
| 6661 | template<typename Derived> |
| 6662 | ExprResult |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6663 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6664 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6666 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6667 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6668 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6669 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6670 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6671 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6672 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6673 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6674 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6675 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6676 | E->getKind(), |
| 6677 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6678 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6679 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6680 | // C++0x [expr.sizeof]p1: |
| 6681 | // The operand is either an expression, which is an unevaluated operand |
| 6682 | // [...] |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 6683 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 6684 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6685 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6686 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6687 | if (SubExpr.isInvalid()) |
| 6688 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6689 | |
Eli Friedman | 72b8b1e | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6690 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6691 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6692 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6693 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6694 | E->getOperatorLoc(), |
| 6695 | E->getKind(), |
| 6696 | E->getSourceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6697 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6699 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6700 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6701 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6702 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6703 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6704 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6705 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6706 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6707 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6708 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6709 | |
| 6710 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6711 | if (!getDerived().AlwaysRebuild() && |
| 6712 | LHS.get() == E->getLHS() && |
| 6713 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6714 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6715 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6716 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6717 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6718 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6719 | E->getRBracketLoc()); |
| 6720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6721 | |
| 6722 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6723 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6724 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6725 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6726 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6727 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6728 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6729 | |
| 6730 | // Transform arguments. |
| 6731 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6732 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6733 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6734 | &ArgChanged)) |
| 6735 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6736 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6737 | if (!getDerived().AlwaysRebuild() && |
| 6738 | Callee.get() == E->getCallee() && |
| 6739 | !ArgChanged) |
Dmitri Gribenko | 1ad23d6 | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 6740 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6741 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6742 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6743 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6744 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6745 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6746 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6747 | E->getRParenLoc()); |
| 6748 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6749 | |
| 6750 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6751 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6752 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6753 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6754 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6755 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6756 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6757 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6758 | if (E->hasQualifier()) { |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6759 | QualifierLoc |
| 6760 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6761 | |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6762 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6763 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6764 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6765 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6766 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6767 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6768 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6769 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6770 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6771 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6772 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6773 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6774 | if (FoundDecl == E->getMemberDecl()) { |
| 6775 | FoundDecl = Member; |
| 6776 | } else { |
| 6777 | FoundDecl = cast_or_null<NamedDecl>( |
| 6778 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6779 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6780 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6781 | } |
| 6782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6783 | if (!getDerived().AlwaysRebuild() && |
| 6784 | Base.get() == E->getBase() && |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6785 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6786 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6787 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6788 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6789 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6790 | // Mark it referenced in the new context regardless. |
| 6791 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6792 | SemaRef.MarkMemberReferenced(E); |
| 6793 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6794 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6795 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6796 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6797 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6798 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6799 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6800 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6801 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6802 | E->getNumTemplateArgs(), |
| 6803 | TransArgs)) |
| 6804 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6805 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6807 | // FIXME: Bogus source location for the operator |
| 6808 | SourceLocation FakeOperatorLoc |
| 6809 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6810 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6811 | // FIXME: to do this check properly, we will need to preserve the |
| 6812 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6813 | // base (and therefore couldn't do the check) and a |
| 6814 | // nested-name-qualifier (and therefore could do the lookup). |
| 6815 | NamedDecl *FirstQualifierInScope = 0; |
| 6816 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6817 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6818 | E->isArrow(), |
Douglas Gregor | 40d96a6 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6819 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6820 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6821 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6822 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6823 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6824 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6825 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6826 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6827 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6829 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6830 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6831 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6832 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6833 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6834 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6835 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6836 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6837 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6838 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6840 | if (!getDerived().AlwaysRebuild() && |
| 6841 | LHS.get() == E->getLHS() && |
| 6842 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6843 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6844 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6845 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6846 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6847 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6848 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6849 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6850 | } |
| 6851 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6852 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6853 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6854 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6855 | CompoundAssignOperator *E) { |
| 6856 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6857 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6859 | template<typename Derived> |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6860 | ExprResult TreeTransform<Derived>:: |
| 6861 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6862 | // Just rebuild the common and RHS expressions and see whether we |
| 6863 | // get any changes. |
| 6864 | |
| 6865 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6866 | if (commonExpr.isInvalid()) |
| 6867 | return ExprError(); |
| 6868 | |
| 6869 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6870 | if (rhs.isInvalid()) |
| 6871 | return ExprError(); |
| 6872 | |
| 6873 | if (!getDerived().AlwaysRebuild() && |
| 6874 | commonExpr.get() == e->getCommon() && |
| 6875 | rhs.get() == e->getFalseExpr()) |
| 6876 | return SemaRef.Owned(e); |
| 6877 | |
| 6878 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6879 | e->getQuestionLoc(), |
| 6880 | 0, |
| 6881 | e->getColonLoc(), |
| 6882 | rhs.get()); |
| 6883 | } |
| 6884 | |
| 6885 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6886 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6887 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6888 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6889 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6890 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6891 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6892 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6893 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6894 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6895 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6896 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6897 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6898 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6899 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6900 | if (!getDerived().AlwaysRebuild() && |
| 6901 | Cond.get() == E->getCond() && |
| 6902 | LHS.get() == E->getLHS() && |
| 6903 | RHS.get() == E->getRHS()) |
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 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6906 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6907 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6908 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6909 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6910 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6911 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6912 | |
| 6913 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6914 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6915 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6916 | // Implicit casts are eliminated during transformation, since they |
| 6917 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6918 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6920 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6921 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6922 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6923 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6924 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6925 | if (!Type) |
| 6926 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6927 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6928 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6929 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6930 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6931 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6932 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6933 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6934 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6935 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6936 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6937 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6938 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6939 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6940 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6941 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6942 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6943 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6944 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6945 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6946 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6947 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6948 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6949 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6950 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6951 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6952 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6953 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6954 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6955 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6956 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6957 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6958 | Init.get() == E->getInitializer()) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6959 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6960 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6961 | // Note: the expression type doesn't necessarily match the |
| 6962 | // type-as-written, but that's okay, because it should always be |
| 6963 | // derivable from the initializer. |
| 6964 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6965 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6966 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6967 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6968 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6969 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6970 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6971 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6973 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6974 | if (Base.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 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6977 | if (!getDerived().AlwaysRebuild() && |
| 6978 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6979 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6981 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6982 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6983 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6984 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6985 | E->getAccessorLoc(), |
| 6986 | E->getAccessor()); |
| 6987 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6988 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6989 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6990 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6991 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6992 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6993 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6994 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6995 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6996 | Inits, &InitChanged)) |
| 6997 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6998 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7000 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7001 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7002 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 7003 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7005 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7006 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7007 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7008 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7009 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7010 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7011 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7012 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7013 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7014 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7015 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7016 | // transform the designators. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7017 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7018 | bool ExprChanged = false; |
| 7019 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 7020 | DEnd = E->designators_end(); |
| 7021 | D != DEnd; ++D) { |
| 7022 | if (D->isFieldDesignator()) { |
| 7023 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 7024 | D->getDotLoc(), |
| 7025 | D->getFieldLoc())); |
| 7026 | continue; |
| 7027 | } |
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 (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7030 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7031 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7032 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7033 | |
| 7034 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7035 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7037 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 7038 | ArrayExprs.push_back(Index.release()); |
| 7039 | continue; |
| 7040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7041 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7042 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7043 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7044 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 7045 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7046 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7047 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7048 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7049 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7050 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7051 | |
| 7052 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7053 | End.get(), |
| 7054 | D->getLBracketLoc(), |
| 7055 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7056 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7057 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 7058 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7059 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7060 | ArrayExprs.push_back(Start.release()); |
| 7061 | ArrayExprs.push_back(End.release()); |
| 7062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7063 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7064 | if (!getDerived().AlwaysRebuild() && |
| 7065 | Init.get() == E->getInit() && |
| 7066 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7067 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7068 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7069 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7070 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7071 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7073 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7074 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7075 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7076 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7077 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7078 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7079 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7080 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7081 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7082 | QualType T = getDerived().TransformType(E->getType()); |
| 7083 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7084 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7085 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7086 | if (!getDerived().AlwaysRebuild() && |
| 7087 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7088 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7089 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7090 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7091 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7093 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7094 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7095 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7096 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7097 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7098 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7099 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7100 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7101 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7102 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7103 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7104 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7105 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7106 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7107 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7108 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7109 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7110 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7114 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7115 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7116 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7117 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7118 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7119 | &ArgumentChanged)) |
| 7120 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7122 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7123 | Inits, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7124 | E->getRParenLoc()); |
| 7125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7127 | /// \brief Transform an address-of-label expression. |
| 7128 | /// |
| 7129 | /// By default, the transformation of an address-of-label expression always |
| 7130 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7131 | /// the corresponding label statement by semantic analysis. |
| 7132 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7133 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7134 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7135 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7136 | E->getLabel()); |
| 7137 | if (!LD) |
| 7138 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7139 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7140 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | 57ad378 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7141 | cast<LabelDecl>(LD)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7143 | |
| 7144 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7145 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7146 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7147 | SemaRef.ActOnStartStmtExpr(); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7148 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7149 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7150 | if (SubStmt.isInvalid()) { |
| 7151 | SemaRef.ActOnStmtExprError(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7152 | return ExprError(); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7153 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7154 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7155 | if (!getDerived().AlwaysRebuild() && |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7156 | SubStmt.get() == E->getSubStmt()) { |
| 7157 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7158 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7159 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | 7f39d51 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7160 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7161 | |
| 7162 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7163 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7164 | E->getRParenLoc()); |
| 7165 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7166 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7167 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7168 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7169 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7170 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7171 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7172 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7173 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7174 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7175 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7176 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7177 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7178 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7179 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7180 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7181 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7182 | if (!getDerived().AlwaysRebuild() && |
| 7183 | Cond.get() == E->getCond() && |
| 7184 | LHS.get() == E->getLHS() && |
| 7185 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7186 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7187 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7188 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7189 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7190 | E->getRParenLoc()); |
| 7191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7193 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7194 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7195 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7196 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7197 | } |
| 7198 | |
| 7199 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7200 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7201 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7202 | switch (E->getOperator()) { |
| 7203 | case OO_New: |
| 7204 | case OO_Delete: |
| 7205 | case OO_Array_New: |
| 7206 | case OO_Array_Delete: |
| 7207 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7208 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7209 | case OO_Call: { |
| 7210 | // This is a call to an object's operator(). |
| 7211 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7212 | |
| 7213 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7214 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7215 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7216 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7217 | |
| 7218 | // FIXME: Poor location information |
| 7219 | SourceLocation FakeLParenLoc |
| 7220 | = SemaRef.PP.getLocForEndOfToken( |
| 7221 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 7222 | |
| 7223 | // Transform the call arguments. |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7224 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7225 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7226 | Args)) |
| 7227 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7228 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7229 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7230 | Args, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7231 | E->getLocEnd()); |
| 7232 | } |
| 7233 | |
| 7234 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7235 | case OO_##Name: |
| 7236 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7237 | #include "clang/Basic/OperatorKinds.def" |
| 7238 | case OO_Subscript: |
| 7239 | // Handled below. |
| 7240 | break; |
| 7241 | |
| 7242 | case OO_Conditional: |
| 7243 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7244 | |
| 7245 | case OO_None: |
| 7246 | case NUM_OVERLOADED_OPERATORS: |
| 7247 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7248 | } |
| 7249 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7250 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7251 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7252 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7253 | |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7254 | ExprResult First; |
| 7255 | if (E->getOperator() == OO_Amp) |
| 7256 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7257 | else |
| 7258 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7259 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7260 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7261 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7262 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7263 | if (E->getNumArgs() == 2) { |
| 7264 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7265 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7266 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7268 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7269 | if (!getDerived().AlwaysRebuild() && |
| 7270 | Callee.get() == E->getCallee() && |
| 7271 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7272 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7273 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7274 | |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7275 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7276 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7277 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7278 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7279 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7280 | Callee.get(), |
| 7281 | First.get(), |
| 7282 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7284 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7285 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7286 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7287 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7288 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7290 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7291 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7292 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7293 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7294 | // Transform the callee. |
| 7295 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7296 | if (Callee.isInvalid()) |
| 7297 | return ExprError(); |
| 7298 | |
| 7299 | // Transform exec config. |
| 7300 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7301 | if (EC.isInvalid()) |
| 7302 | return ExprError(); |
| 7303 | |
| 7304 | // Transform arguments. |
| 7305 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7306 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7307 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7308 | &ArgChanged)) |
| 7309 | return ExprError(); |
| 7310 | |
| 7311 | if (!getDerived().AlwaysRebuild() && |
| 7312 | Callee.get() == E->getCallee() && |
| 7313 | !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7314 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7315 | |
| 7316 | // FIXME: Wrong source location information for the '('. |
| 7317 | SourceLocation FakeLParenLoc |
| 7318 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7319 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7320 | Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7321 | E->getRParenLoc(), EC.get()); |
| 7322 | } |
| 7323 | |
| 7324 | template<typename Derived> |
| 7325 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7326 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7327 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7328 | if (!Type) |
| 7329 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7330 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7331 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7332 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7333 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7334 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7335 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7336 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7337 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7338 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7339 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7340 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7341 | E->getStmtClass(), |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7342 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7343 | Type, |
Fariborz Jahanian | f799ae1 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7344 | E->getAngleBrackets().getEnd(), |
| 7345 | // FIXME. this should be '(' location |
| 7346 | E->getAngleBrackets().getEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7347 | SubExpr.get(), |
Abramo Bagnara | 6cf7d7d | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7348 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7350 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7351 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7352 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7353 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7354 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7356 | |
| 7357 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7358 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7359 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7360 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7361 | } |
| 7362 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7363 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7364 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7365 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7366 | CXXReinterpretCastExpr *E) { |
| 7367 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7370 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7371 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7372 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7373 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7374 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7375 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7376 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7377 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7378 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7379 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7380 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7381 | if (!Type) |
| 7382 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7383 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7384 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7385 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7386 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7387 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7388 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7389 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7390 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7391 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7392 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7393 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7394 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | cdd4b78 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 7395 | E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7396 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7397 | E->getRParenLoc()); |
| 7398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7399 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7400 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7401 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7402 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7403 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7404 | TypeSourceInfo *TInfo |
| 7405 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7406 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7407 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7408 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7409 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7410 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7411 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7412 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7413 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7414 | E->getLocStart(), |
| 7415 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7416 | E->getLocEnd()); |
| 7417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7418 | |
Eli Friedman | ef331b7 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7419 | // We don't know whether the subexpression is potentially evaluated until |
| 7420 | // after we perform semantic analysis. We speculatively assume it is |
| 7421 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7422 | // potentially evaluated. |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7423 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7424 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7425 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7426 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7427 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7428 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7429 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7430 | if (!getDerived().AlwaysRebuild() && |
| 7431 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7432 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7433 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7434 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7435 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7436 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7437 | E->getLocEnd()); |
| 7438 | } |
| 7439 | |
| 7440 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7441 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7442 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7443 | if (E->isTypeOperand()) { |
| 7444 | TypeSourceInfo *TInfo |
| 7445 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7446 | if (!TInfo) |
| 7447 | return ExprError(); |
| 7448 | |
| 7449 | if (!getDerived().AlwaysRebuild() && |
| 7450 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7451 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7452 | |
Douglas Gregor | 3c52a21 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7453 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7454 | E->getLocStart(), |
| 7455 | TInfo, |
| 7456 | E->getLocEnd()); |
| 7457 | } |
| 7458 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7459 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7460 | |
| 7461 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7462 | if (SubExpr.isInvalid()) |
| 7463 | return ExprError(); |
| 7464 | |
| 7465 | if (!getDerived().AlwaysRebuild() && |
| 7466 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7467 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7468 | |
| 7469 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7470 | E->getLocStart(), |
| 7471 | SubExpr.get(), |
| 7472 | E->getLocEnd()); |
| 7473 | } |
| 7474 | |
| 7475 | template<typename Derived> |
| 7476 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7477 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7478 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7480 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7481 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7482 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7483 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7484 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7485 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7486 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7488 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7489 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7490 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | cafeb94 | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 7491 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7492 | |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7493 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7494 | // Make sure that we capture 'this'. |
| 7495 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7496 | return SemaRef.Owned(E); |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7497 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7498 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7499 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7501 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7502 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7503 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7504 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7505 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7506 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7507 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7509 | if (!getDerived().AlwaysRebuild() && |
| 7510 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7511 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7512 | |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7513 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7514 | E->isThrownVariableInScope()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7516 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7517 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7518 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7519 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7520 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7521 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7522 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7523 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7524 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7525 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7526 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7527 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7528 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7529 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7530 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7531 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7532 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7533 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7534 | ExprResult |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 7535 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7536 | FieldDecl *Field |
| 7537 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7538 | E->getField())); |
| 7539 | if (!Field) |
| 7540 | return ExprError(); |
| 7541 | |
| 7542 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
| 7543 | return SemaRef.Owned(E); |
| 7544 | |
| 7545 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 7546 | } |
| 7547 | |
| 7548 | template<typename Derived> |
| 7549 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7550 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7551 | CXXScalarValueInitExpr *E) { |
| 7552 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7553 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7554 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7555 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7556 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7557 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7558 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7559 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7560 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7561 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7562 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7565 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7566 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7567 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7568 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7569 | TypeSourceInfo *AllocTypeInfo |
| 7570 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7571 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7572 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7573 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7574 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7575 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7576 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7577 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7578 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7579 | // Transform the placement arguments (if any). |
| 7580 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7581 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7582 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7583 | E->getNumPlacementArgs(), true, |
| 7584 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7585 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7586 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7587 | // Transform the initializer (if any). |
| 7588 | Expr *OldInit = E->getInitializer(); |
| 7589 | ExprResult NewInit; |
| 7590 | if (OldInit) |
| 7591 | NewInit = getDerived().TransformExpr(OldInit); |
| 7592 | if (NewInit.isInvalid()) |
| 7593 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7594 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7595 | // Transform new operator and delete operator. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7596 | FunctionDecl *OperatorNew = 0; |
| 7597 | if (E->getOperatorNew()) { |
| 7598 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7599 | getDerived().TransformDecl(E->getLocStart(), |
| 7600 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7601 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7602 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | FunctionDecl *OperatorDelete = 0; |
| 7606 | if (E->getOperatorDelete()) { |
| 7607 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7608 | getDerived().TransformDecl(E->getLocStart(), |
| 7609 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7610 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7611 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7612 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7613 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7614 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7615 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7616 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7617 | NewInit.get() == OldInit && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7618 | OperatorNew == E->getOperatorNew() && |
| 7619 | OperatorDelete == E->getOperatorDelete() && |
| 7620 | !ArgumentChanged) { |
| 7621 | // Mark any declarations we need as referenced. |
| 7622 | // FIXME: instantiation-specific. |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7623 | if (OperatorNew) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7624 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7625 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7626 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7627 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7628 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7629 | QualType ElementType |
| 7630 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7631 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7632 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7633 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7634 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 2ad63cf | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7635 | } |
| 7636 | } |
| 7637 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7638 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7639 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7641 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7642 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7643 | if (!ArraySize.get()) { |
| 7644 | // If no array size was specified, but the new expression was |
| 7645 | // instantiated with an array type (e.g., "new T" where T is |
| 7646 | // instantiated with "int[4]"), extract the outer bound from the |
| 7647 | // array type as our array size. We do this with constant and |
| 7648 | // dependently-sized array types. |
| 7649 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7650 | if (!ArrayT) { |
| 7651 | // Do nothing |
| 7652 | } else if (const ConstantArrayType *ConsArrayT |
| 7653 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7654 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7655 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7656 | ConsArrayT->getSize(), |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7657 | SemaRef.Context.getSizeType(), |
| 7658 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7659 | AllocType = ConsArrayT->getElementType(); |
| 7660 | } else if (const DependentSizedArrayType *DepArrayT |
| 7661 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7662 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7663 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7664 | AllocType = DepArrayT->getElementType(); |
| 7665 | } |
| 7666 | } |
| 7667 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7669 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7670 | E->isGlobalNew(), |
| 7671 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7672 | PlacementArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7673 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7674 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7675 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7676 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7677 | ArraySize.get(), |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7678 | E->getDirectInitRange(), |
| 7679 | NewInit.take()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7681 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7682 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7683 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7684 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7685 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7686 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7687 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7688 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7689 | // Transform the delete operator, if known. |
| 7690 | FunctionDecl *OperatorDelete = 0; |
| 7691 | if (E->getOperatorDelete()) { |
| 7692 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7693 | getDerived().TransformDecl(E->getLocStart(), |
| 7694 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7695 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7696 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7697 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7699 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7700 | Operand.get() == E->getArgument() && |
| 7701 | OperatorDelete == E->getOperatorDelete()) { |
| 7702 | // Mark any declarations we need as referenced. |
| 7703 | // FIXME: instantiation-specific. |
| 7704 | if (OperatorDelete) |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7705 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7706 | |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7707 | if (!E->getArgument()->isTypeDependent()) { |
| 7708 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7709 | E->getDestroyedType()); |
| 7710 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7711 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7712 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7713 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7714 | } |
| 7715 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7716 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7717 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7718 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7719 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7720 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7721 | E->isGlobalDelete(), |
| 7722 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7723 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7726 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7727 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7728 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7729 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7730 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7731 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7732 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7733 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7734 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7735 | bool MayBePseudoDestructor = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7736 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7737 | E->getOperatorLoc(), |
| 7738 | E->isArrow()? tok::arrow : tok::period, |
| 7739 | ObjectTypePtr, |
| 7740 | MayBePseudoDestructor); |
| 7741 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7742 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7743 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7744 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7745 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7746 | if (QualifierLoc) { |
| 7747 | QualifierLoc |
| 7748 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7749 | if (!QualifierLoc) |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7750 | return ExprError(); |
| 7751 | } |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7752 | CXXScopeSpec SS; |
| 7753 | SS.Adopt(QualifierLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7754 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7755 | PseudoDestructorTypeStorage Destroyed; |
| 7756 | if (E->getDestroyedTypeInfo()) { |
| 7757 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7758 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | b71d821 | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7759 | ObjectType, 0, SS); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7760 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7761 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7762 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7763 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7764 | // We aren't likely to be able to resolve the identifier down to a type |
| 7765 | // now anyway, so just retain the identifier. |
| 7766 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7767 | E->getDestroyedTypeLoc()); |
| 7768 | } else { |
| 7769 | // Look for a destructor known with the given name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7770 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7771 | *E->getDestroyedTypeIdentifier(), |
| 7772 | E->getDestroyedTypeLoc(), |
| 7773 | /*Scope=*/0, |
| 7774 | SS, ObjectTypePtr, |
| 7775 | false); |
| 7776 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7777 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7778 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7779 | Destroyed |
| 7780 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7781 | E->getDestroyedTypeLoc()); |
| 7782 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7783 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7784 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7785 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 303b96f | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 7786 | CXXScopeSpec EmptySS; |
| 7787 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 7788 | E->getScopeTypeInfo(), ObjectType, 0, EmptySS); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7789 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7790 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7791 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7792 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7793 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7794 | E->getOperatorLoc(), |
| 7795 | E->isArrow(), |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7796 | SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7797 | ScopeTypeInfo, |
| 7798 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7799 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7800 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7801 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7802 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7803 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7804 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7805 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7806 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7807 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7808 | Sema::LookupOrdinaryName); |
| 7809 | |
| 7810 | // Transform all the decls. |
| 7811 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7812 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7813 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7814 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7815 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7816 | if (!InstD) { |
| 7817 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7818 | // This can happen because of dependent hiding. |
| 7819 | if (isa<UsingShadowDecl>(*I)) |
| 7820 | continue; |
Serge Pavlov | 1e75a1a | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7821 | else { |
| 7822 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7823 | return ExprError(); |
Serge Pavlov | 1e75a1a | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7824 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7825 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7826 | |
| 7827 | // Expand using declarations. |
| 7828 | if (isa<UsingDecl>(InstD)) { |
| 7829 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7830 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7831 | E = UD->shadow_end(); I != E; ++I) |
| 7832 | R.addDecl(*I); |
| 7833 | continue; |
| 7834 | } |
| 7835 | |
| 7836 | R.addDecl(InstD); |
| 7837 | } |
| 7838 | |
| 7839 | // Resolve a kind, but don't do any further analysis. If it's |
| 7840 | // ambiguous, the callee needs to deal with it. |
| 7841 | R.resolveKind(); |
| 7842 | |
| 7843 | // Rebuild the nested-name qualifier, if present. |
| 7844 | CXXScopeSpec SS; |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7845 | if (Old->getQualifierLoc()) { |
| 7846 | NestedNameSpecifierLoc QualifierLoc |
| 7847 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7848 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7849 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7850 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7851 | SS.Adopt(QualifierLoc); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7852 | } |
| 7853 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7854 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7855 | CXXRecordDecl *NamingClass |
| 7856 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7857 | Old->getNameLoc(), |
| 7858 | Old->getNamingClass())); |
Serge Pavlov | 1e75a1a | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7859 | if (!NamingClass) { |
| 7860 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7861 | return ExprError(); |
Serge Pavlov | 1e75a1a | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7862 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7863 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7864 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7865 | } |
| 7866 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7867 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7868 | |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7869 | // If we have neither explicit template arguments, nor the template keyword, |
| 7870 | // it's a normal declaration name. |
| 7871 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7872 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7873 | |
| 7874 | // If we have template arguments, rebuild them, then rebuild the |
| 7875 | // templateid expression. |
| 7876 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 02e221b | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 7877 | if (Old->hasExplicitTemplateArgs() && |
| 7878 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7879 | Old->getNumTemplateArgs(), |
Serge Pavlov | 1e75a1a | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7880 | TransArgs)) { |
| 7881 | R.clear(); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7882 | return ExprError(); |
Serge Pavlov | 1e75a1a | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7883 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7884 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7885 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 9d9922a | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7886 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7889 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7890 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7891 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7892 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7893 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7894 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7895 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7896 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7897 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7898 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7899 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7900 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7901 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7902 | T, |
| 7903 | E->getLocEnd()); |
| 7904 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7906 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7907 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7908 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7909 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7910 | if (!LhsT) |
| 7911 | return ExprError(); |
| 7912 | |
| 7913 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7914 | if (!RhsT) |
| 7915 | return ExprError(); |
| 7916 | |
| 7917 | if (!getDerived().AlwaysRebuild() && |
| 7918 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7919 | return SemaRef.Owned(E); |
| 7920 | |
| 7921 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7922 | E->getLocStart(), |
| 7923 | LhsT, RhsT, |
| 7924 | E->getLocEnd()); |
| 7925 | } |
| 7926 | |
| 7927 | template<typename Derived> |
| 7928 | ExprResult |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7929 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7930 | bool ArgChanged = false; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7931 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7932 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7933 | TypeSourceInfo *From = E->getArg(I); |
| 7934 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7935 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7936 | TypeLocBuilder TLB; |
| 7937 | TLB.reserve(FromTL.getFullDataSize()); |
| 7938 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7939 | if (To.isNull()) |
| 7940 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7941 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7942 | if (To == From->getType()) |
| 7943 | Args.push_back(From); |
| 7944 | else { |
| 7945 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7946 | ArgChanged = true; |
| 7947 | } |
| 7948 | continue; |
| 7949 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7950 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7951 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7952 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7953 | // We have a pack expansion. Instantiate it. |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7954 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7955 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7956 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7957 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7958 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7959 | // Determine whether the set of unexpanded parameter packs can and should |
| 7960 | // be expanded. |
| 7961 | bool Expand = true; |
| 7962 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 7963 | Optional<unsigned> OrigNumExpansions = |
| 7964 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7965 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7966 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7967 | PatternTL.getSourceRange(), |
| 7968 | Unexpanded, |
| 7969 | Expand, RetainExpansion, |
| 7970 | NumExpansions)) |
| 7971 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7972 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7973 | if (!Expand) { |
| 7974 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7975 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7976 | // expansion. |
| 7977 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7978 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7979 | TypeLocBuilder TLB; |
| 7980 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7981 | |
| 7982 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7983 | if (To.isNull()) |
| 7984 | return ExprError(); |
| 7985 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7986 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7987 | PatternTL.getSourceRange(), |
| 7988 | ExpansionTL.getEllipsisLoc(), |
| 7989 | NumExpansions); |
| 7990 | if (To.isNull()) |
| 7991 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7992 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7993 | PackExpansionTypeLoc ToExpansionTL |
| 7994 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7995 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7996 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7997 | continue; |
| 7998 | } |
| 7999 | |
| 8000 | // Expand the pack expansion by substituting for each argument in the |
| 8001 | // pack(s). |
| 8002 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8003 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 8004 | TypeLocBuilder TLB; |
| 8005 | TLB.reserve(PatternTL.getFullDataSize()); |
| 8006 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8007 | if (To.isNull()) |
| 8008 | return ExprError(); |
| 8009 | |
Eli Friedman | 20cfeca | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 8010 | if (To->containsUnexpandedParameterPack()) { |
| 8011 | To = getDerived().RebuildPackExpansionType(To, |
| 8012 | PatternTL.getSourceRange(), |
| 8013 | ExpansionTL.getEllipsisLoc(), |
| 8014 | NumExpansions); |
| 8015 | if (To.isNull()) |
| 8016 | return ExprError(); |
| 8017 | |
| 8018 | PackExpansionTypeLoc ToExpansionTL |
| 8019 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8020 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8021 | } |
| 8022 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8023 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8024 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8025 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8026 | if (!RetainExpansion) |
| 8027 | continue; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8028 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8029 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 8030 | // forgetting the partially-substituted parameter pack. |
| 8031 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 8032 | |
| 8033 | TypeLocBuilder TLB; |
| 8034 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8035 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8036 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 8037 | if (To.isNull()) |
| 8038 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8039 | |
| 8040 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8041 | PatternTL.getSourceRange(), |
| 8042 | ExpansionTL.getEllipsisLoc(), |
| 8043 | NumExpansions); |
| 8044 | if (To.isNull()) |
| 8045 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8046 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8047 | PackExpansionTypeLoc ToExpansionTL |
| 8048 | = TLB.push<PackExpansionTypeLoc>(To); |
| 8049 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 8050 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 8051 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8052 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 8053 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8054 | return SemaRef.Owned(E); |
| 8055 | |
| 8056 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 8057 | E->getLocStart(), |
| 8058 | Args, |
| 8059 | E->getLocEnd()); |
| 8060 | } |
| 8061 | |
| 8062 | template<typename Derived> |
| 8063 | ExprResult |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8064 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 8065 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 8066 | if (!T) |
| 8067 | return ExprError(); |
| 8068 | |
| 8069 | if (!getDerived().AlwaysRebuild() && |
| 8070 | T == E->getQueriedTypeSourceInfo()) |
| 8071 | return SemaRef.Owned(E); |
| 8072 | |
| 8073 | ExprResult SubExpr; |
| 8074 | { |
| 8075 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8076 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 8077 | if (SubExpr.isInvalid()) |
| 8078 | return ExprError(); |
| 8079 | |
| 8080 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 8081 | return SemaRef.Owned(E); |
| 8082 | } |
| 8083 | |
| 8084 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8085 | E->getLocStart(), |
| 8086 | T, |
| 8087 | SubExpr.get(), |
| 8088 | E->getLocEnd()); |
| 8089 | } |
| 8090 | |
| 8091 | template<typename Derived> |
| 8092 | ExprResult |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8093 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8094 | ExprResult SubExpr; |
| 8095 | { |
| 8096 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8097 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8098 | if (SubExpr.isInvalid()) |
| 8099 | return ExprError(); |
| 8100 | |
| 8101 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 8102 | return SemaRef.Owned(E); |
| 8103 | } |
| 8104 | |
| 8105 | return getDerived().RebuildExpressionTrait( |
| 8106 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8107 | } |
| 8108 | |
| 8109 | template<typename Derived> |
| 8110 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8111 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8112 | DependentScopeDeclRefExpr *E) { |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8113 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); |
| 8114 | } |
| 8115 | |
| 8116 | template<typename Derived> |
| 8117 | ExprResult |
| 8118 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8119 | DependentScopeDeclRefExpr *E, |
| 8120 | bool IsAddressOfOperand) { |
Reid Kleckner | 8690cee | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 8121 | assert(E->getQualifierLoc()); |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8122 | NestedNameSpecifierLoc QualifierLoc |
| 8123 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8124 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8125 | return ExprError(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8126 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8127 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8128 | // TODO: If this is a conversion-function-id, verify that the |
| 8129 | // destination type name (if present) resolves the same way after |
| 8130 | // instantiation as it did in the local scope. |
| 8131 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8132 | DeclarationNameInfo NameInfo |
| 8133 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8134 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8135 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8136 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8137 | if (!E->hasExplicitTemplateArgs()) { |
| 8138 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8139 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8140 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8141 | // if name has not changed, DNLoc has not changed either. |
| 8142 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8143 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8144 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8145 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8146 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8147 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8148 | /*TemplateArgs*/ 0, |
| 8149 | IsAddressOfOperand); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8150 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8151 | |
| 8152 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8153 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8154 | E->getNumTemplateArgs(), |
| 8155 | TransArgs)) |
| 8156 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8157 | |
Douglas Gregor | 00cf3cc | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8158 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8159 | TemplateKWLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8160 | NameInfo, |
Richard Smith | efeeccf | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8161 | &TransArgs, |
| 8162 | IsAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8163 | } |
| 8164 | |
| 8165 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8166 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8167 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8168 | // CXXConstructExprs other than for list-initialization and |
| 8169 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8170 | // a 1-argument construction we just transform that argument. |
Richard Smith | 73ed67c | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8171 | if ((E->getNumArgs() == 1 || |
| 8172 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8173 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8174 | !E->isListInitialization()) |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8175 | return getDerived().TransformExpr(E->getArg(0)); |
| 8176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8177 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8178 | |
| 8179 | QualType T = getDerived().TransformType(E->getType()); |
| 8180 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8181 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8182 | |
| 8183 | CXXConstructorDecl *Constructor |
| 8184 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8185 | getDerived().TransformDecl(E->getLocStart(), |
| 8186 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8187 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8188 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8189 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8190 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8191 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8192 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8193 | &ArgumentChanged)) |
| 8194 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8196 | if (!getDerived().AlwaysRebuild() && |
| 8197 | T == E->getType() && |
| 8198 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8199 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8200 | // Mark the constructor as referenced. |
| 8201 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8202 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8203 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8204 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8205 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8206 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8207 | Constructor, E->isElidable(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8208 | Args, |
Abramo Bagnara | 7cc58b4 | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8209 | E->hadMultipleCandidates(), |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8210 | E->isListInitialization(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8211 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8212 | E->getConstructionKind(), |
Enea Zaffanella | 1245a54 | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 8213 | E->getParenOrBraceRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8216 | /// \brief Transform a C++ temporary-binding expression. |
| 8217 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8218 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8219 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8220 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8221 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8222 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8223 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8225 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8226 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8227 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8228 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8229 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8230 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8231 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8232 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8233 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8234 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8235 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8236 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8237 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8238 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8239 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8240 | CXXTemporaryObjectExpr *E) { |
| 8241 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8242 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8243 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8244 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8245 | CXXConstructorDecl *Constructor |
| 8246 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8247 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8248 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8249 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8250 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8251 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8252 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8253 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8254 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8255 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8256 | &ArgumentChanged)) |
| 8257 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8258 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8259 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8260 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8261 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8262 | !ArgumentChanged) { |
| 8263 | // FIXME: Instantiation-specific |
Eli Friedman | 5f2987c | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8264 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8265 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8266 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8267 | |
Richard Smith | c83c230 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8268 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8269 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8270 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8271 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8272 | E->getLocEnd()); |
| 8273 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8274 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8275 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8276 | ExprResult |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8277 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Faisal Vali | fad9e13 | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8278 | |
Faisal Vali | d78d659 | 2013-11-12 01:40:44 +0000 | [diff] [blame^] | 8279 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8280 | // Transform the template parameters, and add them to the current |
| 8281 | // instantiation scope. The null case is handled correctly. |
| 8282 | LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList( |
| 8283 | E->getTemplateParameterList()); |
| 8284 | |
| 8285 | // Check to see if the TypeSourceInfo of the call operator needs to |
| 8286 | // be transformed, and if so do the transformation in the |
| 8287 | // CurrentInstantiationScope. |
| 8288 | |
| 8289 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 8290 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 8291 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
| 8292 | TypeSourceInfo *NewCallOpTSI = 0; |
| 8293 | |
| 8294 | const bool CallOpWasAlreadyTransformed = |
| 8295 | getDerived().AlreadyTransformed(OldCallOpTSI->getType()); |
| 8296 | |
| 8297 | // Use the Old Call Operator's TypeSourceInfo if it is already transformed. |
| 8298 | if (CallOpWasAlreadyTransformed) |
| 8299 | NewCallOpTSI = OldCallOpTSI; |
| 8300 | else { |
| 8301 | // Transform the TypeSourceInfo of the Original Lambda's Call Operator. |
| 8302 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 8303 | // it introduces a mapping of the original to the newly created |
| 8304 | // transformed parameters. |
| 8305 | |
| 8306 | TypeLocBuilder NewCallOpTLBuilder; |
| 8307 | QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder, |
| 8308 | OldCallOpFPTL, |
| 8309 | 0, 0); |
| 8310 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 8311 | NewCallOpType); |
Faisal Vali | fad9e13 | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8312 | } |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8313 | // Extract the ParmVarDecls from the NewCallOpTSI and add them to |
| 8314 | // the vector below - this will be used to synthesize the |
| 8315 | // NewCallOperator. Additionally, add the parameters of the untransformed |
| 8316 | // lambda call operator to the CurrentInstantiationScope. |
| 8317 | SmallVector<ParmVarDecl *, 4> Params; |
| 8318 | { |
| 8319 | FunctionProtoTypeLoc NewCallOpFPTL = |
| 8320 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>(); |
| 8321 | ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray(); |
| 8322 | const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs(); |
| 8323 | |
| 8324 | for (unsigned I = 0; I < NewNumArgs; ++I) { |
| 8325 | // If this call operator's type does not require transformation, |
| 8326 | // the parameters do not get added to the current instantiation scope, |
| 8327 | // - so ADD them! This allows the following to compile when the enclosing |
| 8328 | // template is specialized and the entire lambda expression has to be |
| 8329 | // transformed. |
| 8330 | // template<class T> void foo(T t) { |
| 8331 | // auto L = [](auto a) { |
| 8332 | // auto M = [](char b) { <-- note: non-generic lambda |
| 8333 | // auto N = [](auto c) { |
| 8334 | // int x = sizeof(a); |
| 8335 | // x = sizeof(b); <-- specifically this line |
| 8336 | // x = sizeof(c); |
| 8337 | // }; |
| 8338 | // }; |
| 8339 | // }; |
| 8340 | // } |
| 8341 | // foo('a') |
| 8342 | if (CallOpWasAlreadyTransformed) |
| 8343 | getDerived().transformedLocalDecl(NewParamDeclArray[I], |
| 8344 | NewParamDeclArray[I]); |
| 8345 | // Add to Params array, so these parameters can be used to create |
| 8346 | // the newly transformed call operator. |
| 8347 | Params.push_back(NewParamDeclArray[I]); |
| 8348 | } |
| 8349 | } |
| 8350 | |
| 8351 | if (!NewCallOpTSI) |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8352 | return ExprError(); |
| 8353 | |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8354 | // Create the local class that will describe the lambda. |
| 8355 | CXXRecordDecl *Class |
| 8356 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8357 | NewCallOpTSI, |
Faisal Vali | bef582b | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 8358 | /*KnownDependent=*/false, |
| 8359 | E->getCaptureDefault()); |
| 8360 | |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8361 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8362 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8363 | // Build the call operator. |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8364 | CXXMethodDecl *NewCallOperator |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8365 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8366 | NewCallOpTSI, |
Douglas Gregor | c6889e7 | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8367 | E->getCallOperator()->getLocEnd(), |
Richard Smith | adb1d4c | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8368 | Params); |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8369 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | f003acd | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 8370 | |
Faisal Vali | a3d311e | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8371 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 8372 | |
| 8373 | return getDerived().TransformLambdaScope(E, NewCallOperator); |
Richard Smith | 612409e | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | template<typename Derived> |
| 8377 | ExprResult |
| 8378 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
| 8379 | CXXMethodDecl *CallOperator) { |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8380 | bool Invalid = false; |
| 8381 | |
| 8382 | // Transform any init-capture expressions before entering the scope of the |
| 8383 | // lambda. |
Robert Wilhelm | e7205c0 | 2013-08-10 12:33:24 +0000 | [diff] [blame] | 8384 | SmallVector<ExprResult, 8> InitCaptureExprs; |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8385 | InitCaptureExprs.resize(E->explicit_capture_end() - |
| 8386 | E->explicit_capture_begin()); |
| 8387 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8388 | CEnd = E->capture_end(); |
| 8389 | C != CEnd; ++C) { |
| 8390 | if (!C->isInitCapture()) |
| 8391 | continue; |
| 8392 | InitCaptureExprs[C - E->capture_begin()] = |
Richard Smith | 04fa7a3 | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8393 | getDerived().TransformInitializer( |
| 8394 | C->getCapturedVar()->getInit(), |
| 8395 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8396 | } |
| 8397 | |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8398 | // Introduce the context of the call operator. |
| 8399 | Sema::ContextRAII SavedContext(getSema(), CallOperator); |
| 8400 | |
Faisal Vali | fad9e13 | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8401 | LambdaScopeInfo *const LSI = getSema().getCurLambda(); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8402 | // Enter the scope of the lambda. |
Faisal Vali | fad9e13 | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8403 | getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8404 | E->getCaptureDefault(), |
James Dennett | f68af64 | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 8405 | E->getCaptureDefaultLoc(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8406 | E->hasExplicitParameters(), |
| 8407 | E->hasExplicitResultType(), |
| 8408 | E->isMutable()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8409 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8410 | // Transform captures. |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8411 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8412 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8413 | CEnd = E->capture_end(); |
| 8414 | C != CEnd; ++C) { |
| 8415 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8416 | // the list of explicit captures. |
| 8417 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8418 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8419 | FinishedExplicitCaptures = true; |
| 8420 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8421 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8422 | // Capturing 'this' is trivial. |
| 8423 | if (C->capturesThis()) { |
| 8424 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8425 | continue; |
| 8426 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8427 | |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8428 | // Rebuild init-captures, including the implied field declaration. |
| 8429 | if (C->isInitCapture()) { |
| 8430 | ExprResult Init = InitCaptureExprs[C - E->capture_begin()]; |
| 8431 | if (Init.isInvalid()) { |
| 8432 | Invalid = true; |
| 8433 | continue; |
| 8434 | } |
Richard Smith | 04fa7a3 | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8435 | VarDecl *OldVD = C->getCapturedVar(); |
| 8436 | VarDecl *NewVD = getSema().checkInitCapture( |
| 8437 | C->getLocation(), OldVD->getType()->isReferenceType(), |
| 8438 | OldVD->getIdentifier(), Init.take()); |
| 8439 | if (!NewVD) |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8440 | Invalid = true; |
| 8441 | else |
Richard Smith | 04fa7a3 | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8442 | getDerived().transformedLocalDecl(OldVD, NewVD); |
| 8443 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8444 | continue; |
| 8445 | } |
| 8446 | |
| 8447 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 8448 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8449 | // Determine the capture kind for Sema. |
| 8450 | Sema::TryCaptureKind Kind |
| 8451 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8452 | : C->getCaptureKind() == LCK_ByCopy |
| 8453 | ? Sema::TryCapture_ExplicitByVal |
| 8454 | : Sema::TryCapture_ExplicitByRef; |
| 8455 | SourceLocation EllipsisLoc; |
| 8456 | if (C->isPackExpansion()) { |
| 8457 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8458 | bool ShouldExpand = false; |
| 8459 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8460 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8461 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8462 | C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8463 | Unexpanded, |
| 8464 | ShouldExpand, RetainExpansion, |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8465 | NumExpansions)) { |
| 8466 | Invalid = true; |
| 8467 | continue; |
| 8468 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8469 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8470 | if (ShouldExpand) { |
| 8471 | // The transform has determined that we should perform an expansion; |
| 8472 | // transform and capture each of the arguments. |
| 8473 | // expansion of the pattern. Do so. |
| 8474 | VarDecl *Pack = C->getCapturedVar(); |
| 8475 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8476 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8477 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8478 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8479 | Pack)); |
| 8480 | if (!CapturedVar) { |
| 8481 | Invalid = true; |
| 8482 | continue; |
| 8483 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8484 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8485 | // Capture the transformed variable. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8486 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8487 | } |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8488 | continue; |
| 8489 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8490 | |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8491 | EllipsisLoc = C->getEllipsisLoc(); |
| 8492 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8493 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8494 | // Transform the captured variable. |
| 8495 | VarDecl *CapturedVar |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8496 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8497 | C->getCapturedVar())); |
| 8498 | if (!CapturedVar) { |
| 8499 | Invalid = true; |
| 8500 | continue; |
| 8501 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8502 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8503 | // Capture the transformed variable. |
Douglas Gregor | 999713e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8504 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8505 | } |
| 8506 | if (!FinishedExplicitCaptures) |
| 8507 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8508 | |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8509 | |
| 8510 | // Enter a new evaluation context to insulate the lambda from any |
| 8511 | // cleanups from the enclosing full-expression. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8512 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8513 | |
| 8514 | if (Invalid) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8515 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | dfca6f5 | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8516 | /*IsInstantiation=*/true); |
| 8517 | return ExprError(); |
| 8518 | } |
| 8519 | |
| 8520 | // Instantiate the body of the lambda expression. |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8521 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8522 | if (Body.isInvalid()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8523 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8524 | /*IsInstantiation=*/true); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8525 | return ExprError(); |
Douglas Gregor | d5387e8 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8526 | } |
Douglas Gregor | ccc1b5e | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8527 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8528 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | f54486a | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8529 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | 01d0801 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8530 | } |
| 8531 | |
| 8532 | template<typename Derived> |
| 8533 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8534 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8535 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8536 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8537 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8538 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8539 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8540 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8541 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8542 | Args.reserve(E->arg_size()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8543 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8544 | &ArgumentChanged)) |
| 8545 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8546 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8547 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8548 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8549 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8550 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8551 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8552 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8553 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8554 | E->getLParenLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8555 | Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8556 | E->getRParenLoc()); |
| 8557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8558 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8559 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8560 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8561 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8562 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8563 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8564 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8565 | Expr *OldBase; |
| 8566 | QualType BaseType; |
| 8567 | QualType ObjectType; |
| 8568 | if (!E->isImplicitAccess()) { |
| 8569 | OldBase = E->getBase(); |
| 8570 | Base = getDerived().TransformExpr(OldBase); |
| 8571 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8572 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8573 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8574 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8575 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8576 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8577 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8578 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8579 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8580 | ObjectTy, |
| 8581 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8582 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8583 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8584 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8585 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8586 | BaseType = ((Expr*) Base.get())->getType(); |
| 8587 | } else { |
| 8588 | OldBase = 0; |
| 8589 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8590 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8592 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8593 | // Transform the first part of the nested-name-specifier that qualifies |
| 8594 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8595 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8596 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8597 | E->getFirstQualifierFoundInScope(), |
| 8598 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8599 | |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8600 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8601 | if (E->getQualifier()) { |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8602 | QualifierLoc |
| 8603 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8604 | ObjectType, |
| 8605 | FirstQualifierInScope); |
| 8606 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8607 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8608 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8609 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8610 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8611 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8612 | // TODO: If this is a conversion-function-id, verify that the |
| 8613 | // destination type name (if present) resolves the same way after |
| 8614 | // instantiation as it did in the local scope. |
| 8615 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8616 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8617 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8618 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8619 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8620 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8621 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8622 | // This is a reference to a member without an explicitly-specified |
| 8623 | // template argument list. Optimize for this common case. |
| 8624 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8625 | Base.get() == OldBase && |
| 8626 | BaseType == E->getBaseType() && |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8627 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8628 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8629 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8630 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8631 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8632 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8633 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8634 | E->isArrow(), |
| 8635 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8636 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8637 | TemplateKWLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8638 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8639 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8640 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8641 | } |
| 8642 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8643 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8644 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8645 | E->getNumTemplateArgs(), |
| 8646 | TransArgs)) |
| 8647 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8648 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8649 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8650 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8651 | E->isArrow(), |
| 8652 | E->getOperatorLoc(), |
Douglas Gregor | 7c3179c | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8653 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8654 | TemplateKWLoc, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8655 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8656 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8657 | &TransArgs); |
| 8658 | } |
| 8659 | |
| 8660 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8661 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8662 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8663 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8664 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8665 | QualType BaseType; |
| 8666 | if (!Old->isImplicitAccess()) { |
| 8667 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8668 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8669 | return ExprError(); |
Richard Smith | 9138b4e | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8670 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8671 | Old->isArrow()); |
| 8672 | if (Base.isInvalid()) |
| 8673 | return ExprError(); |
| 8674 | BaseType = Base.get()->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8675 | } else { |
| 8676 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8677 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8678 | |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8679 | NestedNameSpecifierLoc QualifierLoc; |
| 8680 | if (Old->getQualifierLoc()) { |
| 8681 | QualifierLoc |
| 8682 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8683 | if (!QualifierLoc) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8684 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8685 | } |
| 8686 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8687 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8688 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8689 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8690 | Sema::LookupOrdinaryName); |
| 8691 | |
| 8692 | // Transform all the decls. |
| 8693 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8694 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8695 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8696 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8697 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8698 | if (!InstD) { |
| 8699 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8700 | // This can happen because of dependent hiding. |
| 8701 | if (isa<UsingShadowDecl>(*I)) |
| 8702 | continue; |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8703 | else { |
| 8704 | R.clear(); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8705 | return ExprError(); |
Argyrios Kyrtzidis | 34f52d1 | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8706 | } |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8707 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8708 | |
| 8709 | // Expand using declarations. |
| 8710 | if (isa<UsingDecl>(InstD)) { |
| 8711 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8712 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8713 | E = UD->shadow_end(); I != E; ++I) |
| 8714 | R.addDecl(*I); |
| 8715 | continue; |
| 8716 | } |
| 8717 | |
| 8718 | R.addDecl(InstD); |
| 8719 | } |
| 8720 | |
| 8721 | R.resolveKind(); |
| 8722 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8723 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8724 | if (Old->getNamingClass()) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8725 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8726 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8727 | Old->getMemberLoc(), |
| 8728 | Old->getNamingClass())); |
| 8729 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8730 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8731 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8732 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8733 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8734 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8735 | TemplateArgumentListInfo TransArgs; |
| 8736 | if (Old->hasExplicitTemplateArgs()) { |
| 8737 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8738 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8739 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8740 | Old->getNumTemplateArgs(), |
| 8741 | TransArgs)) |
| 8742 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8743 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8744 | |
| 8745 | // FIXME: to do this check properly, we will need to preserve the |
| 8746 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8747 | // base (and therefore couldn't do the check) and a |
| 8748 | // nested-name-qualifier (and therefore could do the lookup). |
| 8749 | NamedDecl *FirstQualifierInScope = 0; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8750 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8751 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8752 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8753 | Old->getOperatorLoc(), |
| 8754 | Old->isArrow(), |
Douglas Gregor | 4c9be89 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8755 | QualifierLoc, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8756 | TemplateKWLoc, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8757 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8758 | R, |
| 8759 | (Old->hasExplicitTemplateArgs() |
| 8760 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8761 | } |
| 8762 | |
| 8763 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8764 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8765 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Sean Hunt | eea06c6 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8766 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8767 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8768 | if (SubExpr.isInvalid()) |
| 8769 | return ExprError(); |
| 8770 | |
| 8771 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8772 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8773 | |
| 8774 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8775 | } |
| 8776 | |
| 8777 | template<typename Derived> |
| 8778 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8779 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8780 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8781 | if (Pattern.isInvalid()) |
| 8782 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8783 | |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8784 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8785 | return SemaRef.Owned(E); |
| 8786 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8787 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8788 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8789 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8790 | |
| 8791 | template<typename Derived> |
| 8792 | ExprResult |
| 8793 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8794 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8795 | // Note: This is an instantiation-centric view. |
| 8796 | if (!E->isValueDependent()) |
| 8797 | return SemaRef.Owned(E); |
| 8798 | |
| 8799 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8800 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8801 | // so |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8802 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8803 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8804 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8805 | Optional<unsigned> NumExpansions; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8806 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | a71f9d0 | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8807 | Unexpanded, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8808 | ShouldExpand, RetainExpansion, |
| 8809 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8810 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8811 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8812 | if (RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8813 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8814 | |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8815 | NamedDecl *Pack = E->getPack(); |
| 8816 | if (!ShouldExpand) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8817 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8818 | Pack)); |
| 8819 | if (!Pack) |
| 8820 | return ExprError(); |
| 8821 | } |
| 8822 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8823 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8824 | // We now know the length of the parameter pack, so build a new expression |
| 8825 | // that stores that length. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8826 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 8827 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 089e893 | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8828 | NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8829 | } |
| 8830 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8831 | template<typename Derived> |
| 8832 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8833 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8834 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8835 | // Default behavior is to do nothing with this transformation. |
| 8836 | return SemaRef.Owned(E); |
| 8837 | } |
| 8838 | |
| 8839 | template<typename Derived> |
| 8840 | ExprResult |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8841 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8842 | SubstNonTypeTemplateParmExpr *E) { |
| 8843 | // Default behavior is to do nothing with this transformation. |
| 8844 | return SemaRef.Owned(E); |
| 8845 | } |
| 8846 | |
| 8847 | template<typename Derived> |
| 8848 | ExprResult |
Richard Smith | 9a4db03 | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 8849 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 8850 | // Default behavior is to do nothing with this transformation. |
| 8851 | return SemaRef.Owned(E); |
| 8852 | } |
| 8853 | |
| 8854 | template<typename Derived> |
| 8855 | ExprResult |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8856 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8857 | MaterializeTemporaryExpr *E) { |
| 8858 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8859 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8860 | |
Douglas Gregor | 03e8003 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8861 | template<typename Derived> |
| 8862 | ExprResult |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 8863 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 8864 | CXXStdInitializerListExpr *E) { |
| 8865 | return getDerived().TransformExpr(E->getSubExpr()); |
| 8866 | } |
| 8867 | |
| 8868 | template<typename Derived> |
| 8869 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8870 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8871 | return SemaRef.MaybeBindToTemporary(E); |
| 8872 | } |
| 8873 | |
| 8874 | template<typename Derived> |
| 8875 | ExprResult |
| 8876 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | d8b5ca1 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8877 | return SemaRef.Owned(E); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8878 | } |
| 8879 | |
| 8880 | template<typename Derived> |
| 8881 | ExprResult |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8882 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8883 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8884 | if (SubExpr.isInvalid()) |
| 8885 | return ExprError(); |
| 8886 | |
| 8887 | if (!getDerived().AlwaysRebuild() && |
| 8888 | SubExpr.get() == E->getSubExpr()) |
| 8889 | return SemaRef.Owned(E); |
| 8890 | |
| 8891 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8892 | } |
| 8893 | |
| 8894 | template<typename Derived> |
| 8895 | ExprResult |
| 8896 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8897 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8898 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8899 | bool ArgChanged = false; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8900 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8901 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8902 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8903 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8904 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8905 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8906 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8907 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8908 | Elements.data(), |
| 8909 | Elements.size()); |
| 8910 | } |
| 8911 | |
| 8912 | template<typename Derived> |
| 8913 | ExprResult |
| 8914 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8915 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8916 | // Transform each of the elements. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8917 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8918 | bool ArgChanged = false; |
| 8919 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8920 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8921 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8922 | if (OrigElement.isPackExpansion()) { |
| 8923 | // This key/value element is a pack expansion. |
| 8924 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8925 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8926 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8927 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8928 | |
| 8929 | // Determine whether the set of unexpanded parameter packs can |
| 8930 | // and should be expanded. |
| 8931 | bool Expand = true; |
| 8932 | bool RetainExpansion = false; |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8933 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8934 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8935 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8936 | OrigElement.Value->getLocEnd()); |
| 8937 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8938 | PatternRange, |
| 8939 | Unexpanded, |
| 8940 | Expand, RetainExpansion, |
| 8941 | NumExpansions)) |
| 8942 | return ExprError(); |
| 8943 | |
| 8944 | if (!Expand) { |
| 8945 | // The transform has determined that we should perform a simple |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8946 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8947 | // expansion. |
| 8948 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8949 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8950 | if (Key.isInvalid()) |
| 8951 | return ExprError(); |
| 8952 | |
| 8953 | if (Key.get() != OrigElement.Key) |
| 8954 | ArgChanged = true; |
| 8955 | |
| 8956 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8957 | if (Value.isInvalid()) |
| 8958 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8959 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8960 | if (Value.get() != OrigElement.Value) |
| 8961 | ArgChanged = true; |
| 8962 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8963 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8964 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8965 | }; |
| 8966 | Elements.push_back(Expansion); |
| 8967 | continue; |
| 8968 | } |
| 8969 | |
| 8970 | // Record right away that the argument was changed. This needs |
| 8971 | // to happen even if the array expands to nothing. |
| 8972 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8973 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8974 | // The transform has determined that we should perform an elementwise |
| 8975 | // expansion of the pattern. Do so. |
| 8976 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8977 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8978 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8979 | if (Key.isInvalid()) |
| 8980 | return ExprError(); |
| 8981 | |
| 8982 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8983 | if (Value.isInvalid()) |
| 8984 | return ExprError(); |
| 8985 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8986 | ObjCDictionaryElement Element = { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8987 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8988 | }; |
| 8989 | |
| 8990 | // If any unexpanded parameter packs remain, we still have a |
| 8991 | // pack expansion. |
| 8992 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8993 | Value.get()->containsUnexpandedParameterPack()) |
| 8994 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8995 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8996 | Elements.push_back(Element); |
| 8997 | } |
| 8998 | |
| 8999 | // We've finished with this pack expansion. |
| 9000 | continue; |
| 9001 | } |
| 9002 | |
| 9003 | // Transform and check key. |
| 9004 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 9005 | if (Key.isInvalid()) |
| 9006 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9007 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9008 | if (Key.get() != OrigElement.Key) |
| 9009 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9010 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9011 | // Transform and check value. |
| 9012 | ExprResult Value |
| 9013 | = getDerived().TransformExpr(OrigElement.Value); |
| 9014 | if (Value.isInvalid()) |
| 9015 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9016 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9017 | if (Value.get() != OrigElement.Value) |
| 9018 | ArgChanged = true; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9019 | |
| 9020 | ObjCDictionaryElement Element = { |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 9021 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9022 | }; |
| 9023 | Elements.push_back(Element); |
| 9024 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9025 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9026 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 9027 | return SemaRef.MaybeBindToTemporary(E); |
| 9028 | |
| 9029 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 9030 | Elements.data(), |
| 9031 | Elements.size()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9032 | } |
| 9033 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9034 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9035 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9036 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9037 | TypeSourceInfo *EncodedTypeInfo |
| 9038 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 9039 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9040 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9041 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9042 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9043 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9044 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9045 | |
| 9046 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9047 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9048 | E->getRParenLoc()); |
| 9049 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9050 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9051 | template<typename Derived> |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9052 | ExprResult TreeTransform<Derived>:: |
| 9053 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | 93b6457 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 9054 | // This is a kind of implicit conversion, and it needs to get dropped |
| 9055 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 9056 | // do, as well a more specific one: this expression is only valid when |
| 9057 | // it appears *immediately* as an argument expression. |
| 9058 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9059 | } |
| 9060 | |
| 9061 | template<typename Derived> |
| 9062 | ExprResult TreeTransform<Derived>:: |
| 9063 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9064 | TypeSourceInfo *TSInfo |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9065 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9066 | if (!TSInfo) |
| 9067 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9068 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9069 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9070 | if (Result.isInvalid()) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9071 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9072 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9073 | if (!getDerived().AlwaysRebuild() && |
| 9074 | TSInfo == E->getTypeInfoAsWritten() && |
| 9075 | Result.get() == E->getSubExpr()) |
| 9076 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9077 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9078 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9079 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9080 | Result.get()); |
| 9081 | } |
| 9082 | |
| 9083 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9084 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9085 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9086 | // Transform arguments. |
| 9087 | bool ArgChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9088 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9089 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9090 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9091 | &ArgChanged)) |
| 9092 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9093 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9094 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 9095 | // Class message: transform the receiver type. |
| 9096 | TypeSourceInfo *ReceiverTypeInfo |
| 9097 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 9098 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9099 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9100 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9101 | // If nothing changed, just retain the existing message send. |
| 9102 | if (!getDerived().AlwaysRebuild() && |
| 9103 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9104 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9105 | |
| 9106 | // Build a new class message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9107 | SmallVector<SourceLocation, 16> SelLocs; |
| 9108 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9109 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 9110 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9111 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9112 | E->getMethodDecl(), |
| 9113 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9114 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9115 | E->getRightLoc()); |
| 9116 | } |
| 9117 | |
| 9118 | // Instance message: transform the receiver |
| 9119 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 9120 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9121 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9122 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 9123 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9124 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9125 | |
| 9126 | // If nothing changed, just retain the existing message send. |
| 9127 | if (!getDerived().AlwaysRebuild() && |
| 9128 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9129 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9130 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9131 | // Build a new instance message send. |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9132 | SmallVector<SourceLocation, 16> SelLocs; |
| 9133 | E->getSelectorLocs(SelLocs); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9134 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9135 | E->getSelector(), |
Argyrios Kyrtzidis | 2071808 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9136 | SelLocs, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9137 | E->getMethodDecl(), |
| 9138 | E->getLeftLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9139 | Args, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9140 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9141 | } |
| 9142 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9143 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9144 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9145 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9146 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9147 | } |
| 9148 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9149 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9150 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9151 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9152 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9153 | } |
| 9154 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9155 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9156 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9157 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9158 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9159 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9160 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9161 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9162 | |
| 9163 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9164 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9165 | // If nothing changed, just retain the existing expression. |
| 9166 | if (!getDerived().AlwaysRebuild() && |
| 9167 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9168 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9169 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9170 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9171 | E->getLocation(), |
| 9172 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9173 | } |
| 9174 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9175 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9176 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9177 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9178 | // 'super' and types never change. Property never changes. Just |
| 9179 | // retain the existing expression. |
| 9180 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9181 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9182 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9183 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9184 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9185 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9186 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9187 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9188 | // We don't need to transform the property; it will never change. |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9189 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9190 | // If nothing changed, just retain the existing expression. |
| 9191 | if (!getDerived().AlwaysRebuild() && |
| 9192 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9193 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9194 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9195 | if (E->isExplicitProperty()) |
| 9196 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9197 | E->getExplicitProperty(), |
| 9198 | E->getLocation()); |
| 9199 | |
| 9200 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9201 | SemaRef.Context.PseudoObjectTy, |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9202 | E->getImplicitPropertyGetter(), |
| 9203 | E->getImplicitPropertySetter(), |
| 9204 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9205 | } |
| 9206 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9207 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9208 | ExprResult |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9209 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9210 | // Transform the base expression. |
| 9211 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9212 | if (Base.isInvalid()) |
| 9213 | return ExprError(); |
| 9214 | |
| 9215 | // Transform the key expression. |
| 9216 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9217 | if (Key.isInvalid()) |
| 9218 | return ExprError(); |
| 9219 | |
| 9220 | // If nothing changed, just retain the existing expression. |
| 9221 | if (!getDerived().AlwaysRebuild() && |
| 9222 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 9223 | return SemaRef.Owned(E); |
| 9224 | |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9225 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9226 | Base.get(), Key.get(), |
| 9227 | E->getAtIndexMethodDecl(), |
| 9228 | E->setAtIndexMethodDecl()); |
| 9229 | } |
| 9230 | |
| 9231 | template<typename Derived> |
| 9232 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9233 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9234 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9235 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9236 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9237 | return ExprError(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9238 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9239 | // If nothing changed, just retain the existing expression. |
| 9240 | if (!getDerived().AlwaysRebuild() && |
| 9241 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9242 | return SemaRef.Owned(E); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9243 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9244 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | ec8deba | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9245 | E->getOpLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9246 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9247 | } |
| 9248 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9249 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9250 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9251 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9252 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9253 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9254 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9255 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9256 | SubExprs, &ArgumentChanged)) |
| 9257 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9258 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9259 | if (!getDerived().AlwaysRebuild() && |
| 9260 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9261 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9262 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9263 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9264 | SubExprs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9265 | E->getRParenLoc()); |
| 9266 | } |
| 9267 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9268 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9269 | ExprResult |
Hal Finkel | 414a1bd | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9270 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 9271 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 9272 | if (SrcExpr.isInvalid()) |
| 9273 | return ExprError(); |
| 9274 | |
| 9275 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9276 | if (!Type) |
| 9277 | return ExprError(); |
| 9278 | |
| 9279 | if (!getDerived().AlwaysRebuild() && |
| 9280 | Type == E->getTypeSourceInfo() && |
| 9281 | SrcExpr.get() == E->getSrcExpr()) |
| 9282 | return SemaRef.Owned(E); |
| 9283 | |
| 9284 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 9285 | SrcExpr.get(), Type, |
| 9286 | E->getRParenLoc()); |
| 9287 | } |
| 9288 | |
| 9289 | template<typename Derived> |
| 9290 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9291 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9292 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9293 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9294 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 9295 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 9296 | |
| 9297 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 0586520 | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 9298 | blockScope->TheDecl->setBlockMissingReturnType( |
| 9299 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9300 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9301 | SmallVector<ParmVarDecl*, 4> params; |
| 9302 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9303 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 9304 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9305 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 9306 | oldBlock->param_begin(), |
| 9307 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9308 | 0, paramTypes, ¶ms)) { |
| 9309 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | 92be2a5 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9310 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9311 | } |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9312 | |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9313 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9314 | QualType exprResultType = |
| 9315 | getDerived().TransformType(exprFunctionType->getResultType()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 9316 | |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9317 | QualType functionType = |
| 9318 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9319 | exprFunctionType->getExtProtoInfo()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9320 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9321 | |
| 9322 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9323 | if (!params.empty()) |
David Blaikie | 4278c65 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 9324 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9325 | |
| 9326 | if (!oldBlock->blockMissingReturnType()) { |
| 9327 | blockScope->HasImplicitReturnType = false; |
| 9328 | blockScope->ReturnType = exprResultType; |
| 9329 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9330 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9331 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9332 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9333 | if (body.isInvalid()) { |
| 9334 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9335 | return ExprError(); |
Argyrios Kyrtzidis | 00b4657 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9336 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9337 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9338 | #ifndef NDEBUG |
| 9339 | // In builds with assertions, make sure that we captured everything we |
| 9340 | // captured before. |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9341 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 9342 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 9343 | e = oldBlock->capture_end(); i != e; ++i) { |
| 9344 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9345 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9346 | // Ignore parameter packs. |
| 9347 | if (isa<ParmVarDecl>(oldCapture) && |
| 9348 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 9349 | continue; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9350 | |
Douglas Gregor | fc92137 | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9351 | VarDecl *newCapture = |
| 9352 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 9353 | oldCapture)); |
| 9354 | assert(blockScope->CaptureMap.count(newCapture)); |
| 9355 | } |
Douglas Gregor | ec79d87 | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9356 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9357 | } |
| 9358 | #endif |
| 9359 | |
| 9360 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 9361 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9362 | } |
| 9363 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9364 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9365 | ExprResult |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9366 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 9367 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9368 | } |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9369 | |
| 9370 | template<typename Derived> |
| 9371 | ExprResult |
| 9372 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9373 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 9374 | bool ArgumentChanged = false; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9375 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9376 | SubExprs.reserve(E->getNumSubExprs()); |
| 9377 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 9378 | SubExprs, &ArgumentChanged)) |
| 9379 | return ExprError(); |
| 9380 | |
| 9381 | if (!getDerived().AlwaysRebuild() && |
| 9382 | !ArgumentChanged) |
| 9383 | return SemaRef.Owned(E); |
| 9384 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9385 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | dfa64ba | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9386 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9387 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9388 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9389 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9390 | // Type reconstruction |
| 9391 | //===----------------------------------------------------------------------===// |
| 9392 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9393 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9394 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 9395 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9396 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9397 | getDerived().getBaseEntity()); |
| 9398 | } |
| 9399 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9400 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9401 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 9402 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9403 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9404 | getDerived().getBaseEntity()); |
| 9405 | } |
| 9406 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9407 | template<typename Derived> |
| 9408 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9409 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9410 | bool WrittenAsLValue, |
| 9411 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9412 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9413 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9414 | } |
| 9415 | |
| 9416 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9417 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9418 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9419 | QualType ClassType, |
| 9420 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9421 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9422 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9423 | } |
| 9424 | |
| 9425 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9426 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9427 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9428 | ArrayType::ArraySizeModifier SizeMod, |
| 9429 | const llvm::APInt *Size, |
| 9430 | Expr *SizeExpr, |
| 9431 | unsigned IndexTypeQuals, |
| 9432 | SourceRange BracketsRange) { |
| 9433 | if (SizeExpr || !Size) |
| 9434 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9435 | IndexTypeQuals, BracketsRange, |
| 9436 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9437 | |
| 9438 | QualType Types[] = { |
| 9439 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9440 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9441 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9442 | }; |
Craig Topper | b960232 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 9443 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9444 | QualType SizeType; |
| 9445 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9446 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9447 | SizeType = Types[I]; |
| 9448 | break; |
| 9449 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9450 | |
Eli Friedman | 01f276d | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9451 | // Note that we can return a VariableArrayType here in the case where |
| 9452 | // the element type was a dependent VariableArrayType. |
| 9453 | IntegerLiteral *ArraySize |
| 9454 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9455 | /*FIXME*/BracketsRange.getBegin()); |
| 9456 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9457 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9458 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9460 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9461 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9462 | QualType |
| 9463 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9464 | ArrayType::ArraySizeModifier SizeMod, |
| 9465 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9466 | unsigned IndexTypeQuals, |
| 9467 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9468 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9469 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9470 | } |
| 9471 | |
| 9472 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9473 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9474 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9475 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9476 | unsigned IndexTypeQuals, |
| 9477 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9478 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9479 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9481 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9482 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9483 | QualType |
| 9484 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9485 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9486 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9487 | unsigned IndexTypeQuals, |
| 9488 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9489 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9490 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9491 | IndexTypeQuals, BracketsRange); |
| 9492 | } |
| 9493 | |
| 9494 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9495 | QualType |
| 9496 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9497 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9498 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9499 | unsigned IndexTypeQuals, |
| 9500 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9501 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9502 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9503 | IndexTypeQuals, BracketsRange); |
| 9504 | } |
| 9505 | |
| 9506 | template<typename Derived> |
| 9507 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9508 | unsigned NumElements, |
| 9509 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9510 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9511 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9513 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9514 | template<typename Derived> |
| 9515 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 9516 | unsigned NumElements, |
| 9517 | SourceLocation AttributeLoc) { |
| 9518 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9519 | NumElements, true); |
| 9520 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9521 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9522 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9523 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9525 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9526 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9527 | QualType |
| 9528 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9529 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9530 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9531 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9533 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9534 | template<typename Derived> |
Jordan Rose | bea522f | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9535 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 9536 | QualType T, |
| 9537 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9538 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 9539 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9540 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9541 | getDerived().getBaseEntity(), |
Jordan Rose | 0918989 | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9542 | EPI); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9544 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9545 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9546 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9547 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9548 | } |
| 9549 | |
| 9550 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9551 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9552 | assert(D && "no decl found"); |
| 9553 | if (D->isInvalidDecl()) return QualType(); |
| 9554 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9555 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9556 | TypeDecl *Ty; |
| 9557 | if (isa<UsingDecl>(D)) { |
| 9558 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 9559 | assert(Using->hasTypename() && |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9560 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9561 | |
| 9562 | // A valid resolved using typename decl points to exactly one type decl. |
| 9563 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9564 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9565 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9566 | } else { |
| 9567 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9568 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9569 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9570 | } |
| 9571 | |
| 9572 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9573 | } |
| 9574 | |
| 9575 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9576 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9577 | SourceLocation Loc) { |
| 9578 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9579 | } |
| 9580 | |
| 9581 | template<typename Derived> |
| 9582 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9583 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9584 | } |
| 9585 | |
| 9586 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9587 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9588 | SourceLocation Loc) { |
| 9589 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9590 | } |
| 9591 | |
| 9592 | template<typename Derived> |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9593 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9594 | UnaryTransformType::UTTKind UKind, |
| 9595 | SourceLocation Loc) { |
| 9596 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9597 | } |
| 9598 | |
| 9599 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9600 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9601 | TemplateName Template, |
| 9602 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 6771423 | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9603 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9604 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9605 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9606 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9607 | template<typename Derived> |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9608 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9609 | SourceLocation KWLoc) { |
| 9610 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9611 | } |
| 9612 | |
| 9613 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9614 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9615 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9616 | bool TemplateKW, |
| 9617 | TemplateDecl *Template) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9618 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9619 | Template); |
| 9620 | } |
| 9621 | |
| 9622 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9623 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9624 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9625 | const IdentifierInfo &Name, |
| 9626 | SourceLocation NameLoc, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9627 | QualType ObjectType, |
| 9628 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9629 | UnqualifiedId TemplateName; |
| 9630 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9631 | Sema::TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9632 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9633 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9634 | SS, TemplateKWLoc, TemplateName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9635 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9636 | /*EnteringContext=*/false, |
| 9637 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9638 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9641 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9642 | TemplateName |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9643 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9644 | OverloadedOperatorKind Operator, |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9645 | SourceLocation NameLoc, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9646 | QualType ObjectType) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9647 | UnqualifiedId Name; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9648 | // FIXME: Bogus location information. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9649 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | fd4ffeb | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9650 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9651 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9652 | Sema::TemplateTy Template; |
| 9653 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9654 | SS, TemplateKWLoc, Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9655 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9656 | /*EnteringContext=*/false, |
| 9657 | Template); |
Serge Pavlov | 1806239 | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 9658 | return Template.get(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9659 | } |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9660 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9661 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9662 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9663 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9664 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9665 | Expr *OrigCallee, |
| 9666 | Expr *First, |
| 9667 | Expr *Second) { |
| 9668 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9669 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9670 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9671 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9672 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9673 | if (!First->getType()->isOverloadableType() && |
| 9674 | !Second->getType()->isOverloadableType()) |
| 9675 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9676 | Callee->getLocStart(), |
| 9677 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9678 | } else if (Op == OO_Arrow) { |
| 9679 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9680 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9681 | } else if (Second == 0 || isPostIncDec) { |
| 9682 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9683 | // The argument is not of overloadable type, so try to create a |
| 9684 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9685 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9686 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9687 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9688 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9689 | } |
| 9690 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9691 | if (!First->getType()->isOverloadableType() && |
| 9692 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9693 | // Neither of the arguments is an overloadable type, so try to |
| 9694 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9695 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9696 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9697 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9698 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9699 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9700 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9701 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9702 | } |
| 9703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9704 | |
| 9705 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9706 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9707 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9708 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9709 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9710 | assert(ULE->requiresADL()); |
| 9711 | |
| 9712 | // FIXME: Do we have to check |
| 9713 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9714 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9715 | } else { |
Richard Smith | f641166 | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 9716 | // If we've resolved this to a particular non-member function, just call |
| 9717 | // that function. If we resolved it to a member function, |
| 9718 | // CreateOverloaded* will find that function for us. |
| 9719 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 9720 | if (!isa<CXXMethodDecl>(ND)) |
| 9721 | Functions.addDecl(ND); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9722 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9723 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9724 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9725 | Expr *Args[2] = { First, Second }; |
| 9726 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9727 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9728 | // Create the overloaded operator invocation for unary operators. |
| 9729 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9730 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9731 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9732 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9733 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9734 | |
Douglas Gregor | 5b8968c | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9735 | if (Op == OO_Subscript) { |
| 9736 | SourceLocation LBrace; |
| 9737 | SourceLocation RBrace; |
| 9738 | |
| 9739 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9740 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9741 | LBrace = SourceLocation::getFromRawEncoding( |
| 9742 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9743 | RBrace = SourceLocation::getFromRawEncoding( |
| 9744 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9745 | } else { |
| 9746 | LBrace = Callee->getLocStart(); |
| 9747 | RBrace = OpLoc; |
| 9748 | } |
| 9749 | |
| 9750 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9751 | First, Second); |
| 9752 | } |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9754 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9755 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9756 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9757 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9758 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9759 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9760 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9761 | return Result; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9762 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9763 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9764 | template<typename Derived> |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9765 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9766 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9767 | SourceLocation OperatorLoc, |
| 9768 | bool isArrow, |
Douglas Gregor | f3db29f | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9769 | CXXScopeSpec &SS, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9770 | TypeSourceInfo *ScopeType, |
| 9771 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9772 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9773 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9774 | QualType BaseType = Base->getType(); |
| 9775 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9776 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 4a9d795 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9777 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9778 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9779 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9780 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9781 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9782 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9783 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9784 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9785 | /*FIXME?*/true); |
| 9786 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9787 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9788 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9789 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9790 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9791 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9792 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9793 | |
Richard Smith | 6314db9 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9794 | // The scope type is now known to be a valid nested name specifier |
| 9795 | // component. Tack it on to the end of the nested name specifier. |
| 9796 | if (ScopeType) |
| 9797 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9798 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9799 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9800 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9801 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9802 | OperatorLoc, isArrow, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9803 | SS, TemplateKWLoc, |
| 9804 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9805 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9806 | /*TemplateArgs*/ 0); |
| 9807 | } |
| 9808 | |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9809 | template<typename Derived> |
| 9810 | StmtResult |
| 9811 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 9812 | SourceLocation Loc = S->getLocStart(); |
| 9813 | unsigned NumParams = S->getCapturedDecl()->getNumParams(); |
| 9814 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0, |
| 9815 | S->getCapturedRegionKind(), NumParams); |
| 9816 | StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 9817 | |
| 9818 | if (Body.isInvalid()) { |
| 9819 | getSema().ActOnCapturedRegionError(); |
| 9820 | return StmtError(); |
| 9821 | } |
| 9822 | |
| 9823 | return getSema().ActOnCapturedRegionEnd(Body.take()); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9824 | } |
| 9825 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9826 | } // end namespace clang |
| 9827 | |
| 9828 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |