Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 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 | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 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 | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | d6ff332 | 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 | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "TypeLocBuilder.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 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 | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/StmtOpenMP.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Chandler Carruth | 3a02247 | 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 | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/ArrayRef.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 38 | #include <algorithm> |
| 39 | |
| 40 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 41 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 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 | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 72 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 73 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 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 | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 79 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 80 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 94 | template<typename Derived> |
| 95 | class TreeTransform { |
Douglas Gregor | a8bac7f | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 103 | public: |
| 104 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 105 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 106 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 108 | ~ForgetPartiallySubstitutedPackRAII() { |
| 109 | Self.RememberPartiallySubstitutedPack(Old); |
| 110 | } |
| 111 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | protected: |
| 114 | Sema &SemaRef; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | 0c46b2b | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 120 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 123 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | const Derived &getDerived() const { |
| 130 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 131 | } |
| 132 | |
John McCall | dadc575 | 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 | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | d6ff332 | 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 | 2aa81a7 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | d6ff332 | 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 | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 180 | public: |
| 181 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 183 | OldLocation = Self.getDerived().getBaseLocation(); |
| 184 | OldEntity = Self.getDerived().getBaseEntity(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 186 | if (Location.isValid()) |
| 187 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 190 | ~TemporaryBase() { |
| 191 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 192 | } |
| 193 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | |
| 195 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 196 | /// transformed. |
| 197 | /// |
| 198 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 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 | d6ff332 | 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 | d196a58 | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 215 | |
Douglas Gregor | 840bd6c | 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 | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 220 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 229 | /// \param Unexpanded The set of unexpanded parameter packs within the |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 230 | /// pattern. |
| 231 | /// |
Douglas Gregor | 840bd6c | 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 | a8bac7f | 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 | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 241 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 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 | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 248 | /// |
Chad Rosier | 1dcde96 | 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 | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | /// must be set. |
| 253 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 254 | SourceRange PatternRange, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 255 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 256 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 257 | bool &RetainExpansion, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 258 | Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 259 | ShouldExpand = false; |
| 260 | return false; |
| 261 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | a8bac7f | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | a8bac7f | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | f301011 | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transforms the given type into another type. |
| 284 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 285 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 286 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 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 | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 289 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 290 | /// |
| 291 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 292 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
John McCall | 550e0c2 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 296 | /// |
John McCall | 550e0c2 | 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 | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 302 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 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 | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 308 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 310 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 311 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 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 | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 319 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 320 | |
Alexey Bataev | 5ec3eb1 | 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 | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 331 | /// \brief Transform the given expression. |
| 332 | /// |
Douglas Gregor | a16548e | 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 | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 339 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | |
Richard Smith | d59b832 | 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 | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 350 | /// \brief Transform the given list of expressions. |
| 351 | /// |
Chad Rosier | 1dcde96 | 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 | a3efea1 | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 363 | /// function-call arguments, and any arguments that should be dropped, will |
Douglas Gregor | a3efea1 | 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 | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 374 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 375 | bool *ArgChanged = 0); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 376 | |
Douglas Gregor | d6ff332 | 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 | 0c46b2b | 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 | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 382 | /// may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 383 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 0c46b2b | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 388 | |
| 389 | return D; |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 390 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 391 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 392 | /// \brief Transform the attributes associated with the given declaration and |
Douglas Gregor | 0c46b2b | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | 0c46b2b | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 402 | /// Local declarations are typically transformed via a call to |
Douglas Gregor | 0c46b2b | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 409 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 410 | /// \brief Transform the definition of the given declaration. |
| 411 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 413 | /// Subclasses may override this function to provide alternate behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 414 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 415 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | |
Douglas Gregor | a5cb6da | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 421 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 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 | 1dcde96 | 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 | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 429 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 430 | |
Douglas Gregor | 1445480 | 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 | f816bd7 | 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 | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 448 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 449 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 451 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | /// |
Douglas Gregor | 9db5350 | 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 | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 460 | /// \param ObjectType If we're translating a template name within a member |
Douglas Gregor | 9db5350 | 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 | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 473 | SourceLocation NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 474 | QualType ObjectType = QualType(), |
| 475 | NamedDecl *FirstQualifierInScope = 0); |
| 476 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 477 | /// \brief Transform the given template argument. |
| 478 | /// |
Mike Stump | 11289f4 | 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 | e922c77 | 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 | 0ad1666 | 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 | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 488 | /// \brief Transform the given set of template arguments. |
| 489 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 490 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 62e06f2 | 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 | fe921a7 | 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 | 62e06f2 | 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 | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 508 | TemplateArgumentListInfo &Outputs) { |
| 509 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 510 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 511 | |
| 512 | /// \brief Transform the given set of template arguments. |
| 513 | /// |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 514 | /// By default, this operation transforms all of the template arguments |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 515 | /// in the input set using \c TransformTemplateArgument(), and appends |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 516 | /// the transformed arguments to the output list. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 517 | /// |
Douglas Gregor | fe921a7 | 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 | 42cafa8 | 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 | fe921a7 | 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 | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 530 | |
John McCall | 0ad1666 | 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 | bcd0350 | 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 | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 538 | getDerived().getBaseLocation()); |
| 539 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 541 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 542 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 543 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 544 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 545 | |
Douglas Gregor | 3024f07 | 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 | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 551 | StmtResult TransformSEHHandler(Stmt *Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 552 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 553 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 554 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 555 | TemplateSpecializationTypeLoc TL, |
| 556 | TemplateName Template); |
| 557 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 558 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 559 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 560 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 561 | TemplateName Template, |
| 562 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 563 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 564 | QualType |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 565 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 566 | DependentTemplateSpecializationTypeLoc TL, |
| 567 | NestedNameSpecifierLoc QualifierLoc); |
| 568 | |
John McCall | 58f10c3 | 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 | dd47216 | 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 | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 579 | SmallVectorImpl<QualType> &PTypes, |
| 580 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 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 | 8fb0d9d | 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 | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 587 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 588 | int indexAdjustment, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 589 | Optional<unsigned> NumExpansions, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 590 | bool ExpectParameterPack); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 591 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 592 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 593 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 594 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 595 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 596 | |
| 597 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 598 | /// \brief Transform the captures and body of a lambda expression. |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 599 | ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator, |
| 600 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 601 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 602 | TemplateParameterList *TransformTemplateParameterList( |
| 603 | TemplateParameterList *TPL) { |
| 604 | return TPL; |
| 605 | } |
| 606 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 607 | ExprResult TransformAddressOfOperand(Expr *E); |
| 608 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 609 | bool IsAddressOfOperand); |
| 610 | |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 611 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 612 | // amount of stack usage with clang. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 613 | #define STMT(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 614 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 615 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 616 | #define EXPR(Node, Parent) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 617 | LLVM_ATTRIBUTE_NOINLINE \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 618 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 619 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 620 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 622 | #define OPENMP_CLAUSE(Name, Class) \ |
Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 623 | LLVM_ATTRIBUTE_NOINLINE \ |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 624 | OMPClause *Transform ## Class(Class *S); |
| 625 | #include "clang/Basic/OpenMPKinds.def" |
| 626 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 627 | /// \brief Build a new pointer type given its pointee type. |
| 628 | /// |
| 629 | /// By default, performs semantic analysis when building the pointer type. |
| 630 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 631 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 632 | |
| 633 | /// \brief Build a new block pointer type given its pointee type. |
| 634 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 636 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 637 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 638 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 639 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 640 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 641 | /// By default, performs semantic analysis when building the |
| 642 | /// reference type. Subclasses may override this routine to provide |
| 643 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 645 | /// \param LValue whether the type was written with an lvalue sigil |
| 646 | /// or an rvalue sigil. |
| 647 | QualType RebuildReferenceType(QualType ReferentType, |
| 648 | bool LValue, |
| 649 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 651 | /// \brief Build a new member pointer type given the pointee type and the |
| 652 | /// class type it refers into. |
| 653 | /// |
| 654 | /// By default, performs semantic analysis when building the member pointer |
| 655 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 656 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 657 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 659 | /// \brief Build a new array type given the element type, size |
| 660 | /// modifier, size of the array (if known), size expression, and index type |
| 661 | /// qualifiers. |
| 662 | /// |
| 663 | /// By default, performs semantic analysis when building the array type. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 666 | QualType RebuildArrayType(QualType ElementType, |
| 667 | ArrayType::ArraySizeModifier SizeMod, |
| 668 | const llvm::APInt *Size, |
| 669 | Expr *SizeExpr, |
| 670 | unsigned IndexTypeQuals, |
| 671 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 673 | /// \brief Build a new constant array type given the element type, size |
| 674 | /// modifier, (known) size of the array, and index type qualifiers. |
| 675 | /// |
| 676 | /// By default, performs semantic analysis when building the array type. |
| 677 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 678 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 679 | ArrayType::ArraySizeModifier SizeMod, |
| 680 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 681 | unsigned IndexTypeQuals, |
| 682 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 683 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 684 | /// \brief Build a new incomplete array type given the element type, size |
| 685 | /// modifier, and index type qualifiers. |
| 686 | /// |
| 687 | /// By default, performs semantic analysis when building the array type. |
| 688 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 690 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 691 | unsigned IndexTypeQuals, |
| 692 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 693 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | /// size modifier, size expression, and index type qualifiers. |
| 696 | /// |
| 697 | /// By default, performs semantic analysis when building the array type. |
| 698 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 699 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 700 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 701 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 702 | unsigned IndexTypeQuals, |
| 703 | SourceRange BracketsRange); |
| 704 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 706 | /// size modifier, size expression, and index type qualifiers. |
| 707 | /// |
| 708 | /// By default, performs semantic analysis when building the array type. |
| 709 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 711 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 712 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 713 | unsigned IndexTypeQuals, |
| 714 | SourceRange BracketsRange); |
| 715 | |
| 716 | /// \brief Build a new vector type given the element type and |
| 717 | /// number of elements. |
| 718 | /// |
| 719 | /// By default, performs semantic analysis when building the vector type. |
| 720 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 721 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 722 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 724 | /// \brief Build a new extended vector type given the element type and |
| 725 | /// number of elements. |
| 726 | /// |
| 727 | /// By default, performs semantic analysis when building the vector type. |
| 728 | /// Subclasses may override this routine to provide different behavior. |
| 729 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 730 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
| 732 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 733 | /// given the element type and number of elements. |
| 734 | /// |
| 735 | /// By default, performs semantic analysis when building the vector type. |
| 736 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 738 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 739 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 741 | /// \brief Build a new function type. |
| 742 | /// |
| 743 | /// By default, performs semantic analysis when building the function type. |
| 744 | /// Subclasses may override this routine to provide different behavior. |
| 745 | QualType RebuildFunctionProtoType(QualType T, |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 746 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 747 | const FunctionProtoType::ExtProtoInfo &EPI); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 749 | /// \brief Build a new unprototyped function type. |
| 750 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 751 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 752 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 753 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 754 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 755 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 756 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 757 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 758 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 759 | } |
| 760 | |
| 761 | /// \brief Build a new class/struct/union type. |
| 762 | QualType RebuildRecordType(RecordDecl *Record) { |
| 763 | return SemaRef.Context.getTypeDeclType(Record); |
| 764 | } |
| 765 | |
| 766 | /// \brief Build a new Enum type. |
| 767 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 768 | return SemaRef.Context.getTypeDeclType(Enum); |
| 769 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 770 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 772 | /// |
| 773 | /// By default, performs semantic analysis when building the typeof type. |
| 774 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 775 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 776 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 778 | /// |
| 779 | /// By default, builds a new TypeOfType with the given underlying type. |
| 780 | QualType RebuildTypeOfType(QualType Underlying); |
| 781 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 782 | /// \brief Build a new unary transform type. |
| 783 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 784 | UnaryTransformType::UTTKind UKind, |
| 785 | SourceLocation Loc); |
| 786 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 787 | /// \brief Build a new C++11 decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 788 | /// |
| 789 | /// By default, performs semantic analysis when building the decltype type. |
| 790 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 791 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 792 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 793 | /// \brief Build a new C++11 auto type. |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 794 | /// |
| 795 | /// By default, builds a new AutoType with the given deduced type. |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 796 | QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) { |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 797 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 798 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 799 | // that we'll retry deduction after the transformation. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 800 | return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto, |
| 801 | /*IsDependent*/ false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 804 | /// \brief Build a new template specialization type. |
| 805 | /// |
| 806 | /// By default, performs semantic analysis when building the template |
| 807 | /// specialization type. Subclasses may override this routine to provide |
| 808 | /// different behavior. |
| 809 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 810 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 811 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 813 | /// \brief Build a new parenthesized type. |
| 814 | /// |
| 815 | /// By default, builds a new ParenType type from the inner type. |
| 816 | /// Subclasses may override this routine to provide different behavior. |
| 817 | QualType RebuildParenType(QualType InnerType) { |
| 818 | return SemaRef.Context.getParenType(InnerType); |
| 819 | } |
| 820 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 821 | /// \brief Build a new qualified name type. |
| 822 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 823 | /// By default, builds a new ElaboratedType type from the keyword, |
| 824 | /// the nested-name-specifier and the named type. |
| 825 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 826 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 827 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 828 | NestedNameSpecifierLoc QualifierLoc, |
| 829 | QualType Named) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 830 | return SemaRef.Context.getElaboratedType(Keyword, |
| 831 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 832 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 834 | |
| 835 | /// \brief Build a new typename type that refers to a template-id. |
| 836 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 837 | /// By default, builds a new DependentNameType type from the |
| 838 | /// nested-name-specifier and the given type. Subclasses may override |
| 839 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 840 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 841 | ElaboratedTypeKeyword Keyword, |
| 842 | NestedNameSpecifierLoc QualifierLoc, |
| 843 | const IdentifierInfo *Name, |
| 844 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 845 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 846 | // Rebuild the template name. |
| 847 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 848 | CXXScopeSpec SS; |
| 849 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 850 | TemplateName InstName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 851 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 853 | if (InstName.isNull()) |
| 854 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 855 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 856 | // If it's still dependent, make a dependent specialization. |
| 857 | if (InstName.getAsDependentTemplateName()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 858 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 859 | QualifierLoc.getNestedNameSpecifier(), |
| 860 | Name, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 861 | Args); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 862 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 863 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 864 | // specialization. |
| 865 | QualType T = |
| 866 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 867 | if (T.isNull()) return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 868 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 869 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 870 | return T; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 871 | |
| 872 | return SemaRef.Context.getElaboratedType(Keyword, |
| 873 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 874 | T); |
| 875 | } |
| 876 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 877 | /// \brief Build a new typename type that refers to an identifier. |
| 878 | /// |
| 879 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 880 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 881 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 882 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 883 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 884 | NestedNameSpecifierLoc QualifierLoc, |
| 885 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 886 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 887 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 888 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 889 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 890 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 891 | // If the name is still dependent, just build a new dependent name type. |
| 892 | if (!SemaRef.computeDeclContext(SS)) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 893 | return SemaRef.Context.getDependentNameType(Keyword, |
| 894 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 895 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 898 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 899 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 900 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 901 | |
| 902 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 903 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 904 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 905 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 906 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 907 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 908 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 909 | if (!DC) |
| 910 | return QualType(); |
| 911 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 912 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 913 | return QualType(); |
| 914 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 915 | TagDecl *Tag = 0; |
| 916 | SemaRef.LookupQualifiedName(Result, DC); |
| 917 | switch (Result.getResultKind()) { |
| 918 | case LookupResult::NotFound: |
| 919 | case LookupResult::NotFoundInCurrentInstantiation: |
| 920 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 921 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 922 | case LookupResult::Found: |
| 923 | Tag = Result.getAsSingle<TagDecl>(); |
| 924 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 925 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 926 | case LookupResult::FoundOverloaded: |
| 927 | case LookupResult::FoundUnresolvedValue: |
| 928 | llvm_unreachable("Tag lookup cannot find non-tags"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 930 | case LookupResult::Ambiguous: |
| 931 | // Let the LookupResult structure handle ambiguities. |
| 932 | return QualType(); |
| 933 | } |
| 934 | |
| 935 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 936 | // Check where the name exists but isn't a tag type and use that to emit |
| 937 | // better diagnostics. |
| 938 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 939 | SemaRef.LookupQualifiedName(Result, DC); |
| 940 | switch (Result.getResultKind()) { |
| 941 | case LookupResult::Found: |
| 942 | case LookupResult::FoundOverloaded: |
| 943 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 944 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 945 | unsigned Kind = 0; |
| 946 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 947 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 948 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 949 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 950 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 951 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 952 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 953 | default: |
| 954 | // FIXME: Would be nice to highlight just the source range. |
| 955 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 956 | << Kind << Id << DC; |
| 957 | break; |
| 958 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 959 | return QualType(); |
| 960 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 961 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 962 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 963 | IdLoc, *Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 964 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 965 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 966 | return QualType(); |
| 967 | } |
| 968 | |
| 969 | // Build the elaborated-type-specifier type. |
| 970 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 971 | return SemaRef.Context.getElaboratedType(Keyword, |
| 972 | QualifierLoc.getNestedNameSpecifier(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 973 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 974 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 976 | /// \brief Build a new pack expansion type. |
| 977 | /// |
| 978 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 979 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 980 | QualType RebuildPackExpansionType(QualType Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 981 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 982 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 983 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 984 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 985 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 988 | /// \brief Build a new atomic type given its value type. |
| 989 | /// |
| 990 | /// By default, performs semantic analysis when building the atomic type. |
| 991 | /// Subclasses may override this routine to provide different behavior. |
| 992 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 993 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 994 | /// \brief Build a new template name given a nested name specifier, a flag |
| 995 | /// indicating whether the "template" keyword was provided, and the template |
| 996 | /// that the template name refers to. |
| 997 | /// |
| 998 | /// By default, builds the new template name directly. Subclasses may override |
| 999 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1000 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1001 | bool TemplateKW, |
| 1002 | TemplateDecl *Template); |
| 1003 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1004 | /// \brief Build a new template name given a nested name specifier and the |
| 1005 | /// name that is referred to as a template. |
| 1006 | /// |
| 1007 | /// By default, performs semantic analysis to determine whether the name can |
| 1008 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1009 | /// template name. Subclasses may override this routine to provide different |
| 1010 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1011 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1012 | const IdentifierInfo &Name, |
| 1013 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 1014 | QualType ObjectType, |
| 1015 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1016 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1017 | /// \brief Build a new template name given a nested name specifier and the |
| 1018 | /// overloaded operator name that is referred to as a template. |
| 1019 | /// |
| 1020 | /// By default, performs semantic analysis to determine whether the name can |
| 1021 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1022 | /// template name. Subclasses may override this routine to provide different |
| 1023 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1024 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1025 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1026 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1027 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1028 | |
| 1029 | /// \brief Build a new template name given a template template parameter pack |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1030 | /// and the |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1031 | /// |
| 1032 | /// By default, performs semantic analysis to determine whether the name can |
| 1033 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1034 | /// template name. Subclasses may override this routine to provide different |
| 1035 | /// behavior. |
| 1036 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1037 | const TemplateArgument &ArgPack) { |
| 1038 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1039 | } |
| 1040 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1041 | /// \brief Build a new compound statement. |
| 1042 | /// |
| 1043 | /// By default, performs semantic analysis to build the new statement. |
| 1044 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1045 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1046 | MultiStmtArg Statements, |
| 1047 | SourceLocation RBraceLoc, |
| 1048 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1049 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1050 | IsStmtExpr); |
| 1051 | } |
| 1052 | |
| 1053 | /// \brief Build a new case statement. |
| 1054 | /// |
| 1055 | /// By default, performs semantic analysis to build the new statement. |
| 1056 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1057 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1058 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1060 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1061 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1062 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1063 | ColonLoc); |
| 1064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1065 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1066 | /// \brief Attach the body to a new case statement. |
| 1067 | /// |
| 1068 | /// By default, performs semantic analysis to build the new statement. |
| 1069 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1070 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1071 | getSema().ActOnCaseStmtBody(S, Body); |
| 1072 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1074 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1075 | /// \brief Build a new default statement. |
| 1076 | /// |
| 1077 | /// By default, performs semantic analysis to build the new statement. |
| 1078 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1079 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1080 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1081 | Stmt *SubStmt) { |
| 1082 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1083 | /*CurScope=*/0); |
| 1084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1086 | /// \brief Build a new label statement. |
| 1087 | /// |
| 1088 | /// By default, performs semantic analysis to build the new statement. |
| 1089 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1090 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1091 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1092 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1095 | /// \brief Build a new label statement. |
| 1096 | /// |
| 1097 | /// By default, performs semantic analysis to build the new statement. |
| 1098 | /// Subclasses may override this routine to provide different behavior. |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1099 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1100 | ArrayRef<const Attr*> Attrs, |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1101 | Stmt *SubStmt) { |
| 1102 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1103 | } |
| 1104 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1105 | /// \brief Build a new "if" statement. |
| 1106 | /// |
| 1107 | /// By default, performs semantic analysis to build the new statement. |
| 1108 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1109 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1110 | VarDecl *CondVar, Stmt *Then, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1111 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1112 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1115 | /// \brief Start building a new switch statement. |
| 1116 | /// |
| 1117 | /// By default, performs semantic analysis to build the new statement. |
| 1118 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1119 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1120 | Expr *Cond, VarDecl *CondVar) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1121 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1122 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1125 | /// \brief Attach the body to the switch statement. |
| 1126 | /// |
| 1127 | /// By default, performs semantic analysis to build the new statement. |
| 1128 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1129 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1130 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1131 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | /// \brief Build a new while statement. |
| 1135 | /// |
| 1136 | /// By default, performs semantic analysis to build the new statement. |
| 1137 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1138 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1139 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1140 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1143 | /// \brief Build a new do-while statement. |
| 1144 | /// |
| 1145 | /// By default, performs semantic analysis to build the new statement. |
| 1146 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1147 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1148 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1149 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1150 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1151 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /// \brief Build a new for statement. |
| 1155 | /// |
| 1156 | /// By default, performs semantic analysis to build the new statement. |
| 1157 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1158 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1159 | Stmt *Init, Sema::FullExprArg Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1160 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1161 | SourceLocation RParenLoc, Stmt *Body) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1162 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1163 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1164 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1165 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1166 | /// \brief Build a new goto statement. |
| 1167 | /// |
| 1168 | /// By default, performs semantic analysis to build the new statement. |
| 1169 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1170 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1171 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1172 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /// \brief Build a new indirect goto statement. |
| 1176 | /// |
| 1177 | /// By default, performs semantic analysis to build the new statement. |
| 1178 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1179 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1180 | SourceLocation StarLoc, |
| 1181 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1182 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1185 | /// \brief Build a new return statement. |
| 1186 | /// |
| 1187 | /// By default, performs semantic analysis to build the new statement. |
| 1188 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1189 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1190 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1191 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1193 | /// \brief Build a new declaration statement. |
| 1194 | /// |
| 1195 | /// By default, performs semantic analysis to build the new statement. |
| 1196 | /// Subclasses may override this routine to provide different behavior. |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1197 | StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls, |
| 1198 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1199 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1200 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1202 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1203 | /// \brief Build a new inline asm statement. |
| 1204 | /// |
| 1205 | /// By default, performs semantic analysis to build the new statement. |
| 1206 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1207 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1208 | bool IsVolatile, unsigned NumOutputs, |
| 1209 | unsigned NumInputs, IdentifierInfo **Names, |
| 1210 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1211 | Expr *AsmString, MultiExprArg Clobbers, |
| 1212 | SourceLocation RParenLoc) { |
| 1213 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1214 | NumInputs, Names, Constraints, Exprs, |
| 1215 | AsmString, Clobbers, RParenLoc); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1216 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1217 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1218 | /// \brief Build a new MS style inline asm statement. |
| 1219 | /// |
| 1220 | /// By default, performs semantic analysis to build the new statement. |
| 1221 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1222 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1223 | ArrayRef<Token> AsmToks, |
| 1224 | StringRef AsmString, |
| 1225 | unsigned NumOutputs, unsigned NumInputs, |
| 1226 | ArrayRef<StringRef> Constraints, |
| 1227 | ArrayRef<StringRef> Clobbers, |
| 1228 | ArrayRef<Expr*> Exprs, |
| 1229 | SourceLocation EndLoc) { |
| 1230 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1231 | NumOutputs, NumInputs, |
| 1232 | Constraints, Clobbers, Exprs, EndLoc); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1235 | /// \brief Build a new Objective-C \@try statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1236 | /// |
| 1237 | /// By default, performs semantic analysis to build the new statement. |
| 1238 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1239 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1240 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1241 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1242 | Stmt *Finally) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1243 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1244 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1247 | /// \brief Rebuild an Objective-C exception declaration. |
| 1248 | /// |
| 1249 | /// By default, performs semantic analysis to build the new declaration. |
| 1250 | /// Subclasses may override this routine to provide different behavior. |
| 1251 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1252 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1253 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1254 | ExceptionDecl->getInnerLocStart(), |
| 1255 | ExceptionDecl->getLocation(), |
| 1256 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1257 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1258 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1259 | /// \brief Build a new Objective-C \@catch statement. |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1260 | /// |
| 1261 | /// By default, performs semantic analysis to build the new statement. |
| 1262 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1263 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1264 | SourceLocation RParenLoc, |
| 1265 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1266 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1267 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1268 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1269 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1270 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1271 | /// \brief Build a new Objective-C \@finally statement. |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1272 | /// |
| 1273 | /// By default, performs semantic analysis to build the new statement. |
| 1274 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1275 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1276 | Stmt *Body) { |
| 1277 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1278 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1279 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1280 | /// \brief Build a new Objective-C \@throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1281 | /// |
| 1282 | /// By default, performs semantic analysis to build the new statement. |
| 1283 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1284 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1285 | Expr *Operand) { |
| 1286 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1287 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1288 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1289 | /// \brief Build a new OpenMP parallel directive. |
| 1290 | /// |
| 1291 | /// By default, performs semantic analysis to build the new statement. |
| 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1294 | Stmt *AStmt, |
| 1295 | SourceLocation StartLoc, |
| 1296 | SourceLocation EndLoc) { |
| 1297 | return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt, |
| 1298 | StartLoc, EndLoc); |
| 1299 | } |
| 1300 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1301 | /// \brief Build a new OpenMP 'if' clause. |
| 1302 | /// |
| 1303 | /// By default, performs semantic analysis to build the new statement. |
| 1304 | /// Subclasses may override this routine to provide different behavior. |
| 1305 | OMPClause *RebuildOMPIfClause(Expr *Condition, |
| 1306 | SourceLocation StartLoc, |
| 1307 | SourceLocation LParenLoc, |
| 1308 | SourceLocation EndLoc) { |
| 1309 | return getSema().ActOnOpenMPIfClause(Condition, StartLoc, |
| 1310 | LParenLoc, EndLoc); |
| 1311 | } |
| 1312 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1313 | /// \brief Build a new OpenMP 'default' clause. |
| 1314 | /// |
| 1315 | /// By default, performs semantic analysis to build the new statement. |
| 1316 | /// Subclasses may override this routine to provide different behavior. |
| 1317 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1318 | SourceLocation KindKwLoc, |
| 1319 | SourceLocation StartLoc, |
| 1320 | SourceLocation LParenLoc, |
| 1321 | SourceLocation EndLoc) { |
| 1322 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1323 | StartLoc, LParenLoc, EndLoc); |
| 1324 | } |
| 1325 | |
| 1326 | /// \brief Build a new OpenMP 'private' clause. |
| 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new statement. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1331 | SourceLocation StartLoc, |
| 1332 | SourceLocation LParenLoc, |
| 1333 | SourceLocation EndLoc) { |
| 1334 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1335 | EndLoc); |
| 1336 | } |
| 1337 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1338 | /// \brief Build a new OpenMP 'firstprivate' clause. |
| 1339 | /// |
| 1340 | /// By default, performs semantic analysis to build the new statement. |
| 1341 | /// Subclasses may override this routine to provide different behavior. |
| 1342 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1343 | SourceLocation StartLoc, |
| 1344 | SourceLocation LParenLoc, |
| 1345 | SourceLocation EndLoc) { |
| 1346 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1347 | EndLoc); |
| 1348 | } |
| 1349 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1350 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1351 | SourceLocation StartLoc, |
| 1352 | SourceLocation LParenLoc, |
| 1353 | SourceLocation EndLoc) { |
| 1354 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1355 | EndLoc); |
| 1356 | } |
| 1357 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1358 | /// \brief Rebuild the operand to an Objective-C \@synchronized statement. |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1359 | /// |
| 1360 | /// By default, performs semantic analysis to build the new statement. |
| 1361 | /// Subclasses may override this routine to provide different behavior. |
| 1362 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1363 | Expr *object) { |
| 1364 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1365 | } |
| 1366 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1367 | /// \brief Build a new Objective-C \@synchronized statement. |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1368 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1369 | /// By default, performs semantic analysis to build the new statement. |
| 1370 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1371 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1372 | Expr *Object, Stmt *Body) { |
| 1373 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1374 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1375 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 1376 | /// \brief Build a new Objective-C \@autoreleasepool statement. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1377 | /// |
| 1378 | /// By default, performs semantic analysis to build the new statement. |
| 1379 | /// Subclasses may override this routine to provide different behavior. |
| 1380 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1381 | Stmt *Body) { |
| 1382 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1383 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1384 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1385 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1386 | /// |
| 1387 | /// By default, performs semantic analysis to build the new statement. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1389 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1390 | Stmt *Element, |
| 1391 | Expr *Collection, |
| 1392 | SourceLocation RParenLoc, |
| 1393 | Stmt *Body) { |
Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1394 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1395 | Element, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1396 | Collection, |
Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1397 | RParenLoc); |
| 1398 | if (ForEachStmt.isInvalid()) |
| 1399 | return StmtError(); |
| 1400 | |
| 1401 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1402 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1403 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1404 | /// \brief Build a new C++ exception declaration. |
| 1405 | /// |
| 1406 | /// By default, performs semantic analysis to build the new decaration. |
| 1407 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1408 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1409 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1410 | SourceLocation StartLoc, |
| 1411 | SourceLocation IdLoc, |
| 1412 | IdentifierInfo *Id) { |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1413 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1414 | StartLoc, IdLoc, Id); |
| 1415 | if (Var) |
| 1416 | getSema().CurContext->addDecl(Var); |
| 1417 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | /// \brief Build a new C++ catch statement. |
| 1421 | /// |
| 1422 | /// By default, performs semantic analysis to build the new statement. |
| 1423 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1424 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1425 | VarDecl *ExceptionDecl, |
| 1426 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1427 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1428 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1431 | /// \brief Build a new C++ try statement. |
| 1432 | /// |
| 1433 | /// By default, performs semantic analysis to build the new statement. |
| 1434 | /// Subclasses may override this routine to provide different behavior. |
Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 1435 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 1436 | ArrayRef<Stmt *> Handlers) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1437 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1440 | /// \brief Build a new C++0x range-based for statement. |
| 1441 | /// |
| 1442 | /// By default, performs semantic analysis to build the new statement. |
| 1443 | /// Subclasses may override this routine to provide different behavior. |
| 1444 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1445 | SourceLocation ColonLoc, |
| 1446 | Stmt *Range, Stmt *BeginEnd, |
| 1447 | Expr *Cond, Expr *Inc, |
| 1448 | Stmt *LoopVar, |
| 1449 | SourceLocation RParenLoc) { |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1450 | // If we've just learned that the range is actually an Objective-C |
| 1451 | // collection, treat this as an Objective-C fast enumeration loop. |
| 1452 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 1453 | if (RangeStmt->isSingleDecl()) { |
| 1454 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 1455 | if (RangeVar->isInvalidDecl()) |
| 1456 | return StmtError(); |
| 1457 | |
Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 1458 | Expr *RangeExpr = RangeVar->getInit(); |
| 1459 | if (!RangeExpr->isTypeDependent() && |
| 1460 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 1461 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 1462 | RParenLoc); |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1467 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 1468 | Cond, Inc, LoopVar, RParenLoc, |
| 1469 | Sema::BFRK_Rebuild); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1470 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1471 | |
| 1472 | /// \brief Build a new C++0x range-based for statement. |
| 1473 | /// |
| 1474 | /// By default, performs semantic analysis to build the new statement. |
| 1475 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1476 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 1477 | bool IsIfExists, |
| 1478 | NestedNameSpecifierLoc QualifierLoc, |
| 1479 | DeclarationNameInfo NameInfo, |
| 1480 | Stmt *Nested) { |
| 1481 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 1482 | QualifierLoc, NameInfo, Nested); |
| 1483 | } |
| 1484 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1485 | /// \brief Attach body to a C++0x range-based for statement. |
| 1486 | /// |
| 1487 | /// By default, performs semantic analysis to finish the new statement. |
| 1488 | /// Subclasses may override this routine to provide different behavior. |
| 1489 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1490 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1491 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1492 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1493 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| 1494 | Stmt *TryBlock, Stmt *Handler) { |
| 1495 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1498 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1499 | Stmt *Block) { |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1500 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 1503 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 1504 | return getSema().ActOnSEHFinallyBlock(Loc, Block); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | /// \brief Build a new expression that references a declaration. |
| 1508 | /// |
| 1509 | /// By default, performs semantic analysis to build the new expression. |
| 1510 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1511 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1512 | LookupResult &R, |
| 1513 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1514 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | /// \brief Build a new expression that references a declaration. |
| 1519 | /// |
| 1520 | /// By default, performs semantic analysis to build the new expression. |
| 1521 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1522 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1523 | ValueDecl *VD, |
| 1524 | const DeclarationNameInfo &NameInfo, |
| 1525 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1526 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1527 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1528 | |
| 1529 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1530 | |
| 1531 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1532 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1536 | /// By default, performs semantic analysis to build the new expression. |
| 1537 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1538 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1540 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1543 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1544 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1545 | /// By default, performs semantic analysis to build the new expression. |
| 1546 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1547 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1548 | SourceLocation OperatorLoc, |
| 1549 | bool isArrow, |
| 1550 | CXXScopeSpec &SS, |
| 1551 | TypeSourceInfo *ScopeType, |
| 1552 | SourceLocation CCLoc, |
| 1553 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1554 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1555 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1556 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1557 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | /// By default, performs semantic analysis to build the new expression. |
| 1559 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1560 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1561 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1562 | Expr *SubExpr) { |
| 1563 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1565 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1566 | /// \brief Build a new builtin offsetof expression. |
| 1567 | /// |
| 1568 | /// By default, performs semantic analysis to build the new expression. |
| 1569 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1570 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1571 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1572 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1573 | unsigned NumComponents, |
| 1574 | SourceLocation RParenLoc) { |
| 1575 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1576 | NumComponents, RParenLoc); |
| 1577 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1578 | |
| 1579 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1580 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1581 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | /// By default, performs semantic analysis to build the new expression. |
| 1583 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1584 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1585 | SourceLocation OpLoc, |
| 1586 | UnaryExprOrTypeTrait ExprKind, |
| 1587 | SourceRange R) { |
| 1588 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1591 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1592 | /// expression argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | /// By default, performs semantic analysis to build the new expression. |
| 1595 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1596 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1597 | UnaryExprOrTypeTrait ExprKind, |
| 1598 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1599 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1600 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1601 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1602 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1603 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1604 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1605 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1607 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1608 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1609 | /// By default, performs semantic analysis to build the new expression. |
| 1610 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1611 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1613 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | SourceLocation RBracketLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1615 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1616 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | RBracketLoc); |
| 1618 | } |
| 1619 | |
| 1620 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1621 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | /// By default, performs semantic analysis to build the new expression. |
| 1623 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1624 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1626 | SourceLocation RParenLoc, |
| 1627 | Expr *ExecConfig = 0) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1628 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1629 | Args, RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | /// By default, performs semantic analysis to build the new expression. |
| 1635 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1636 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1637 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1638 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1639 | SourceLocation TemplateKWLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1640 | const DeclarationNameInfo &MemberNameInfo, |
| 1641 | ValueDecl *Member, |
| 1642 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1643 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1644 | NamedDecl *FirstQualifierInScope) { |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1645 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 1646 | isArrow); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1647 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1648 | // We have a reference to an unnamed field. This is always the |
| 1649 | // base of an anonymous struct/union member access, i.e. the |
| 1650 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1651 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1652 | assert(Member->getType()->isRecordType() && |
| 1653 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 1655 | BaseResult = |
| 1656 | getSema().PerformObjectMemberConversion(BaseResult.take(), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1657 | QualifierLoc.getNestedNameSpecifier(), |
| 1658 | FoundDecl, Member); |
| 1659 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1660 | return ExprError(); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1661 | Base = BaseResult.take(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1662 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1663 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1664 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1665 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1666 | cast<FieldDecl>(Member)->getType(), |
| 1667 | VK, OK_Ordinary); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1668 | return getSema().Owned(ME); |
| 1669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1671 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1672 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1673 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1674 | Base = BaseResult.take(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1675 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1676 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1677 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1678 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1679 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1680 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1681 | R.resolveKind(); |
| 1682 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1683 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1684 | SS, TemplateKWLoc, |
| 1685 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1686 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | /// By default, performs semantic analysis to build the new expression. |
| 1692 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1693 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1694 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1695 | Expr *LHS, Expr *RHS) { |
| 1696 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1700 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | /// By default, performs semantic analysis to build the new expression. |
| 1702 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1703 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1704 | SourceLocation QuestionLoc, |
| 1705 | Expr *LHS, |
| 1706 | SourceLocation ColonLoc, |
| 1707 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1708 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1709 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | /// By default, performs semantic analysis to build the new expression. |
| 1715 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1716 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1717 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1719 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1720 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1721 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1723 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1724 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | /// By default, performs semantic analysis to build the new expression. |
| 1727 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1728 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1729 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1731 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1732 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1733 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1736 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1738 | /// By default, performs semantic analysis to build the new expression. |
| 1739 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1740 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1741 | SourceLocation OpLoc, |
| 1742 | SourceLocation AccessorLoc, |
| 1743 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1744 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1745 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1746 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1747 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1748 | OpLoc, /*IsArrow*/ false, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1749 | SS, SourceLocation(), |
| 1750 | /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1751 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1752 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1755 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1757 | /// By default, performs semantic analysis to build the new expression. |
| 1758 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1759 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1760 | MultiExprArg Inits, |
| 1761 | SourceLocation RBraceLoc, |
| 1762 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1763 | ExprResult Result |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1764 | = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1765 | if (Result.isInvalid() || ResultTy->isDependentType()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1766 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1767 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1768 | // Patch in the result type we were given, which may have been computed |
| 1769 | // when the initial InitListExpr was built. |
| 1770 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1771 | ILE->setType(ResultTy); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1772 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1775 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1777 | /// By default, performs semantic analysis to build the new expression. |
| 1778 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1779 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1780 | MultiExprArg ArrayExprs, |
| 1781 | SourceLocation EqualOrColonLoc, |
| 1782 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1783 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1784 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1786 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1787 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1788 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1790 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1793 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | /// By default, builds the implicit value initialization without performing |
| 1796 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1797 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1798 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1799 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1800 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1801 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1802 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1804 | /// By default, performs semantic analysis to build the new expression. |
| 1805 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1806 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1807 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1808 | SourceLocation RParenLoc) { |
| 1809 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1810 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1811 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1815 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1816 | /// By default, performs semantic analysis to build the new expression. |
| 1817 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1818 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1819 | MultiExprArg SubExprs, |
| 1820 | SourceLocation RParenLoc) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1821 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1822 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1824 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | /// |
| 1826 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1827 | /// rather than attempting to map the label statement itself. |
| 1828 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1829 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1830 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1831 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1833 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1834 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1836 | /// By default, performs semantic analysis to build the new expression. |
| 1837 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1838 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1839 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1840 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1841 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1844 | /// \brief Build a new __builtin_choose_expr expression. |
| 1845 | /// |
| 1846 | /// By default, performs semantic analysis to build the new expression. |
| 1847 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1848 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1849 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1850 | SourceLocation RParenLoc) { |
| 1851 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1852 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1853 | RParenLoc); |
| 1854 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1856 | /// \brief Build a new generic selection expression. |
| 1857 | /// |
| 1858 | /// By default, performs semantic analysis to build the new expression. |
| 1859 | /// Subclasses may override this routine to provide different behavior. |
| 1860 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1861 | SourceLocation DefaultLoc, |
| 1862 | SourceLocation RParenLoc, |
| 1863 | Expr *ControllingExpr, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1864 | ArrayRef<TypeSourceInfo *> Types, |
| 1865 | ArrayRef<Expr *> Exprs) { |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1866 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 1867 | ControllingExpr, Types, Exprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1870 | /// \brief Build a new overloaded operator call expression. |
| 1871 | /// |
| 1872 | /// By default, performs semantic analysis to build the new expression. |
| 1873 | /// The semantic analysis provides the behavior of template instantiation, |
| 1874 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1876 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1877 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1878 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1879 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1880 | Expr *Callee, |
| 1881 | Expr *First, |
| 1882 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1883 | |
| 1884 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1885 | /// reinterpret_cast. |
| 1886 | /// |
| 1887 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1888 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1889 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1890 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1891 | Stmt::StmtClass Class, |
| 1892 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1893 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1894 | SourceLocation RAngleLoc, |
| 1895 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1896 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1897 | SourceLocation RParenLoc) { |
| 1898 | switch (Class) { |
| 1899 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1900 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1902 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1903 | |
| 1904 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1905 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1906 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1907 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1909 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1910 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1911 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1912 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1913 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1914 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1915 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1916 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1917 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1918 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1920 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1921 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1922 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1923 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1925 | /// \brief Build a new C++ static_cast expression. |
| 1926 | /// |
| 1927 | /// By default, performs semantic analysis to build the new expression. |
| 1928 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1929 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1930 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1931 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1932 | SourceLocation RAngleLoc, |
| 1933 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1934 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1935 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1936 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1937 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1938 | SourceRange(LAngleLoc, RAngleLoc), |
| 1939 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /// \brief Build a new C++ dynamic_cast expression. |
| 1943 | /// |
| 1944 | /// By default, performs semantic analysis to build the new expression. |
| 1945 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1946 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1947 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1948 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | SourceLocation RAngleLoc, |
| 1950 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1951 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1953 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1954 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1955 | SourceRange(LAngleLoc, RAngleLoc), |
| 1956 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1960 | /// |
| 1961 | /// By default, performs semantic analysis to build the new expression. |
| 1962 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1963 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1964 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1965 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1966 | SourceLocation RAngleLoc, |
| 1967 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1968 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1969 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1970 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1971 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1972 | SourceRange(LAngleLoc, RAngleLoc), |
| 1973 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | /// \brief Build a new C++ const_cast expression. |
| 1977 | /// |
| 1978 | /// By default, performs semantic analysis to build the new expression. |
| 1979 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1980 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1981 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1982 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1983 | SourceLocation RAngleLoc, |
| 1984 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1985 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1986 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1987 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1988 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1989 | SourceRange(LAngleLoc, RAngleLoc), |
| 1990 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | /// \brief Build a new C++ functional-style cast expression. |
| 1994 | /// |
| 1995 | /// By default, performs semantic analysis to build the new expression. |
| 1996 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1997 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1998 | SourceLocation LParenLoc, |
| 1999 | Expr *Sub, |
| 2000 | SourceLocation RParenLoc) { |
| 2001 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2002 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2003 | RParenLoc); |
| 2004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2006 | /// \brief Build a new C++ typeid(type) expression. |
| 2007 | /// |
| 2008 | /// By default, performs semantic analysis to build the new expression. |
| 2009 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2010 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2011 | SourceLocation TypeidLoc, |
| 2012 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2013 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2014 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2015 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2019 | /// \brief Build a new C++ typeid(expr) expression. |
| 2020 | /// |
| 2021 | /// By default, performs semantic analysis to build the new expression. |
| 2022 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2023 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2024 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2025 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2026 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2027 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2028 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2031 | /// \brief Build a new C++ __uuidof(type) expression. |
| 2032 | /// |
| 2033 | /// By default, performs semantic analysis to build the new expression. |
| 2034 | /// Subclasses may override this routine to provide different behavior. |
| 2035 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2036 | SourceLocation TypeidLoc, |
| 2037 | TypeSourceInfo *Operand, |
| 2038 | SourceLocation RParenLoc) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2039 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2040 | RParenLoc); |
| 2041 | } |
| 2042 | |
| 2043 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 2044 | /// |
| 2045 | /// By default, performs semantic analysis to build the new expression. |
| 2046 | /// Subclasses may override this routine to provide different behavior. |
| 2047 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2048 | SourceLocation TypeidLoc, |
| 2049 | Expr *Operand, |
| 2050 | SourceLocation RParenLoc) { |
| 2051 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2052 | RParenLoc); |
| 2053 | } |
| 2054 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2055 | /// \brief Build a new C++ "this" expression. |
| 2056 | /// |
| 2057 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2059 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2060 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2061 | QualType ThisType, |
| 2062 | bool isImplicit) { |
Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2063 | getSema().CheckCXXThisCapture(ThisLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2064 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 2065 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 2066 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | /// \brief Build a new C++ throw expression. |
| 2070 | /// |
| 2071 | /// By default, performs semantic analysis to build the new expression. |
| 2072 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2073 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2074 | bool IsThrownVariableInScope) { |
| 2075 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | /// \brief Build a new C++ default-argument expression. |
| 2079 | /// |
| 2080 | /// By default, builds a new default-argument expression, which does not |
| 2081 | /// require any semantic analysis. Subclasses may override this routine to |
| 2082 | /// provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2083 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2084 | ParmVarDecl *Param) { |
| 2085 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 2086 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2089 | /// \brief Build a new C++11 default-initialization expression. |
| 2090 | /// |
| 2091 | /// By default, builds a new default field initialization expression, which |
| 2092 | /// does not require any semantic analysis. Subclasses may override this |
| 2093 | /// routine to provide different behavior. |
| 2094 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2095 | FieldDecl *Field) { |
| 2096 | return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc, |
| 2097 | Field)); |
| 2098 | } |
| 2099 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2100 | /// \brief Build a new C++ zero-initialization expression. |
| 2101 | /// |
| 2102 | /// By default, performs semantic analysis to build the new expression. |
| 2103 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2104 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2105 | SourceLocation LParenLoc, |
| 2106 | SourceLocation RParenLoc) { |
| 2107 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2108 | None, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2109 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2110 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2111 | /// \brief Build a new C++ "new" expression. |
| 2112 | /// |
| 2113 | /// By default, performs semantic analysis to build the new expression. |
| 2114 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2115 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2116 | bool UseGlobal, |
| 2117 | SourceLocation PlacementLParen, |
| 2118 | MultiExprArg PlacementArgs, |
| 2119 | SourceLocation PlacementRParen, |
| 2120 | SourceRange TypeIdParens, |
| 2121 | QualType AllocatedType, |
| 2122 | TypeSourceInfo *AllocatedTypeInfo, |
| 2123 | Expr *ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2124 | SourceRange DirectInitRange, |
| 2125 | Expr *Initializer) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2127 | PlacementLParen, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2128 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2130 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2131 | AllocatedType, |
| 2132 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2133 | ArraySize, |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2134 | DirectInitRange, |
| 2135 | Initializer); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2136 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2137 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2138 | /// \brief Build a new C++ "delete" expression. |
| 2139 | /// |
| 2140 | /// By default, performs semantic analysis to build the new expression. |
| 2141 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2142 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2143 | bool IsGlobalDelete, |
| 2144 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2145 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2146 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2147 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2148 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2149 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2150 | /// \brief Build a new type trait expression. |
| 2151 | /// |
| 2152 | /// By default, performs semantic analysis to build the new expression. |
| 2153 | /// Subclasses may override this routine to provide different behavior. |
| 2154 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2155 | SourceLocation StartLoc, |
| 2156 | ArrayRef<TypeSourceInfo *> Args, |
| 2157 | SourceLocation RParenLoc) { |
| 2158 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2159 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2160 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2161 | /// \brief Build a new array type trait expression. |
| 2162 | /// |
| 2163 | /// By default, performs semantic analysis to build the new expression. |
| 2164 | /// Subclasses may override this routine to provide different behavior. |
| 2165 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2166 | SourceLocation StartLoc, |
| 2167 | TypeSourceInfo *TSInfo, |
| 2168 | Expr *DimExpr, |
| 2169 | SourceLocation RParenLoc) { |
| 2170 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2171 | } |
| 2172 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2173 | /// \brief Build a new expression trait expression. |
| 2174 | /// |
| 2175 | /// By default, performs semantic analysis to build the new expression. |
| 2176 | /// Subclasses may override this routine to provide different behavior. |
| 2177 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2178 | SourceLocation StartLoc, |
| 2179 | Expr *Queried, |
| 2180 | SourceLocation RParenLoc) { |
| 2181 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2182 | } |
| 2183 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2184 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2185 | /// expression. |
| 2186 | /// |
| 2187 | /// By default, performs semantic analysis to build the new expression. |
| 2188 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2189 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2190 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2191 | SourceLocation TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2192 | const DeclarationNameInfo &NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2193 | const TemplateArgumentListInfo *TemplateArgs, |
| 2194 | bool IsAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2195 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2196 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2197 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2198 | if (TemplateArgs || TemplateKWLoc.isValid()) |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2199 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2200 | NameInfo, TemplateArgs); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2201 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2202 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo, |
| 2203 | IsAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /// \brief Build a new template-id expression. |
| 2207 | /// |
| 2208 | /// By default, performs semantic analysis to build the new expression. |
| 2209 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2210 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2211 | SourceLocation TemplateKWLoc, |
| 2212 | LookupResult &R, |
| 2213 | bool RequiresADL, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2214 | const TemplateArgumentListInfo *TemplateArgs) { |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2215 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2216 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | /// \brief Build a new object-construction expression. |
| 2220 | /// |
| 2221 | /// By default, performs semantic analysis to build the new expression. |
| 2222 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2223 | ExprResult RebuildCXXConstructExpr(QualType T, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2224 | SourceLocation Loc, |
| 2225 | CXXConstructorDecl *Constructor, |
| 2226 | bool IsElidable, |
| 2227 | MultiExprArg Args, |
| 2228 | bool HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2229 | bool ListInitialization, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2230 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2231 | CXXConstructExpr::ConstructionKind ConstructKind, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2232 | SourceRange ParenRange) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2233 | SmallVector<Expr*, 8> ConvertedArgs; |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2234 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2235 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2236 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2238 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2239 | ConvertedArgs, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2240 | HadMultipleCandidates, |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2241 | ListInitialization, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2242 | RequiresZeroInit, ConstructKind, |
| 2243 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | /// \brief Build a new object-construction expression. |
| 2247 | /// |
| 2248 | /// By default, performs semantic analysis to build the new expression. |
| 2249 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2250 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2251 | SourceLocation LParenLoc, |
| 2252 | MultiExprArg Args, |
| 2253 | SourceLocation RParenLoc) { |
| 2254 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2255 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2256 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2257 | RParenLoc); |
| 2258 | } |
| 2259 | |
| 2260 | /// \brief Build a new object-construction expression. |
| 2261 | /// |
| 2262 | /// By default, performs semantic analysis to build the new expression. |
| 2263 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2264 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2265 | SourceLocation LParenLoc, |
| 2266 | MultiExprArg Args, |
| 2267 | SourceLocation RParenLoc) { |
| 2268 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2269 | LParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2270 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2271 | RParenLoc); |
| 2272 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2273 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2274 | /// \brief Build a new member reference expression. |
| 2275 | /// |
| 2276 | /// By default, performs semantic analysis to build the new expression. |
| 2277 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2278 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2279 | QualType BaseType, |
| 2280 | bool IsArrow, |
| 2281 | SourceLocation OperatorLoc, |
| 2282 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2283 | SourceLocation TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2284 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2285 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2286 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2287 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2288 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2289 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2290 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2291 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2292 | SS, TemplateKWLoc, |
| 2293 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2294 | MemberNameInfo, |
| 2295 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2298 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2299 | /// |
| 2300 | /// By default, performs semantic analysis to build the new expression. |
| 2301 | /// Subclasses may override this routine to provide different behavior. |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2302 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2303 | SourceLocation OperatorLoc, |
| 2304 | bool IsArrow, |
| 2305 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2306 | SourceLocation TemplateKWLoc, |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2307 | NamedDecl *FirstQualifierInScope, |
| 2308 | LookupResult &R, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2309 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2310 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2311 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2312 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2313 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2314 | OperatorLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2315 | SS, TemplateKWLoc, |
| 2316 | FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2317 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2318 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2319 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2320 | /// \brief Build a new noexcept expression. |
| 2321 | /// |
| 2322 | /// By default, performs semantic analysis to build the new expression. |
| 2323 | /// Subclasses may override this routine to provide different behavior. |
| 2324 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2325 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2326 | } |
| 2327 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2328 | /// \brief Build a new expression to compute the length of a parameter pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2329 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2330 | SourceLocation PackLoc, |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2331 | SourceLocation RParenLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2332 | Optional<unsigned> Length) { |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2333 | if (Length) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2334 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2335 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2336 | RParenLoc, *Length); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2337 | |
| 2338 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2339 | OperatorLoc, Pack, PackLoc, |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 2340 | RParenLoc); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2341 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2342 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2343 | /// \brief Build a new Objective-C boxed expression. |
| 2344 | /// |
| 2345 | /// By default, performs semantic analysis to build the new expression. |
| 2346 | /// Subclasses may override this routine to provide different behavior. |
| 2347 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2348 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2349 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2350 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2351 | /// \brief Build a new Objective-C array literal. |
| 2352 | /// |
| 2353 | /// By default, performs semantic analysis to build the new expression. |
| 2354 | /// Subclasses may override this routine to provide different behavior. |
| 2355 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2356 | Expr **Elements, unsigned NumElements) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2357 | return getSema().BuildObjCArrayLiteral(Range, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2358 | MultiExprArg(Elements, NumElements)); |
| 2359 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2360 | |
| 2361 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2362 | Expr *Base, Expr *Key, |
| 2363 | ObjCMethodDecl *getterMethod, |
| 2364 | ObjCMethodDecl *setterMethod) { |
| 2365 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2366 | getterMethod, setterMethod); |
| 2367 | } |
| 2368 | |
| 2369 | /// \brief Build a new Objective-C dictionary literal. |
| 2370 | /// |
| 2371 | /// By default, performs semantic analysis to build the new expression. |
| 2372 | /// Subclasses may override this routine to provide different behavior. |
| 2373 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 2374 | ObjCDictionaryElement *Elements, |
| 2375 | unsigned NumElements) { |
| 2376 | return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); |
| 2377 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2378 | |
James Dennett | 2a4d13c | 2012-06-15 07:13:21 +0000 | [diff] [blame] | 2379 | /// \brief Build a new Objective-C \@encode expression. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2380 | /// |
| 2381 | /// By default, performs semantic analysis to build the new expression. |
| 2382 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2383 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2384 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2385 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2386 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2387 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2388 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2389 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2390 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2391 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2392 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2393 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2394 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2395 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2396 | MultiExprArg Args, |
| 2397 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2398 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2399 | ReceiverTypeInfo->getType(), |
| 2400 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2401 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2402 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2406 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2407 | Selector Sel, |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2408 | ArrayRef<SourceLocation> SelectorLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2409 | ObjCMethodDecl *Method, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2410 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2411 | MultiExprArg Args, |
| 2412 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2413 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2414 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2415 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2416 | Sel, Method, LBracLoc, SelectorLocs, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2417 | RBracLoc, Args); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2420 | /// \brief Build a new Objective-C ivar reference expression. |
| 2421 | /// |
| 2422 | /// By default, performs semantic analysis to build the new expression. |
| 2423 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2424 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2425 | SourceLocation IvarLoc, |
| 2426 | bool IsArrow, bool IsFreeIvar) { |
| 2427 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2428 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2429 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2430 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2431 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2432 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2433 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2434 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2435 | false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2436 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2437 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2438 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2439 | if (Result.get()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2440 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2441 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2442 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2443 | /*FIXME:*/IvarLoc, IsArrow, |
| 2444 | SS, SourceLocation(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2445 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2446 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2447 | /*TemplateArgs=*/0); |
| 2448 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2449 | |
| 2450 | /// \brief Build a new Objective-C property reference expression. |
| 2451 | /// |
| 2452 | /// By default, performs semantic analysis to build the new expression. |
| 2453 | /// Subclasses may override this routine to provide different behavior. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2454 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 2455 | ObjCPropertyDecl *Property, |
| 2456 | SourceLocation PropertyLoc) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2457 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2458 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2459 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2460 | Sema::LookupMemberName); |
| 2461 | bool IsArrow = false; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2462 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2463 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2464 | SS, 0, false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2465 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2466 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2467 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2468 | if (Result.get()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2469 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2470 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2471 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2472 | /*FIXME:*/PropertyLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2473 | SS, SourceLocation(), |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2474 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2475 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2476 | /*TemplateArgs=*/0); |
| 2477 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2478 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2479 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2480 | /// |
| 2481 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2482 | /// Subclasses may override this routine to provide different behavior. |
| 2483 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2484 | ObjCMethodDecl *Getter, |
| 2485 | ObjCMethodDecl *Setter, |
| 2486 | SourceLocation PropertyLoc) { |
| 2487 | // Since these expressions can only be value-dependent, we do not |
| 2488 | // need to perform semantic analysis again. |
| 2489 | return Owned( |
| 2490 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2491 | VK_LValue, OK_ObjCProperty, |
| 2492 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2495 | /// \brief Build a new Objective-C "isa" expression. |
| 2496 | /// |
| 2497 | /// By default, performs semantic analysis to build the new expression. |
| 2498 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2499 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2500 | SourceLocation OpLoc, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2501 | bool IsArrow) { |
| 2502 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2503 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2504 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2505 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2506 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2507 | OpLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2508 | SS, 0, false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2509 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2510 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2511 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2512 | if (Result.get()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2513 | return Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2514 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2515 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 2516 | OpLoc, IsArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2517 | SS, SourceLocation(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2518 | /*FirstQualifierInScope=*/0, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2519 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2520 | /*TemplateArgs=*/0); |
| 2521 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2522 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2523 | /// \brief Build a new shuffle vector expression. |
| 2524 | /// |
| 2525 | /// By default, performs semantic analysis to build the new expression. |
| 2526 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2527 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2528 | MultiExprArg SubExprs, |
| 2529 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2530 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2532 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2533 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2534 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2535 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2536 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2537 | // Build a reference to the __builtin_shufflevector builtin |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 2538 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 2539 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 2540 | SemaRef.Context.BuiltinFnTy, |
| 2541 | VK_RValue, BuiltinLoc); |
| 2542 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 2543 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 2544 | CK_BuiltinFnToFnPtr).take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2545 | |
| 2546 | // Build the CallExpr |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2547 | ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr( |
| 2548 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
| 2549 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2550 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2551 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2552 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2553 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2554 | |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 2555 | /// \brief Build a new convert vector expression. |
| 2556 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 2557 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 2558 | SourceLocation RParenLoc) { |
| 2559 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 2560 | BuiltinLoc, RParenLoc); |
| 2561 | } |
| 2562 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2563 | /// \brief Build a new template argument pack expansion. |
| 2564 | /// |
| 2565 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2566 | /// for a template argument. Subclasses may override this routine to provide |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2567 | /// different behavior. |
| 2568 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2569 | SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2570 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2571 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2572 | case TemplateArgument::Expression: { |
| 2573 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2574 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2575 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2576 | if (Result.isInvalid()) |
| 2577 | return TemplateArgumentLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2578 | |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2579 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2580 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2582 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2583 | return TemplateArgumentLoc(TemplateArgument( |
| 2584 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2585 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2586 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2587 | Pattern.getTemplateNameLoc(), |
| 2588 | EllipsisLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2589 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2590 | case TemplateArgument::Null: |
| 2591 | case TemplateArgument::Integral: |
| 2592 | case TemplateArgument::Declaration: |
| 2593 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2594 | case TemplateArgument::TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 2595 | case TemplateArgument::NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2596 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2597 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2598 | case TemplateArgument::Type: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2599 | if (TypeSourceInfo *Expansion |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2600 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2601 | EllipsisLoc, |
| 2602 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2603 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2604 | Expansion); |
| 2605 | break; |
| 2606 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2607 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2608 | return TemplateArgumentLoc(); |
| 2609 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2610 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2611 | /// \brief Build a new expression pack expansion. |
| 2612 | /// |
| 2613 | /// By default, performs semantic analysis to build a new pack expansion |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2614 | /// for an expression. Subclasses may override this routine to provide |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2615 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2616 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2617 | Optional<unsigned> NumExpansions) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2618 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2619 | } |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2620 | |
| 2621 | /// \brief Build a new atomic operation expression. |
| 2622 | /// |
| 2623 | /// By default, performs semantic analysis to build the new expression. |
| 2624 | /// Subclasses may override this routine to provide different behavior. |
| 2625 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 2626 | MultiExprArg SubExprs, |
| 2627 | QualType RetTy, |
| 2628 | AtomicExpr::AtomicOp Op, |
| 2629 | SourceLocation RParenLoc) { |
| 2630 | // Just create the expression; there is not any interesting semantic |
| 2631 | // analysis here because we can't actually build an AtomicExpr until |
| 2632 | // we are sure it is semantically sound. |
Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 2633 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 2634 | RParenLoc); |
| 2635 | } |
| 2636 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2637 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2638 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2639 | QualType ObjectType, |
| 2640 | NamedDecl *FirstQualifierInScope, |
| 2641 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2642 | |
| 2643 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2644 | QualType ObjectType, |
| 2645 | NamedDecl *FirstQualifierInScope, |
| 2646 | CXXScopeSpec &SS); |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 2647 | |
| 2648 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 2649 | NamedDecl *FirstQualifierInScope, |
| 2650 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2651 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2652 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2653 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2654 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2655 | if (!S) |
| 2656 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2657 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2658 | switch (S->getStmtClass()) { |
| 2659 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2660 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2661 | // Transform individual statement nodes |
| 2662 | #define STMT(Node, Parent) \ |
| 2663 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2664 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2665 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2666 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2667 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2668 | // Transform expressions by calling TransformExpr. |
| 2669 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2670 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2671 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2672 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2673 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2674 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2675 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2676 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2677 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2678 | return getSema().ActOnExprStmt(E); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2679 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2682 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2683 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2684 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2685 | template<typename Derived> |
| 2686 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 2687 | if (!S) |
| 2688 | return S; |
| 2689 | |
| 2690 | switch (S->getClauseKind()) { |
| 2691 | default: break; |
| 2692 | // Transform individual clause nodes |
| 2693 | #define OPENMP_CLAUSE(Name, Class) \ |
| 2694 | case OMPC_ ## Name : \ |
| 2695 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 2696 | #include "clang/Basic/OpenMPKinds.def" |
| 2697 | } |
| 2698 | |
| 2699 | return S; |
| 2700 | } |
| 2701 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2703 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2704 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2705 | if (!E) |
| 2706 | return SemaRef.Owned(E); |
| 2707 | |
| 2708 | switch (E->getStmtClass()) { |
| 2709 | case Stmt::NoStmtClass: break; |
| 2710 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2711 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2712 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2713 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2714 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2717 | return SemaRef.Owned(E); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | template<typename Derived> |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2721 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 2722 | bool CXXDirectInit) { |
| 2723 | // Initializers are instantiated like expressions, except that various outer |
| 2724 | // layers are stripped. |
| 2725 | if (!Init) |
| 2726 | return SemaRef.Owned(Init); |
| 2727 | |
| 2728 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 2729 | Init = ExprTemp->getSubExpr(); |
| 2730 | |
Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 2731 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 2732 | Init = MTE->GetTemporaryExpr(); |
| 2733 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2734 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 2735 | Init = Binder->getSubExpr(); |
| 2736 | |
| 2737 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 2738 | Init = ICE->getSubExprAsWritten(); |
| 2739 | |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 2740 | if (CXXStdInitializerListExpr *ILE = |
| 2741 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 2742 | return TransformInitializer(ILE->getSubExpr(), CXXDirectInit); |
| 2743 | |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2744 | // If this is not a direct-initializer, we only need to reconstruct |
| 2745 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 2746 | // the initializer is already the right type. |
| 2747 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 2748 | if (!CXXDirectInit && !(Construct && Construct->isListInitialization())) |
| 2749 | return getDerived().TransformExpr(Init); |
| 2750 | |
| 2751 | // Revert value-initialization back to empty parens. |
| 2752 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 2753 | SourceRange Parens = VIE->getSourceRange(); |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2754 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2755 | Parens.getEnd()); |
| 2756 | } |
| 2757 | |
| 2758 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 2759 | if (isa<ImplicitValueInitExpr>(Init)) |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 2760 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 2761 | SourceLocation()); |
| 2762 | |
| 2763 | // Revert initialization by constructor back to a parenthesized or braced list |
| 2764 | // of expressions. Any other form of initializer can just be reused directly. |
| 2765 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2766 | return getDerived().TransformExpr(Init); |
| 2767 | |
| 2768 | SmallVector<Expr*, 8> NewArgs; |
| 2769 | bool ArgChanged = false; |
| 2770 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 2771 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 2772 | return ExprError(); |
| 2773 | |
| 2774 | // If this was list initialization, revert to list form. |
| 2775 | if (Construct->isListInitialization()) |
| 2776 | return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, |
| 2777 | Construct->getLocEnd(), |
| 2778 | Construct->getType()); |
| 2779 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2780 | // Build a ParenListExpr to represent anything else. |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 2781 | SourceRange Parens = Construct->getParenOrBraceRange(); |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2782 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 2783 | Parens.getEnd()); |
| 2784 | } |
| 2785 | |
| 2786 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2787 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2788 | unsigned NumInputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2789 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2790 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2791 | bool *ArgChanged) { |
| 2792 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2793 | // If requested, drop call arguments that need to be dropped. |
| 2794 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2795 | if (ArgChanged) |
| 2796 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2797 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2798 | break; |
| 2799 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2800 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2801 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2802 | Expr *Pattern = Expansion->getPattern(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2803 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2804 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2805 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2806 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2808 | // Determine whether the set of unexpanded parameter packs can and should |
| 2809 | // be expanded. |
| 2810 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2811 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 2812 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 2813 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2814 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2815 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2816 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2817 | Expand, RetainExpansion, |
| 2818 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2819 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2820 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2821 | if (!Expand) { |
| 2822 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2823 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2824 | // expansion. |
| 2825 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2826 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2827 | if (OutPattern.isInvalid()) |
| 2828 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2829 | |
| 2830 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2831 | Expansion->getEllipsisLoc(), |
| 2832 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2833 | if (Out.isInvalid()) |
| 2834 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2835 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2836 | if (ArgChanged) |
| 2837 | *ArgChanged = true; |
| 2838 | Outputs.push_back(Out.get()); |
| 2839 | continue; |
| 2840 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2841 | |
| 2842 | // Record right away that the argument was changed. This needs |
| 2843 | // to happen even if the array expands to nothing. |
| 2844 | if (ArgChanged) *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2845 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2846 | // The transform has determined that we should perform an elementwise |
| 2847 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2848 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2849 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2850 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2851 | if (Out.isInvalid()) |
| 2852 | return true; |
| 2853 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2854 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2855 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2856 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2857 | if (Out.isInvalid()) |
| 2858 | return true; |
| 2859 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2860 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2861 | Outputs.push_back(Out.get()); |
| 2862 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2863 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2864 | continue; |
| 2865 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2866 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2867 | ExprResult Result = |
| 2868 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 2869 | : getDerived().TransformExpr(Inputs[I]); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2870 | if (Result.isInvalid()) |
| 2871 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2872 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2873 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2874 | *ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2875 | |
| 2876 | Outputs.push_back(Result.get()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2877 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2878 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2879 | return false; |
| 2880 | } |
| 2881 | |
| 2882 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2883 | NestedNameSpecifierLoc |
| 2884 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2885 | NestedNameSpecifierLoc NNS, |
| 2886 | QualType ObjectType, |
| 2887 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2888 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2889 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2890 | Qualifier = Qualifier.getPrefix()) |
| 2891 | Qualifiers.push_back(Qualifier); |
| 2892 | |
| 2893 | CXXScopeSpec SS; |
| 2894 | while (!Qualifiers.empty()) { |
| 2895 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2896 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2897 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2898 | switch (QNNS->getKind()) { |
| 2899 | case NestedNameSpecifier::Identifier: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2900 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2901 | *QNNS->getAsIdentifier(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2902 | Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2903 | Q.getLocalEndLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2904 | ObjectType, false, SS, |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2905 | FirstQualifierInScope, false)) |
| 2906 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2907 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2908 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2909 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2910 | case NestedNameSpecifier::Namespace: { |
| 2911 | NamespaceDecl *NS |
| 2912 | = cast_or_null<NamespaceDecl>( |
| 2913 | getDerived().TransformDecl( |
| 2914 | Q.getLocalBeginLoc(), |
| 2915 | QNNS->getAsNamespace())); |
| 2916 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2917 | break; |
| 2918 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2919 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2920 | case NestedNameSpecifier::NamespaceAlias: { |
| 2921 | NamespaceAliasDecl *Alias |
| 2922 | = cast_or_null<NamespaceAliasDecl>( |
| 2923 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2924 | QNNS->getAsNamespaceAlias())); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2925 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2926 | Q.getLocalEndLoc()); |
| 2927 | break; |
| 2928 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2929 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2930 | case NestedNameSpecifier::Global: |
| 2931 | // There is no meaningful transformation that one could perform on the |
| 2932 | // global scope. |
| 2933 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2934 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2935 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2936 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2937 | case NestedNameSpecifier::TypeSpec: { |
| 2938 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2939 | FirstQualifierInScope, SS); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2940 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2941 | if (!TL) |
| 2942 | return NestedNameSpecifierLoc(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2943 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2944 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2945 | (SemaRef.getLangOpts().CPlusPlus11 && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2946 | TL.getType()->isEnumeralType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2947 | assert(!TL.getType().hasLocalQualifiers() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2948 | "Can't get cv-qualifiers here"); |
Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 2949 | if (TL.getType()->isEnumeralType()) |
| 2950 | SemaRef.Diag(TL.getBeginLoc(), |
| 2951 | diag::warn_cxx98_compat_enum_nested_name_spec); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2952 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2953 | Q.getLocalEndLoc()); |
| 2954 | break; |
| 2955 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2956 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2957 | // error because a previous error should have already been emitted. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 2958 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 2959 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2960 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2961 | << TL.getType() << SS.getRange(); |
| 2962 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2963 | return NestedNameSpecifierLoc(); |
| 2964 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2965 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2966 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2967 | // The qualifier-in-scope and object type only apply to the leftmost entity. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2968 | FirstQualifierInScope = 0; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2969 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2970 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2971 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2972 | // Don't rebuild the nested-name-specifier if we don't have to. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2973 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2974 | !getDerived().AlwaysRebuild()) |
| 2975 | return NNS; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2976 | |
| 2977 | // If we can re-use the source-location data from the original |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2978 | // nested-name-specifier, do so. |
| 2979 | if (SS.location_size() == NNS.getDataLength() && |
| 2980 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2981 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2982 | |
| 2983 | // Allocate new nested-name-specifier location information. |
| 2984 | return SS.getWithLocInContext(SemaRef.Context); |
| 2985 | } |
| 2986 | |
| 2987 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2988 | DeclarationNameInfo |
| 2989 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2990 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2991 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2992 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2993 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2994 | |
| 2995 | switch (Name.getNameKind()) { |
| 2996 | case DeclarationName::Identifier: |
| 2997 | case DeclarationName::ObjCZeroArgSelector: |
| 2998 | case DeclarationName::ObjCOneArgSelector: |
| 2999 | case DeclarationName::ObjCMultiArgSelector: |
| 3000 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3001 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3002 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3003 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3005 | case DeclarationName::CXXConstructorName: |
| 3006 | case DeclarationName::CXXDestructorName: |
| 3007 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3008 | TypeSourceInfo *NewTInfo; |
| 3009 | CanQualType NewCanTy; |
| 3010 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3011 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3012 | if (!NewTInfo) |
| 3013 | return DeclarationNameInfo(); |
| 3014 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3015 | } |
| 3016 | else { |
| 3017 | NewTInfo = 0; |
| 3018 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3019 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3020 | if (NewT.isNull()) |
| 3021 | return DeclarationNameInfo(); |
| 3022 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3025 | DeclarationName NewName |
| 3026 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3027 | NewCanTy); |
| 3028 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3029 | NewNameInfo.setName(NewName); |
| 3030 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3031 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3032 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3035 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3040 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3041 | TemplateName Name, |
| 3042 | SourceLocation NameLoc, |
| 3043 | QualType ObjectType, |
| 3044 | NamedDecl *FirstQualifierInScope) { |
| 3045 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3046 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3047 | assert(Template && "qualified template name must refer to a template"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3048 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3049 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3050 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3051 | Template)); |
| 3052 | if (!TransTemplate) |
| 3053 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3054 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3055 | if (!getDerived().AlwaysRebuild() && |
| 3056 | SS.getScopeRep() == QTN->getQualifier() && |
| 3057 | TransTemplate == Template) |
| 3058 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3059 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3060 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3061 | TransTemplate); |
| 3062 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3063 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3064 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3065 | if (SS.getScopeRep()) { |
| 3066 | // These apply to the scope specifier, not the template. |
| 3067 | ObjectType = QualType(); |
| 3068 | FirstQualifierInScope = 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3071 | if (!getDerived().AlwaysRebuild() && |
| 3072 | SS.getScopeRep() == DTN->getQualifier() && |
| 3073 | ObjectType.isNull()) |
| 3074 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3075 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3076 | if (DTN->isIdentifier()) { |
| 3077 | return getDerived().RebuildTemplateName(SS, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3078 | *DTN->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3079 | NameLoc, |
| 3080 | ObjectType, |
| 3081 | FirstQualifierInScope); |
| 3082 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3084 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 3085 | ObjectType); |
| 3086 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3088 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3089 | TemplateDecl *TransTemplate |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3090 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3091 | Template)); |
| 3092 | if (!TransTemplate) |
| 3093 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3094 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3095 | if (!getDerived().AlwaysRebuild() && |
| 3096 | TransTemplate == Template) |
| 3097 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3099 | return TemplateName(TransTemplate); |
| 3100 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3101 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3102 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3103 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3104 | TemplateTemplateParmDecl *TransParam |
| 3105 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3106 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3107 | if (!TransParam) |
| 3108 | return TemplateName(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3109 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3110 | if (!getDerived().AlwaysRebuild() && |
| 3111 | TransParam == SubstPack->getParameterPack()) |
| 3112 | return Name; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3113 | |
| 3114 | return getDerived().RebuildTemplateName(TransParam, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3115 | SubstPack->getArgumentPack()); |
| 3116 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3117 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3118 | // These should be getting filtered out before they reach the AST. |
| 3119 | llvm_unreachable("overloaded function decl survived to here"); |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3123 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3124 | const TemplateArgument &Arg, |
| 3125 | TemplateArgumentLoc &Output) { |
| 3126 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3127 | switch (Arg.getKind()) { |
| 3128 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3129 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3130 | break; |
| 3131 | |
| 3132 | case TemplateArgument::Type: |
| 3133 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3134 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3135 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3136 | break; |
| 3137 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3138 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3139 | case TemplateArgument::TemplateExpansion: { |
| 3140 | NestedNameSpecifierLocBuilder Builder; |
| 3141 | TemplateName Template = Arg.getAsTemplate(); |
| 3142 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3143 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3144 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3145 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3146 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3147 | if (Arg.getKind() == TemplateArgument::Template) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3148 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3149 | Builder.getWithLocInContext(SemaRef.Context), |
| 3150 | Loc); |
| 3151 | else |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3152 | Output = TemplateArgumentLoc(Arg, |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3153 | Builder.getWithLocInContext(SemaRef.Context), |
| 3154 | Loc, Loc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3155 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3156 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3157 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3158 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3159 | case TemplateArgument::Expression: |
| 3160 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3161 | break; |
| 3162 | |
| 3163 | case TemplateArgument::Declaration: |
| 3164 | case TemplateArgument::Integral: |
| 3165 | case TemplateArgument::Pack: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3166 | case TemplateArgument::NullPtr: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3167 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3168 | break; |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | template<typename Derived> |
| 3173 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3174 | const TemplateArgumentLoc &Input, |
| 3175 | TemplateArgumentLoc &Output) { |
| 3176 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3177 | switch (Arg.getKind()) { |
| 3178 | case TemplateArgument::Null: |
| 3179 | case TemplateArgument::Integral: |
Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3180 | case TemplateArgument::Pack: |
| 3181 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3182 | case TemplateArgument::NullPtr: |
| 3183 | llvm_unreachable("Unexpected TemplateArgument"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3184 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3185 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3186 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3187 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3188 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3189 | |
| 3190 | DI = getDerived().TransformType(DI); |
| 3191 | if (!DI) return true; |
| 3192 | |
| 3193 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3194 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3197 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3198 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3199 | if (QualifierLoc) { |
| 3200 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3201 | if (!QualifierLoc) |
| 3202 | return true; |
| 3203 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3205 | CXXScopeSpec SS; |
| 3206 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3207 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3208 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3209 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3210 | if (Template.isNull()) |
| 3211 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3212 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3213 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3214 | Input.getTemplateNameLoc()); |
| 3215 | return false; |
| 3216 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3217 | |
| 3218 | case TemplateArgument::TemplateExpansion: |
| 3219 | llvm_unreachable("Caller should expand pack expansions"); |
| 3220 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3221 | case TemplateArgument::Expression: { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3222 | // Template argument expressions are constant expressions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3223 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3224 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3226 | Expr *InputExpr = Input.getSourceExpression(); |
| 3227 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3228 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3229 | ExprResult E = getDerived().TransformExpr(InputExpr); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3230 | E = SemaRef.ActOnConstantExpression(E); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3231 | if (E.isInvalid()) return true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3232 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3233 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3234 | } |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3235 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3236 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3237 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3238 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3241 | /// \brief Iterator adaptor that invents template argument location information |
| 3242 | /// for each of the template arguments in its underlying iterator. |
| 3243 | template<typename Derived, typename InputIterator> |
| 3244 | class TemplateArgumentLocInventIterator { |
| 3245 | TreeTransform<Derived> &Self; |
| 3246 | InputIterator Iter; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3247 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3248 | public: |
| 3249 | typedef TemplateArgumentLoc value_type; |
| 3250 | typedef TemplateArgumentLoc reference; |
| 3251 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3252 | difference_type; |
| 3253 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3255 | class pointer { |
| 3256 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3257 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3258 | public: |
| 3259 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3261 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3262 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3263 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3264 | TemplateArgumentLocInventIterator() { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3265 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3266 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3267 | InputIterator Iter) |
| 3268 | : Self(Self), Iter(Iter) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3269 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3270 | TemplateArgumentLocInventIterator &operator++() { |
| 3271 | ++Iter; |
| 3272 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3273 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3274 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3275 | TemplateArgumentLocInventIterator operator++(int) { |
| 3276 | TemplateArgumentLocInventIterator Old(*this); |
| 3277 | ++(*this); |
| 3278 | return Old; |
| 3279 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3281 | reference operator*() const { |
| 3282 | TemplateArgumentLoc Result; |
| 3283 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3284 | return Result; |
| 3285 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3286 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3287 | pointer operator->() const { return pointer(**this); } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3288 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3289 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3290 | const TemplateArgumentLocInventIterator &Y) { |
| 3291 | return X.Iter == Y.Iter; |
| 3292 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3293 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3294 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3295 | const TemplateArgumentLocInventIterator &Y) { |
| 3296 | return X.Iter != Y.Iter; |
| 3297 | } |
| 3298 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3300 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3301 | template<typename InputIterator> |
| 3302 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3303 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3304 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3305 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3306 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3307 | TemplateArgumentLoc In = *First; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3308 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3309 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3310 | // Unpack argument packs, which we translate them into separate |
| 3311 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3312 | // FIXME: We could do much better if we could guarantee that the |
| 3313 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3314 | // all of the template arguments in the argument pack. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3315 | typedef TemplateArgumentLocInventIterator<Derived, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3316 | TemplateArgument::pack_iterator> |
| 3317 | PackLocIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3318 | if (TransformTemplateArguments(PackLocIterator(*this, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3319 | In.getArgument().pack_begin()), |
| 3320 | PackLocIterator(*this, |
| 3321 | In.getArgument().pack_end()), |
| 3322 | Outputs)) |
| 3323 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3324 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3325 | continue; |
| 3326 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3327 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3328 | if (In.getArgument().isPackExpansion()) { |
| 3329 | // We have a pack expansion, for which we will be substituting into |
| 3330 | // the pattern. |
| 3331 | SourceLocation Ellipsis; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3332 | Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3333 | TemplateArgumentLoc Pattern |
Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 3334 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 3335 | In, Ellipsis, OrigNumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3336 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3337 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3338 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3339 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3340 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3341 | // Determine whether the set of unexpanded parameter packs can and should |
| 3342 | // be expanded. |
| 3343 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3344 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3345 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3346 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3347 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3348 | Unexpanded, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3349 | Expand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3350 | RetainExpansion, |
| 3351 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3352 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3353 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3354 | if (!Expand) { |
| 3355 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3356 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3357 | // expansion. |
| 3358 | TemplateArgumentLoc OutPattern; |
| 3359 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3360 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3361 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3363 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3364 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3365 | if (Out.getArgument().isNull()) |
| 3366 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3368 | Outputs.addArgument(Out); |
| 3369 | continue; |
| 3370 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3371 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3372 | // The transform has determined that we should perform an elementwise |
| 3373 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3374 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3375 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3376 | |
| 3377 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3378 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3379 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3380 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3381 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3382 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3383 | if (Out.getArgument().isNull()) |
| 3384 | return true; |
| 3385 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3387 | Outputs.addArgument(Out); |
| 3388 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3389 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3390 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3391 | // forgetting the partially-substituted parameter pack. |
| 3392 | if (RetainExpansion) { |
| 3393 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3394 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3395 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3396 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3397 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3398 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3399 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3400 | if (Out.getArgument().isNull()) |
| 3401 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3402 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3403 | Outputs.addArgument(Out); |
| 3404 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3405 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3406 | continue; |
| 3407 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3408 | |
| 3409 | // The simple case: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3410 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3411 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3412 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3413 | Outputs.addArgument(Out); |
| 3414 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3415 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3416 | return false; |
| 3417 | |
| 3418 | } |
| 3419 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3420 | //===----------------------------------------------------------------------===// |
| 3421 | // Type transformation |
| 3422 | //===----------------------------------------------------------------------===// |
| 3423 | |
| 3424 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3425 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3426 | if (getDerived().AlreadyTransformed(T)) |
| 3427 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3429 | // Temporary workaround. All of these transformations should |
| 3430 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3431 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3432 | getDerived().getBaseLocation()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3433 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3434 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3435 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3436 | if (!NewDI) |
| 3437 | return QualType(); |
| 3438 | |
| 3439 | return NewDI->getType(); |
| 3440 | } |
| 3441 | |
| 3442 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3443 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3444 | // Refine the base location to the type's location. |
| 3445 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 3446 | getDerived().getBaseEntity()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3447 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3448 | return DI; |
| 3449 | |
| 3450 | TypeLocBuilder TLB; |
| 3451 | |
| 3452 | TypeLoc TL = DI->getTypeLoc(); |
| 3453 | TLB.reserve(TL.getFullDataSize()); |
| 3454 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3455 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3456 | if (Result.isNull()) |
| 3457 | return 0; |
| 3458 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3459 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | template<typename Derived> |
| 3463 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3464 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3465 | switch (T.getTypeLocClass()) { |
| 3466 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3467 | #define TYPELOC(CLASS, PARENT) \ |
| 3468 | case TypeLoc::CLASS: \ |
| 3469 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 3470 | T.castAs<CLASS##TypeLoc>()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3471 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3472 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3474 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3478 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3479 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3480 | /// types). This is the right thing for template instantiation, but |
| 3481 | /// probably not for other clients. |
| 3482 | template<typename Derived> |
| 3483 | QualType |
| 3484 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3485 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3486 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3487 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3488 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3489 | if (Result.isNull()) |
| 3490 | return QualType(); |
| 3491 | |
| 3492 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3493 | // FIXME: this is the right thing for template instantiation, but |
| 3494 | // probably not for other clients. |
| 3495 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3496 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3497 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3498 | // Suppress Objective-C lifetime qualifiers if they don't make sense for the |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3499 | // resulting type. |
| 3500 | if (Quals.hasObjCLifetime()) { |
| 3501 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3502 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3503 | else if (Result.getObjCLifetime()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3504 | // Objective-C ARC: |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3505 | // A lifetime qualifier applied to a substituted template parameter |
| 3506 | // overrides the lifetime qualifier from the template argument. |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3507 | const AutoType *AutoTy; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3508 | if (const SubstTemplateTypeParmType *SubstTypeParam |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3509 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3510 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3511 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3512 | Qs.removeObjCLifetime(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3513 | Replacement |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3514 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3515 | Qs); |
| 3516 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3517 | SubstTypeParam->getReplacedParameter(), |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3518 | Replacement); |
| 3519 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3520 | } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) { |
| 3521 | // 'auto' types behave the same way as template parameters. |
| 3522 | QualType Deduced = AutoTy->getDeducedType(); |
| 3523 | Qualifiers Qs = Deduced.getQualifiers(); |
| 3524 | Qs.removeObjCLifetime(); |
| 3525 | Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), |
| 3526 | Qs); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 3527 | Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(), |
| 3528 | AutoTy->isDependentType()); |
Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 3529 | TLB.TypeWasModifiedSafely(Result); |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3530 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3531 | // Otherwise, complain about the addition of a qualifier to an |
| 3532 | // already-qualified type. |
Eli Friedman | 7152fbe | 2013-06-07 20:31:48 +0000 | [diff] [blame] | 3533 | SourceRange R = T.getUnqualifiedLoc().getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3534 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3535 | << Result << R; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3537 | Quals.removeObjCLifetime(); |
| 3538 | } |
| 3539 | } |
| 3540 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3541 | if (!Quals.empty()) { |
| 3542 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
Richard Smith | deec074 | 2013-03-27 23:36:39 +0000 | [diff] [blame] | 3543 | // BuildQualifiedType might not add qualifiers if they are invalid. |
| 3544 | if (Result.hasLocalQualifiers()) |
| 3545 | TLB.push<QualifiedTypeLoc>(Result); |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3546 | // No location information to preserve. |
| 3547 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3548 | |
| 3549 | return Result; |
| 3550 | } |
| 3551 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3552 | template<typename Derived> |
| 3553 | TypeLoc |
| 3554 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3555 | QualType ObjectType, |
| 3556 | NamedDecl *UnqualLookup, |
| 3557 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3558 | if (getDerived().AlreadyTransformed(TL.getType())) |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3559 | return TL; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3560 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3561 | TypeSourceInfo *TSI = |
| 3562 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 3563 | if (TSI) |
| 3564 | return TSI->getTypeLoc(); |
| 3565 | return TypeLoc(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3568 | template<typename Derived> |
| 3569 | TypeSourceInfo * |
| 3570 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3571 | QualType ObjectType, |
| 3572 | NamedDecl *UnqualLookup, |
| 3573 | CXXScopeSpec &SS) { |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3574 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3575 | return TSInfo; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3576 | |
Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3577 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 3578 | UnqualLookup, SS); |
| 3579 | } |
| 3580 | |
| 3581 | template <typename Derived> |
| 3582 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 3583 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 3584 | CXXScopeSpec &SS) { |
| 3585 | QualType T = TL.getType(); |
| 3586 | assert(!getDerived().AlreadyTransformed(T)); |
| 3587 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3588 | TypeLocBuilder TLB; |
| 3589 | QualType Result; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3590 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3591 | if (isa<TemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3592 | TemplateSpecializationTypeLoc SpecTL = |
| 3593 | TL.castAs<TemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3594 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3595 | TemplateName Template |
| 3596 | = getDerived().TransformTemplateName(SS, |
| 3597 | SpecTL.getTypePtr()->getTemplateName(), |
| 3598 | SpecTL.getTemplateNameLoc(), |
| 3599 | ObjectType, UnqualLookup); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3600 | if (Template.isNull()) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3601 | return 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3602 | |
| 3603 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3604 | Template); |
| 3605 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3606 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 3607 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3608 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3609 | TemplateName Template |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3610 | = getDerived().RebuildTemplateName(SS, |
| 3611 | *SpecTL.getTypePtr()->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 3612 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3613 | ObjectType, UnqualLookup); |
| 3614 | if (Template.isNull()) |
| 3615 | return 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3616 | |
| 3617 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3618 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3619 | Template, |
| 3620 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3621 | } else { |
| 3622 | // Nothing special needs to be done for these. |
| 3623 | Result = getDerived().TransformType(TLB, TL); |
| 3624 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3625 | |
| 3626 | if (Result.isNull()) |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3627 | return 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3628 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3629 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3630 | } |
| 3631 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3632 | template <class TyLoc> static inline |
| 3633 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3634 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3635 | NewT.setNameLoc(T.getNameLoc()); |
| 3636 | return T.getType(); |
| 3637 | } |
| 3638 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3639 | template<typename Derived> |
| 3640 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3641 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3642 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3643 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3644 | if (T.needsExtraLocalData()) |
| 3645 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3646 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3648 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3649 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3650 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3651 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3652 | // FIXME: recurse? |
| 3653 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3654 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3656 | template <typename Derived> |
| 3657 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 3658 | AdjustedTypeLoc TL) { |
| 3659 | // Adjustments applied during transformation are handled elsewhere. |
| 3660 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3661 | } |
| 3662 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3663 | template<typename Derived> |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 3664 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 3665 | DecayedTypeLoc TL) { |
| 3666 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 3667 | if (OriginalType.isNull()) |
| 3668 | return QualType(); |
| 3669 | |
| 3670 | QualType Result = TL.getType(); |
| 3671 | if (getDerived().AlwaysRebuild() || |
| 3672 | OriginalType != TL.getOriginalLoc().getType()) |
| 3673 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 3674 | TLB.push<DecayedTypeLoc>(Result); |
| 3675 | // Nothing to set for DecayedTypeLoc. |
| 3676 | return Result; |
| 3677 | } |
| 3678 | |
| 3679 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3680 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3681 | PointerTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3682 | QualType PointeeType |
| 3683 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3684 | if (PointeeType.isNull()) |
| 3685 | return QualType(); |
| 3686 | |
| 3687 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3688 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3689 | // A dependent pointer type 'T *' has is being transformed such |
| 3690 | // that an Objective-C class type is being replaced for 'T'. The |
| 3691 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3692 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3693 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3694 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3695 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3696 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3697 | return Result; |
| 3698 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3700 | if (getDerived().AlwaysRebuild() || |
| 3701 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3702 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3703 | if (Result.isNull()) |
| 3704 | return QualType(); |
| 3705 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3706 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3707 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3708 | // pointing to. |
| 3709 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3710 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3711 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3712 | NewT.setSigilLoc(TL.getSigilLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3713 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3714 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | |
| 3716 | template<typename Derived> |
| 3717 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3718 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3719 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3720 | QualType PointeeType |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3721 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3722 | if (PointeeType.isNull()) |
| 3723 | return QualType(); |
| 3724 | |
| 3725 | QualType Result = TL.getType(); |
| 3726 | if (getDerived().AlwaysRebuild() || |
| 3727 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3728 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3729 | TL.getSigilLoc()); |
| 3730 | if (Result.isNull()) |
| 3731 | return QualType(); |
| 3732 | } |
| 3733 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3734 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3735 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3736 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3739 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3740 | /// don't care whether the type itself is an l-value type or an r-value |
| 3741 | /// type; we only care if the type was *written* as an l-value type |
| 3742 | /// or an r-value type. |
| 3743 | template<typename Derived> |
| 3744 | QualType |
| 3745 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3746 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3747 | const ReferenceType *T = TL.getTypePtr(); |
| 3748 | |
| 3749 | // Note that this works with the pointee-as-written. |
| 3750 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3751 | if (PointeeType.isNull()) |
| 3752 | return QualType(); |
| 3753 | |
| 3754 | QualType Result = TL.getType(); |
| 3755 | if (getDerived().AlwaysRebuild() || |
| 3756 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3757 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3758 | T->isSpelledAsLValue(), |
| 3759 | TL.getSigilLoc()); |
| 3760 | if (Result.isNull()) |
| 3761 | return QualType(); |
| 3762 | } |
| 3763 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3764 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3765 | // referring to. |
| 3766 | TLB.TypeWasModifiedSafely( |
| 3767 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3768 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3769 | // r-value references can be rebuilt as l-value references. |
| 3770 | ReferenceTypeLoc NewTL; |
| 3771 | if (isa<LValueReferenceType>(Result)) |
| 3772 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3773 | else |
| 3774 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3775 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3776 | |
| 3777 | return Result; |
| 3778 | } |
| 3779 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3780 | template<typename Derived> |
| 3781 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3782 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3783 | LValueReferenceTypeLoc TL) { |
| 3784 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3785 | } |
| 3786 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | template<typename Derived> |
| 3788 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3789 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3790 | RValueReferenceTypeLoc TL) { |
| 3791 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3792 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3793 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3794 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3796 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3797 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3798 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3799 | if (PointeeType.isNull()) |
| 3800 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3801 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3802 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3803 | TypeSourceInfo* NewClsTInfo = 0; |
| 3804 | if (OldClsTInfo) { |
| 3805 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3806 | if (!NewClsTInfo) |
| 3807 | return QualType(); |
| 3808 | } |
| 3809 | |
| 3810 | const MemberPointerType *T = TL.getTypePtr(); |
| 3811 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3812 | QualType NewClsType; |
| 3813 | if (NewClsTInfo) |
| 3814 | NewClsType = NewClsTInfo->getType(); |
| 3815 | else { |
| 3816 | NewClsType = getDerived().TransformType(OldClsType); |
| 3817 | if (NewClsType.isNull()) |
| 3818 | return QualType(); |
| 3819 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3820 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3821 | QualType Result = TL.getType(); |
| 3822 | if (getDerived().AlwaysRebuild() || |
| 3823 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3824 | NewClsType != OldClsType) { |
| 3825 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3826 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3827 | if (Result.isNull()) |
| 3828 | return QualType(); |
| 3829 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3830 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 3831 | // If we had to adjust the pointee type when building a member pointer, make |
| 3832 | // sure to push TypeLoc info for it. |
| 3833 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 3834 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 3835 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 3836 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 3837 | } |
| 3838 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3839 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3840 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3841 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3842 | |
| 3843 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3846 | template<typename Derived> |
| 3847 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3848 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3849 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3850 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3851 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3852 | if (ElementType.isNull()) |
| 3853 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3854 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3855 | QualType Result = TL.getType(); |
| 3856 | if (getDerived().AlwaysRebuild() || |
| 3857 | ElementType != T->getElementType()) { |
| 3858 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3859 | T->getSizeModifier(), |
| 3860 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3861 | T->getIndexTypeCVRQualifiers(), |
| 3862 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3863 | if (Result.isNull()) |
| 3864 | return QualType(); |
| 3865 | } |
Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 3866 | |
| 3867 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 3868 | // a ConstantArrayType is allowed to have an element type which is a |
| 3869 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 3870 | // types have the same location layout. |
| 3871 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3872 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3873 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3875 | Expr *Size = TL.getSizeExpr(); |
| 3876 | if (Size) { |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3877 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3878 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3879 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3880 | Size = SemaRef.ActOnConstantExpression(Size).take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3881 | } |
| 3882 | NewTL.setSizeExpr(Size); |
| 3883 | |
| 3884 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3885 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3886 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3887 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3888 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3889 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3890 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3891 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3892 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3893 | if (ElementType.isNull()) |
| 3894 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3895 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3896 | QualType Result = TL.getType(); |
| 3897 | if (getDerived().AlwaysRebuild() || |
| 3898 | ElementType != T->getElementType()) { |
| 3899 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3900 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3901 | T->getIndexTypeCVRQualifiers(), |
| 3902 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3903 | if (Result.isNull()) |
| 3904 | return QualType(); |
| 3905 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3906 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3907 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3908 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3909 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3910 | NewTL.setSizeExpr(0); |
| 3911 | |
| 3912 | return Result; |
| 3913 | } |
| 3914 | |
| 3915 | template<typename Derived> |
| 3916 | QualType |
| 3917 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3918 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3919 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3920 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3921 | if (ElementType.isNull()) |
| 3922 | return QualType(); |
| 3923 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3924 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3925 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3926 | if (SizeResult.isInvalid()) |
| 3927 | return QualType(); |
| 3928 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3929 | Expr *Size = SizeResult.take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3930 | |
| 3931 | QualType Result = TL.getType(); |
| 3932 | if (getDerived().AlwaysRebuild() || |
| 3933 | ElementType != T->getElementType() || |
| 3934 | Size != T->getSizeExpr()) { |
| 3935 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3936 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3937 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3938 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3939 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3940 | if (Result.isNull()) |
| 3941 | return QualType(); |
| 3942 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3943 | |
Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 3944 | // We might have constant size array now, but fortunately it has the same |
| 3945 | // location layout. |
| 3946 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3947 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3948 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3949 | NewTL.setSizeExpr(Size); |
| 3950 | |
| 3951 | return Result; |
| 3952 | } |
| 3953 | |
| 3954 | template<typename Derived> |
| 3955 | QualType |
| 3956 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3957 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3958 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3959 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3960 | if (ElementType.isNull()) |
| 3961 | return QualType(); |
| 3962 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3963 | // Array bounds are constant expressions. |
| 3964 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 3965 | Sema::ConstantEvaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3966 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3967 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3968 | Expr *origSize = TL.getSizeExpr(); |
| 3969 | if (!origSize) origSize = T->getSizeExpr(); |
| 3970 | |
| 3971 | ExprResult sizeResult |
| 3972 | = getDerived().TransformExpr(origSize); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3973 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3974 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3975 | return QualType(); |
| 3976 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3977 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3978 | |
| 3979 | QualType Result = TL.getType(); |
| 3980 | if (getDerived().AlwaysRebuild() || |
| 3981 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3982 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3983 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3984 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3985 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3986 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3987 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3988 | if (Result.isNull()) |
| 3989 | return QualType(); |
| 3990 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3991 | |
| 3992 | // We might have any sort of array type now, but fortunately they |
| 3993 | // all have the same location layout. |
| 3994 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3995 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3996 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3997 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3998 | |
| 3999 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4000 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | |
| 4002 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4003 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4004 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4005 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4006 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4007 | |
| 4008 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4009 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4010 | if (ElementType.isNull()) |
| 4011 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4012 | |
Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4013 | // Vector sizes are constant expressions. |
| 4014 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 4015 | Sema::ConstantEvaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4016 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4017 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4018 | Size = SemaRef.ActOnConstantExpression(Size); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4019 | if (Size.isInvalid()) |
| 4020 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4021 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4022 | QualType Result = TL.getType(); |
| 4023 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4024 | ElementType != T->getElementType() || |
| 4025 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4026 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4027 | Size.take(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4028 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4029 | if (Result.isNull()) |
| 4030 | return QualType(); |
| 4031 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4032 | |
| 4033 | // Result might be dependent or not. |
| 4034 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4035 | DependentSizedExtVectorTypeLoc NewTL |
| 4036 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4037 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4038 | } else { |
| 4039 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4040 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4041 | } |
| 4042 | |
| 4043 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4044 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
| 4046 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4047 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4048 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4049 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4050 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4051 | if (ElementType.isNull()) |
| 4052 | return QualType(); |
| 4053 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4054 | QualType Result = TL.getType(); |
| 4055 | if (getDerived().AlwaysRebuild() || |
| 4056 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4057 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4058 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4059 | if (Result.isNull()) |
| 4060 | return QualType(); |
| 4061 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4062 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4063 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4064 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4065 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4066 | return Result; |
| 4067 | } |
| 4068 | |
| 4069 | template<typename Derived> |
| 4070 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4071 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4072 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4073 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4074 | if (ElementType.isNull()) |
| 4075 | return QualType(); |
| 4076 | |
| 4077 | QualType Result = TL.getType(); |
| 4078 | if (getDerived().AlwaysRebuild() || |
| 4079 | ElementType != T->getElementType()) { |
| 4080 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4081 | T->getNumElements(), |
| 4082 | /*FIXME*/ SourceLocation()); |
| 4083 | if (Result.isNull()) |
| 4084 | return QualType(); |
| 4085 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4086 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4087 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4088 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4089 | |
| 4090 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4093 | template <typename Derived> |
| 4094 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4095 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4096 | bool ExpectParameterPack) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4097 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4098 | TypeSourceInfo *NewDI = 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4100 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4101 | // If we're substituting into a pack expansion type and we know the |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4102 | // length we want to expand to, just substitute for the pattern. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4103 | TypeLoc OldTL = OldDI->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4104 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4106 | TypeLocBuilder TLB; |
| 4107 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4108 | TLB.reserve(NewTL.getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4109 | |
| 4110 | QualType Result = getDerived().TransformType(TLB, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4111 | OldExpansionTL.getPatternLoc()); |
| 4112 | if (Result.isNull()) |
| 4113 | return 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4114 | |
| 4115 | Result = RebuildPackExpansionType(Result, |
| 4116 | OldExpansionTL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4117 | OldExpansionTL.getEllipsisLoc(), |
| 4118 | NumExpansions); |
| 4119 | if (Result.isNull()) |
| 4120 | return 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4121 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4122 | PackExpansionTypeLoc NewExpansionTL |
| 4123 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4124 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4125 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4126 | } else |
| 4127 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4128 | if (!NewDI) |
| 4129 | return 0; |
| 4130 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4131 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4132 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4133 | |
| 4134 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4135 | OldParm->getDeclContext(), |
| 4136 | OldParm->getInnerLocStart(), |
| 4137 | OldParm->getLocation(), |
| 4138 | OldParm->getIdentifier(), |
| 4139 | NewDI->getType(), |
| 4140 | NewDI, |
| 4141 | OldParm->getStorageClass(), |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4142 | /* DefArg */ NULL); |
| 4143 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4144 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4145 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | template<typename Derived> |
| 4149 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4150 | TransformFunctionTypeParams(SourceLocation Loc, |
| 4151 | ParmVarDecl **Params, unsigned NumParams, |
| 4152 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4153 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4154 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4155 | int indexAdjustment = 0; |
| 4156 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4157 | for (unsigned i = 0; i != NumParams; ++i) { |
| 4158 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4159 | assert(OldParm->getFunctionScopeIndex() == i); |
| 4160 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4161 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4162 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4163 | if (OldParm->isParameterPack()) { |
| 4164 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4165 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4166 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4167 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4168 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4169 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4170 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 4171 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4172 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 4173 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4174 | // Determine whether we should expand the parameter packs. |
| 4175 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4176 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4177 | Optional<unsigned> OrigNumExpansions = |
| 4178 | ExpansionTL.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4179 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 4180 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 4181 | Pattern.getSourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4182 | Unexpanded, |
| 4183 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4184 | RetainExpansion, |
| 4185 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4186 | return true; |
| 4187 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4188 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4189 | if (ShouldExpand) { |
| 4190 | // Expand the function parameter pack into multiple, separate |
| 4191 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 4192 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4193 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4194 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4195 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4196 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4197 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4198 | OrigNumExpansions, |
| 4199 | /*ExpectParameterPack=*/false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4200 | if (!NewParm) |
| 4201 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4202 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4203 | OutParamTypes.push_back(NewParm->getType()); |
| 4204 | if (PVars) |
| 4205 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4206 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4207 | |
| 4208 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4209 | // forgetting the partially-substituted parameter pack. |
| 4210 | if (RetainExpansion) { |
| 4211 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4212 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4213 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4214 | indexAdjustment++, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4215 | OrigNumExpansions, |
| 4216 | /*ExpectParameterPack=*/false); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4217 | if (!NewParm) |
| 4218 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4219 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4220 | OutParamTypes.push_back(NewParm->getType()); |
| 4221 | if (PVars) |
| 4222 | PVars->push_back(NewParm); |
| 4223 | } |
| 4224 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4225 | // The next parameter should have the same adjustment as the |
| 4226 | // last thing we pushed, but we post-incremented indexAdjustment |
| 4227 | // on every push. Also, if we push nothing, the adjustment should |
| 4228 | // go down by one. |
| 4229 | indexAdjustment--; |
| 4230 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4231 | // We're done with the pack expansion. |
| 4232 | continue; |
| 4233 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4234 | |
| 4235 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4236 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4237 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4238 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4239 | indexAdjustment, |
Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4240 | NumExpansions, |
| 4241 | /*ExpectParameterPack=*/true); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4242 | } else { |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4243 | NewParm = getDerived().TransformFunctionTypeParam( |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 4244 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4245 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4246 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4247 | if (!NewParm) |
| 4248 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4249 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4250 | OutParamTypes.push_back(NewParm->getType()); |
| 4251 | if (PVars) |
| 4252 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4253 | continue; |
| 4254 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4255 | |
| 4256 | // Deal with the possibility that we don't have a parameter |
| 4257 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4258 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4259 | bool IsPackExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4260 | Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4261 | QualType NewType; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4262 | if (const PackExpansionType *Expansion |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4263 | = dyn_cast<PackExpansionType>(OldType)) { |
| 4264 | // We have a function parameter pack that may need to be expanded. |
| 4265 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4266 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4267 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4268 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4269 | // Determine whether we should expand the parameter packs. |
| 4270 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4271 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4272 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4273 | Unexpanded, |
| 4274 | ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4275 | RetainExpansion, |
| 4276 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4277 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4278 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4279 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4280 | if (ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4281 | // Expand the function parameter pack into multiple, separate |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4282 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4283 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4284 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4285 | QualType NewType = getDerived().TransformType(Pattern); |
| 4286 | if (NewType.isNull()) |
| 4287 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4289 | OutParamTypes.push_back(NewType); |
| 4290 | if (PVars) |
| 4291 | PVars->push_back(0); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4292 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4293 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4294 | // We're done with the pack expansion. |
| 4295 | continue; |
| 4296 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4297 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4298 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4299 | // forgetting the partially-substituted parameter pack. |
| 4300 | if (RetainExpansion) { |
| 4301 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4302 | QualType NewType = getDerived().TransformType(Pattern); |
| 4303 | if (NewType.isNull()) |
| 4304 | return true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4305 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4306 | OutParamTypes.push_back(NewType); |
| 4307 | if (PVars) |
| 4308 | PVars->push_back(0); |
| 4309 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4310 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4311 | // We'll substitute the parameter now without expanding the pack |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4312 | // expansion. |
| 4313 | OldType = Expansion->getPattern(); |
| 4314 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 4315 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4316 | NewType = getDerived().TransformType(OldType); |
| 4317 | } else { |
| 4318 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4319 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4320 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4321 | if (NewType.isNull()) |
| 4322 | return true; |
| 4323 | |
| 4324 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4325 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 4326 | NumExpansions); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4327 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4328 | OutParamTypes.push_back(NewType); |
| 4329 | if (PVars) |
| 4330 | PVars->push_back(0); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4333 | #ifndef NDEBUG |
| 4334 | if (PVars) { |
| 4335 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4336 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4337 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4338 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4339 | #endif |
| 4340 | |
| 4341 | return false; |
| 4342 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4343 | |
| 4344 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4345 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4346 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4347 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4348 | return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); |
| 4349 | } |
| 4350 | |
| 4351 | template<typename Derived> |
| 4352 | QualType |
| 4353 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 4354 | FunctionProtoTypeLoc TL, |
| 4355 | CXXRecordDecl *ThisContext, |
| 4356 | unsigned ThisTypeQuals) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4357 | // Transform the parameters and return type. |
| 4358 | // |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4359 | // We are required to instantiate the params and return type in source order. |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4360 | // When the function has a trailing return type, we instantiate the |
| 4361 | // parameters before the return type, since the return type can then refer |
| 4362 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4363 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4364 | SmallVector<QualType, 4> ParamTypes; |
| 4365 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4366 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4367 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4368 | QualType ResultType; |
| 4369 | |
Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 4370 | if (T->hasTrailingReturn()) { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4371 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4372 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4373 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4374 | return QualType(); |
| 4375 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4376 | { |
| 4377 | // C++11 [expr.prim.general]p3: |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4378 | // If a declaration declares a member function or member function |
| 4379 | // template of a class X, the expression this is a prvalue of type |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4380 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4381 | // and the end of the function-definition, member-declarator, or |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4382 | // declarator. |
| 4383 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4384 | |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4385 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 4386 | if (ResultType.isNull()) |
| 4387 | return QualType(); |
| 4388 | } |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4389 | } |
| 4390 | else { |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4391 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4392 | if (ResultType.isNull()) |
| 4393 | return QualType(); |
| 4394 | |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4395 | if (getDerived().TransformFunctionTypeParams( |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4396 | TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4397 | TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4398 | return QualType(); |
| 4399 | } |
| 4400 | |
Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 4401 | // FIXME: Need to transform the exception-specification too. |
| 4402 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4403 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4404 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 4405 | T->getNumParams() != ParamTypes.size() || |
| 4406 | !std::equal(T->param_type_begin(), T->param_type_end(), |
| 4407 | ParamTypes.begin())) { |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 4408 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 4409 | T->getExtProtoInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4410 | if (Result.isNull()) |
| 4411 | return QualType(); |
| 4412 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4414 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4415 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4416 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4417 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4418 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 4419 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 4420 | NewTL.setParam(i, ParamDecls[i]); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4421 | |
| 4422 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4425 | template<typename Derived> |
| 4426 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4427 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4428 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4429 | const FunctionNoProtoType *T = TL.getTypePtr(); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 4430 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4431 | if (ResultType.isNull()) |
| 4432 | return QualType(); |
| 4433 | |
| 4434 | QualType Result = TL.getType(); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4435 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4436 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4437 | |
| 4438 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4439 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4440 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4441 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4442 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4443 | |
| 4444 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4445 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4446 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4447 | template<typename Derived> QualType |
| 4448 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4449 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4450 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4451 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4452 | if (!D) |
| 4453 | return QualType(); |
| 4454 | |
| 4455 | QualType Result = TL.getType(); |
| 4456 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4457 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4458 | if (Result.isNull()) |
| 4459 | return QualType(); |
| 4460 | } |
| 4461 | |
| 4462 | // We might get an arbitrary type spec type back. We should at |
| 4463 | // least always get a type spec type, though. |
| 4464 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4465 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4466 | |
| 4467 | return Result; |
| 4468 | } |
| 4469 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4470 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4471 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4472 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4473 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4474 | TypedefNameDecl *Typedef |
| 4475 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4476 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4477 | if (!Typedef) |
| 4478 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4480 | QualType Result = TL.getType(); |
| 4481 | if (getDerived().AlwaysRebuild() || |
| 4482 | Typedef != T->getDecl()) { |
| 4483 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4484 | if (Result.isNull()) |
| 4485 | return QualType(); |
| 4486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4487 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4488 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4489 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4490 | |
| 4491 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4492 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4494 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4495 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4496 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4497 | // typeof expressions are not potentially evaluated contexts |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 4498 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 4499 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4501 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4502 | if (E.isInvalid()) |
| 4503 | return QualType(); |
| 4504 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 4505 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 4506 | if (E.isInvalid()) |
| 4507 | return QualType(); |
| 4508 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4509 | QualType Result = TL.getType(); |
| 4510 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4511 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4512 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4513 | if (Result.isNull()) |
| 4514 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4515 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4516 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4518 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4519 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4520 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4521 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4522 | |
| 4523 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4524 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
| 4526 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4527 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4528 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4529 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4530 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4531 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4532 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4534 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4535 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4536 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4537 | if (Result.isNull()) |
| 4538 | return QualType(); |
| 4539 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4541 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4542 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4543 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4544 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4545 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4546 | |
| 4547 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | |
| 4550 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4551 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4552 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4553 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4554 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4555 | // decltype expressions are not potentially evaluated contexts |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4556 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, |
| 4557 | /*IsDecltype=*/ true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4559 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4560 | if (E.isInvalid()) |
| 4561 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | |
Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 4563 | E = getSema().ActOnDecltypeExpression(E.take()); |
| 4564 | if (E.isInvalid()) |
| 4565 | return QualType(); |
| 4566 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4567 | QualType Result = TL.getType(); |
| 4568 | if (getDerived().AlwaysRebuild() || |
| 4569 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4570 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4571 | if (Result.isNull()) |
| 4572 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4573 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4574 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4576 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4577 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4578 | |
| 4579 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4583 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4584 | TypeLocBuilder &TLB, |
| 4585 | UnaryTransformTypeLoc TL) { |
| 4586 | QualType Result = TL.getType(); |
| 4587 | if (Result->isDependentType()) { |
| 4588 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4589 | QualType NewBase = |
| 4590 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4591 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4592 | T->getUTTKind(), |
| 4593 | TL.getKWLoc()); |
| 4594 | if (Result.isNull()) |
| 4595 | return QualType(); |
| 4596 | } |
| 4597 | |
| 4598 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4599 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4600 | NewTL.setParensRange(TL.getParensRange()); |
| 4601 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4602 | return Result; |
| 4603 | } |
| 4604 | |
| 4605 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4606 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4607 | AutoTypeLoc TL) { |
| 4608 | const AutoType *T = TL.getTypePtr(); |
| 4609 | QualType OldDeduced = T->getDeducedType(); |
| 4610 | QualType NewDeduced; |
| 4611 | if (!OldDeduced.isNull()) { |
| 4612 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4613 | if (NewDeduced.isNull()) |
| 4614 | return QualType(); |
| 4615 | } |
| 4616 | |
| 4617 | QualType Result = TL.getType(); |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 4618 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 4619 | T->isDependentType()) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 4620 | Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto()); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4621 | if (Result.isNull()) |
| 4622 | return QualType(); |
| 4623 | } |
| 4624 | |
| 4625 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4626 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4627 | |
| 4628 | return Result; |
| 4629 | } |
| 4630 | |
| 4631 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4632 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4633 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4634 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4635 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4636 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4637 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4638 | if (!Record) |
| 4639 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4641 | QualType Result = TL.getType(); |
| 4642 | if (getDerived().AlwaysRebuild() || |
| 4643 | Record != T->getDecl()) { |
| 4644 | Result = getDerived().RebuildRecordType(Record); |
| 4645 | if (Result.isNull()) |
| 4646 | return QualType(); |
| 4647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4648 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4649 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4650 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4651 | |
| 4652 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4654 | |
| 4655 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4656 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4657 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4658 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4659 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4660 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4661 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4662 | if (!Enum) |
| 4663 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4665 | QualType Result = TL.getType(); |
| 4666 | if (getDerived().AlwaysRebuild() || |
| 4667 | Enum != T->getDecl()) { |
| 4668 | Result = getDerived().RebuildEnumType(Enum); |
| 4669 | if (Result.isNull()) |
| 4670 | return QualType(); |
| 4671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4673 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4674 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4675 | |
| 4676 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4677 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4678 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4679 | template<typename Derived> |
| 4680 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4681 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4682 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4683 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4684 | TL.getTypePtr()->getDecl()); |
| 4685 | if (!D) return QualType(); |
| 4686 | |
| 4687 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4688 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4689 | return T; |
| 4690 | } |
| 4691 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4692 | template<typename Derived> |
| 4693 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4694 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4695 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4696 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4699 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4700 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4701 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4702 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4703 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4704 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4705 | // Substitute into the replacement type, which itself might involve something |
| 4706 | // that needs to be transformed. This only tends to occur with default |
| 4707 | // template arguments of template template parameters. |
| 4708 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4709 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4710 | if (Replacement.isNull()) |
| 4711 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4712 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4713 | // Always canonicalize the replacement type. |
| 4714 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4715 | QualType Result |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4716 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4717 | Replacement); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4719 | // Propagate type-source information. |
| 4720 | SubstTemplateTypeParmTypeLoc NewTL |
| 4721 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4722 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4723 | return Result; |
| 4724 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4728 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4729 | TypeLocBuilder &TLB, |
| 4730 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4731 | return TransformTypeSpecType(TLB, TL); |
| 4732 | } |
| 4733 | |
| 4734 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4735 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4736 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4737 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4738 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4739 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4740 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4741 | // because we can't have a dependent nested-name-specifier anyway. |
| 4742 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4743 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4744 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4745 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4746 | if (Template.isNull()) |
| 4747 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4748 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4749 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4750 | } |
| 4751 | |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4752 | template<typename Derived> |
| 4753 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 4754 | AtomicTypeLoc TL) { |
| 4755 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 4756 | if (ValueType.isNull()) |
| 4757 | return QualType(); |
| 4758 | |
| 4759 | QualType Result = TL.getType(); |
| 4760 | if (getDerived().AlwaysRebuild() || |
| 4761 | ValueType != TL.getValueLoc().getType()) { |
| 4762 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 4763 | if (Result.isNull()) |
| 4764 | return QualType(); |
| 4765 | } |
| 4766 | |
| 4767 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 4768 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4769 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4770 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4771 | |
| 4772 | return Result; |
| 4773 | } |
| 4774 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4775 | /// \brief Simple iterator that traverses the template arguments in a |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4776 | /// container that provides a \c getArgLoc() member function. |
| 4777 | /// |
| 4778 | /// This iterator is intended to be used with the iterator form of |
| 4779 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4780 | template<typename ArgLocContainer> |
| 4781 | class TemplateArgumentLocContainerIterator { |
| 4782 | ArgLocContainer *Container; |
| 4783 | unsigned Index; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4784 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4785 | public: |
| 4786 | typedef TemplateArgumentLoc value_type; |
| 4787 | typedef TemplateArgumentLoc reference; |
| 4788 | typedef int difference_type; |
| 4789 | typedef std::input_iterator_tag iterator_category; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4790 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4791 | class pointer { |
| 4792 | TemplateArgumentLoc Arg; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4793 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4794 | public: |
| 4795 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4797 | const TemplateArgumentLoc *operator->() const { |
| 4798 | return &Arg; |
| 4799 | } |
| 4800 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4801 | |
| 4802 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4803 | TemplateArgumentLocContainerIterator() {} |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4804 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4805 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4806 | unsigned Index) |
| 4807 | : Container(&Container), Index(Index) { } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4808 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4809 | TemplateArgumentLocContainerIterator &operator++() { |
| 4810 | ++Index; |
| 4811 | return *this; |
| 4812 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4813 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4814 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4815 | TemplateArgumentLocContainerIterator Old(*this); |
| 4816 | ++(*this); |
| 4817 | return Old; |
| 4818 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4819 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4820 | TemplateArgumentLoc operator*() const { |
| 4821 | return Container->getArgLoc(Index); |
| 4822 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4823 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4824 | pointer operator->() const { |
| 4825 | return pointer(Container->getArgLoc(Index)); |
| 4826 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4827 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4828 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4829 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4830 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4831 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4832 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4833 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4834 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4835 | return !(X == Y); |
| 4836 | } |
| 4837 | }; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4838 | |
| 4839 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4840 | template <typename Derived> |
| 4841 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4842 | TypeLocBuilder &TLB, |
| 4843 | TemplateSpecializationTypeLoc TL, |
| 4844 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4845 | TemplateArgumentListInfo NewTemplateArgs; |
| 4846 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4847 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4848 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4849 | ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4850 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4851 | ArgIterator(TL, TL.getNumArgs()), |
| 4852 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4853 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4855 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4856 | |
| 4857 | QualType Result = |
| 4858 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4859 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4860 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4861 | |
| 4862 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4863 | // Specializations of template template parameters are represented as |
| 4864 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4865 | // within a dependent context can transform them into |
| 4866 | // DependentTemplateSpecializationTypes. |
| 4867 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4868 | DependentTemplateSpecializationTypeLoc NewTL |
| 4869 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4870 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4871 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4872 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4873 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4874 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4875 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4876 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4877 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4878 | return Result; |
| 4879 | } |
| 4880 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4881 | TemplateSpecializationTypeLoc NewTL |
| 4882 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4883 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4884 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4885 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4886 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4887 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4888 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4889 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4890 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4891 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4893 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4894 | template <typename Derived> |
| 4895 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4896 | TypeLocBuilder &TLB, |
| 4897 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4898 | TemplateName Template, |
| 4899 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4900 | TemplateArgumentListInfo NewTemplateArgs; |
| 4901 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4902 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4903 | typedef TemplateArgumentLocContainerIterator< |
| 4904 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4905 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4906 | ArgIterator(TL, TL.getNumArgs()), |
| 4907 | NewTemplateArgs)) |
| 4908 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4909 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4910 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4911 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4912 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4913 | QualType Result |
| 4914 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4915 | TL.getTypePtr()->getKeyword(), |
| 4916 | DTN->getQualifier(), |
| 4917 | DTN->getIdentifier(), |
| 4918 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4919 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4920 | DependentTemplateSpecializationTypeLoc NewTL |
| 4921 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4922 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4923 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4924 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4925 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4926 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4927 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4928 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4929 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4930 | return Result; |
| 4931 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4932 | |
| 4933 | QualType Result |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4934 | = getDerived().RebuildTemplateSpecializationType(Template, |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4935 | TL.getTemplateNameLoc(), |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4936 | NewTemplateArgs); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4938 | if (!Result.isNull()) { |
| 4939 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4940 | TemplateSpecializationTypeLoc NewTL |
| 4941 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4942 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4943 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4944 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4945 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4946 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4947 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4948 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4949 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4950 | return Result; |
| 4951 | } |
| 4952 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4953 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4954 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4955 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4956 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4957 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4958 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4959 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4960 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4961 | if (TL.getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4962 | QualifierLoc |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4963 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4964 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4965 | return QualType(); |
| 4966 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4967 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4968 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4969 | if (NamedT.isNull()) |
| 4970 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4971 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4972 | // C++0x [dcl.type.elab]p2: |
| 4973 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4974 | // resolves to an alias template specialization, the |
| 4975 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4976 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4977 | if (const TemplateSpecializationType *TST = |
| 4978 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4979 | TemplateName Template = TST->getTemplateName(); |
| 4980 | if (TypeAliasTemplateDecl *TAT = |
| 4981 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4982 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4983 | diag::err_tag_reference_non_tag) << 4; |
| 4984 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4985 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4986 | } |
| 4987 | } |
| 4988 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4989 | QualType Result = TL.getType(); |
| 4990 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4991 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4992 | NamedT != T->getNamedType()) { |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4993 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4994 | T->getKeyword(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4995 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4996 | if (Result.isNull()) |
| 4997 | return QualType(); |
| 4998 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4999 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5000 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5001 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5002 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5003 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5005 | |
| 5006 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 5007 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 5008 | TypeLocBuilder &TLB, |
| 5009 | AttributedTypeLoc TL) { |
| 5010 | const AttributedType *oldType = TL.getTypePtr(); |
| 5011 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 5012 | if (modifiedType.isNull()) |
| 5013 | return QualType(); |
| 5014 | |
| 5015 | QualType result = TL.getType(); |
| 5016 | |
| 5017 | // FIXME: dependent operand expressions? |
| 5018 | if (getDerived().AlwaysRebuild() || |
| 5019 | modifiedType != oldType->getModifiedType()) { |
| 5020 | // TODO: this is really lame; we should really be rebuilding the |
| 5021 | // equivalent type from first principles. |
| 5022 | QualType equivalentType |
| 5023 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 5024 | if (equivalentType.isNull()) |
| 5025 | return QualType(); |
| 5026 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 5027 | modifiedType, |
| 5028 | equivalentType); |
| 5029 | } |
| 5030 | |
| 5031 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 5032 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5033 | if (TL.hasAttrOperand()) |
| 5034 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5035 | if (TL.hasAttrExprOperand()) |
| 5036 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5037 | else if (TL.hasAttrEnumOperand()) |
| 5038 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 5039 | |
| 5040 | return result; |
| 5041 | } |
| 5042 | |
| 5043 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 5044 | QualType |
| 5045 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 5046 | ParenTypeLoc TL) { |
| 5047 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 5048 | if (Inner.isNull()) |
| 5049 | return QualType(); |
| 5050 | |
| 5051 | QualType Result = TL.getType(); |
| 5052 | if (getDerived().AlwaysRebuild() || |
| 5053 | Inner != TL.getInnerLoc().getType()) { |
| 5054 | Result = getDerived().RebuildParenType(Inner); |
| 5055 | if (Result.isNull()) |
| 5056 | return QualType(); |
| 5057 | } |
| 5058 | |
| 5059 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 5060 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5061 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5062 | return Result; |
| 5063 | } |
| 5064 | |
| 5065 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 5066 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5067 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5068 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5069 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5070 | NestedNameSpecifierLoc QualifierLoc |
| 5071 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5072 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5073 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5074 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5075 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5076 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5077 | TL.getElaboratedKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5078 | QualifierLoc, |
| 5079 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5080 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5081 | if (Result.isNull()) |
| 5082 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5083 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5084 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 5085 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5086 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 5087 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5088 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5089 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 5090 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5091 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5092 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5093 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 5094 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 5095 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5096 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5097 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5098 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5099 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5100 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 5101 | QualType TreeTransform<Derived>:: |
| 5102 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5103 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5104 | NestedNameSpecifierLoc QualifierLoc; |
| 5105 | if (TL.getQualifierLoc()) { |
| 5106 | QualifierLoc |
| 5107 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 5108 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5109 | return QualType(); |
| 5110 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5111 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5112 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5113 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | template<typename Derived> |
| 5117 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5118 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 5119 | DependentTemplateSpecializationTypeLoc TL, |
| 5120 | NestedNameSpecifierLoc QualifierLoc) { |
| 5121 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5122 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5123 | TemplateArgumentListInfo NewTemplateArgs; |
| 5124 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5125 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5126 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5127 | typedef TemplateArgumentLocContainerIterator< |
| 5128 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 5129 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 5130 | ArgIterator(TL, TL.getNumArgs()), |
| 5131 | NewTemplateArgs)) |
| 5132 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5133 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5134 | QualType Result |
| 5135 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 5136 | QualifierLoc, |
| 5137 | T->getIdentifier(), |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5138 | TL.getTemplateNameLoc(), |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5139 | NewTemplateArgs); |
| 5140 | if (Result.isNull()) |
| 5141 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5142 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5143 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 5144 | QualType NamedT = ElabT->getNamedType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5145 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5146 | // Copy information relevant to the template specialization. |
| 5147 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5148 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5149 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5150 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5151 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5152 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5153 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5154 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5155 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5156 | // Copy information relevant to the elaborated type. |
| 5157 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 5158 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5159 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5160 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5161 | DependentTemplateSpecializationTypeLoc SpecTL |
| 5162 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5163 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5164 | SpecTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5165 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5166 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5167 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5168 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5169 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5170 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5171 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5172 | TemplateSpecializationTypeLoc SpecTL |
| 5173 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5174 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5175 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5176 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5177 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 5178 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 5179 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5180 | } |
| 5181 | return Result; |
| 5182 | } |
| 5183 | |
| 5184 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5185 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 5186 | PackExpansionTypeLoc TL) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5187 | QualType Pattern |
| 5188 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5189 | if (Pattern.isNull()) |
| 5190 | return QualType(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5191 | |
| 5192 | QualType Result = TL.getType(); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5193 | if (getDerived().AlwaysRebuild() || |
| 5194 | Pattern != TL.getPatternLoc().getType()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5195 | Result = getDerived().RebuildPackExpansionType(Pattern, |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5196 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5197 | TL.getEllipsisLoc(), |
| 5198 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5199 | if (Result.isNull()) |
| 5200 | return QualType(); |
| 5201 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5202 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 5203 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 5204 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 5205 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5209 | QualType |
| 5210 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5211 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5212 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5213 | TLB.pushFullCopy(TL); |
| 5214 | return TL.getType(); |
| 5215 | } |
| 5216 | |
| 5217 | template<typename Derived> |
| 5218 | QualType |
| 5219 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5220 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5221 | // ObjCObjectType is never dependent. |
| 5222 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5223 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5224 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5225 | |
| 5226 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5227 | QualType |
| 5228 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5229 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5230 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 5231 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5232 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5235 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5236 | // Statement transformation |
| 5237 | //===----------------------------------------------------------------------===// |
| 5238 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5239 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5240 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5241 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5245 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5246 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 5247 | return getDerived().TransformCompoundStmt(S, false); |
| 5248 | } |
| 5249 | |
| 5250 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5251 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5253 | bool IsStmtExpr) { |
Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 5254 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 5255 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5256 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5257 | bool SubStmtChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5258 | SmallVector<Stmt*, 8> Statements; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5259 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 5260 | B != BEnd; ++B) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5261 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5262 | if (Result.isInvalid()) { |
| 5263 | // Immediately fail if this was a DeclStmt, since it's very |
| 5264 | // likely that this will cause problems for future statements. |
| 5265 | if (isa<DeclStmt>(*B)) |
| 5266 | return StmtError(); |
| 5267 | |
| 5268 | // Otherwise, just keep processing substatements and fail later. |
| 5269 | SubStmtInvalid = true; |
| 5270 | continue; |
| 5271 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5272 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5273 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 5274 | Statements.push_back(Result.takeAs<Stmt>()); |
| 5275 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5276 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 5277 | if (SubStmtInvalid) |
| 5278 | return StmtError(); |
| 5279 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5280 | if (!getDerived().AlwaysRebuild() && |
| 5281 | !SubStmtChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5282 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5283 | |
| 5284 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5285 | Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5286 | S->getRBracLoc(), |
| 5287 | IsStmtExpr); |
| 5288 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5290 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5291 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5292 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5293 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5294 | { |
Eli Friedman | 1f4f9dd | 2012-01-18 02:54:10 +0000 | [diff] [blame] | 5295 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 5296 | Sema::ConstantEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5298 | // Transform the left-hand case value. |
| 5299 | LHS = getDerived().TransformExpr(S->getLHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5300 | LHS = SemaRef.ActOnConstantExpression(LHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5301 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5302 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5303 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5304 | // Transform the right-hand case value (for the GNU case-range extension). |
| 5305 | RHS = getDerived().TransformExpr(S->getRHS()); |
Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 5306 | RHS = SemaRef.ActOnConstantExpression(RHS); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5307 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5308 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 5309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5311 | // Build the case statement. |
| 5312 | // Case statements are always rebuilt so that they will attached to their |
| 5313 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5314 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5315 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5316 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5317 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5318 | S->getColonLoc()); |
| 5319 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5320 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5321 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5322 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5323 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5324 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5325 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5327 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5328 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5332 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5333 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5334 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5335 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5336 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5337 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5339 | // Default statements are always rebuilt |
| 5340 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5341 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5343 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5344 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5345 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5346 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5347 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5348 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5349 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5351 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 5352 | S->getDecl()); |
| 5353 | if (!LD) |
| 5354 | return StmtError(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5355 | |
| 5356 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5357 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 5358 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5359 | cast<LabelDecl>(LD), SourceLocation(), |
| 5360 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5362 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5363 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5364 | StmtResult |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 5365 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 5366 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 5367 | if (SubStmt.isInvalid()) |
| 5368 | return StmtError(); |
| 5369 | |
| 5370 | // TODO: transform attributes |
| 5371 | if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) |
| 5372 | return S; |
| 5373 | |
| 5374 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), |
| 5375 | S->getAttrs(), |
| 5376 | SubStmt.get()); |
| 5377 | } |
| 5378 | |
| 5379 | template<typename Derived> |
| 5380 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5382 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5383 | ExprResult Cond; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5384 | VarDecl *ConditionVar = 0; |
| 5385 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5386 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5387 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5388 | getDerived().TransformDefinition( |
| 5389 | S->getConditionVariable()->getLocation(), |
| 5390 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5391 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5392 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5393 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 5394 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5395 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5396 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5397 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5398 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5399 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5400 | if (S->getCond()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5401 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5402 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5403 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5404 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5405 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5406 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5407 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5408 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5409 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5410 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5411 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5412 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5413 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5414 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5415 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5416 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5417 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5419 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5420 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5421 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5422 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5424 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5425 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5426 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5427 | Then.get() == S->getThen() && |
| 5428 | Else.get() == S->getElse()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5429 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5431 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5432 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5433 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5437 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5438 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5439 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5440 | ExprResult Cond; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5441 | VarDecl *ConditionVar = 0; |
| 5442 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5443 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5444 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5445 | getDerived().TransformDefinition( |
| 5446 | S->getConditionVariable()->getLocation(), |
| 5447 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5448 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5449 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5450 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5451 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5452 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5453 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5454 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5455 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5457 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5458 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5459 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5460 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5461 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5462 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5464 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5465 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5466 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5467 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5468 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5469 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5470 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5471 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5472 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5473 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5474 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5475 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5477 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5478 | ExprResult Cond; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5479 | VarDecl *ConditionVar = 0; |
| 5480 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5481 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5482 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5483 | getDerived().TransformDefinition( |
| 5484 | S->getConditionVariable()->getLocation(), |
| 5485 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5486 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5487 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5488 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5489 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5490 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5491 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5492 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5493 | |
| 5494 | if (S->getCond()) { |
| 5495 | // Convert the condition to a boolean value. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5496 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5497 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5498 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5499 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5500 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5501 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5503 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5504 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5505 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5506 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5507 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5508 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5509 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5510 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5511 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5512 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5513 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5514 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5515 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5516 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5517 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5519 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5520 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5521 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5522 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5523 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5524 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5525 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5526 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5527 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5528 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5529 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5531 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5532 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5533 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5534 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5535 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5536 | if (!getDerived().AlwaysRebuild() && |
| 5537 | Cond.get() == S->getCond() && |
| 5538 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5539 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5540 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5541 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5542 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5543 | S->getRParenLoc()); |
| 5544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5546 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5547 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5549 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5550 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5551 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5552 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5554 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5555 | ExprResult Cond; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5556 | VarDecl *ConditionVar = 0; |
| 5557 | if (S->getConditionVariable()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5558 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5559 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5560 | getDerived().TransformDefinition( |
| 5561 | S->getConditionVariable()->getLocation(), |
| 5562 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5563 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5564 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5565 | } else { |
| 5566 | Cond = getDerived().TransformExpr(S->getCond()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5568 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5569 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5570 | |
| 5571 | if (S->getCond()) { |
| 5572 | // Convert the condition to a boolean value. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5573 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5574 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5575 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5576 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5577 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5578 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5579 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5581 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5582 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5583 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5584 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5585 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5586 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5587 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5588 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5589 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5590 | |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 5591 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5592 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5593 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5594 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5595 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5596 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5597 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5598 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5599 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5600 | if (!getDerived().AlwaysRebuild() && |
| 5601 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5602 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5603 | Inc.get() == S->getInc() && |
| 5604 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5605 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5606 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5607 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5608 | Init.get(), FullCond, ConditionVar, |
| 5609 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5613 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5614 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5615 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5616 | S->getLabel()); |
| 5617 | if (!LD) |
| 5618 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5619 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5620 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5621 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5622 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5626 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5627 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5628 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5629 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5630 | return StmtError(); |
Eli Friedman | 9ccdb1d | 2012-01-31 22:47:07 +0000 | [diff] [blame] | 5631 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5632 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5633 | if (!getDerived().AlwaysRebuild() && |
| 5634 | Target.get() == S->getTarget()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5635 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5636 | |
| 5637 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5638 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5642 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5644 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5645 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5646 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5647 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5648 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5649 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5650 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5651 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5653 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5654 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5655 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5656 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5657 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5658 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5659 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5660 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5661 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5662 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5665 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5666 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5667 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5668 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5669 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5670 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5671 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5672 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5673 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5674 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5675 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5677 | if (Transformed != *D) |
| 5678 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5679 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5680 | Decls.push_back(Transformed); |
| 5681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5682 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5683 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5684 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | |
Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 5686 | return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5687 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5688 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5689 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5690 | StmtResult |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5691 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5692 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5693 | SmallVector<Expr*, 8> Constraints; |
| 5694 | SmallVector<Expr*, 8> Exprs; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5695 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5696 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5697 | ExprResult AsmString; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5698 | SmallVector<Expr*, 8> Clobbers; |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5699 | |
| 5700 | bool ExprsChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5701 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5702 | // Go through the outputs. |
| 5703 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5704 | Names.push_back(S->getOutputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5705 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5706 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5707 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5708 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5709 | // Transform the output expr. |
| 5710 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5711 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5712 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5713 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5714 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5715 | ExprsChanged |= Result.get() != OutputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5716 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5717 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5718 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5719 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5720 | // Go through the inputs. |
| 5721 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5722 | Names.push_back(S->getInputIdentifier(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5723 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5724 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5725 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5726 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5727 | // Transform the input expr. |
| 5728 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5729 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5730 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5731 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5732 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5733 | ExprsChanged |= Result.get() != InputExpr; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5734 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5735 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5736 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5737 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5738 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5739 | return SemaRef.Owned(S); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5740 | |
| 5741 | // Go through the clobbers. |
| 5742 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 5743 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5744 | |
| 5745 | // No need to transform the asm string literal. |
| 5746 | AsmString = SemaRef.Owned(S->getAsmString()); |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 5747 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 5748 | S->isVolatile(), S->getNumOutputs(), |
| 5749 | S->getNumInputs(), Names.data(), |
| 5750 | Constraints, Exprs, AsmString.get(), |
| 5751 | Clobbers, S->getRParenLoc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5752 | } |
| 5753 | |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5754 | template<typename Derived> |
| 5755 | StmtResult |
| 5756 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 5757 | ArrayRef<Token> AsmToks = |
| 5758 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 5759 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5760 | bool HadError = false, HadChange = false; |
| 5761 | |
| 5762 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 5763 | SmallVector<Expr*, 8> TransformedExprs; |
| 5764 | TransformedExprs.reserve(SrcExprs.size()); |
| 5765 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 5766 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 5767 | if (!Result.isUsable()) { |
| 5768 | HadError = true; |
| 5769 | } else { |
| 5770 | HadChange |= (Result.get() != SrcExprs[i]); |
| 5771 | TransformedExprs.push_back(Result.take()); |
| 5772 | } |
| 5773 | } |
| 5774 | |
| 5775 | if (HadError) return StmtError(); |
| 5776 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 5777 | return Owned(S); |
| 5778 | |
Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 5779 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 5780 | AsmToks, S->getAsmString(), |
| 5781 | S->getNumOutputs(), S->getNumInputs(), |
| 5782 | S->getAllConstraints(), S->getClobbers(), |
| 5783 | TransformedExprs, S->getEndLoc()); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 5784 | } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5785 | |
| 5786 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5787 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5788 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5789 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5790 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5791 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5792 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5793 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5794 | // Transform the @catch statements (if present). |
| 5795 | bool AnyCatchChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 5796 | SmallVector<Stmt*, 8> CatchStmts; |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5797 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5798 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5799 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5800 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5801 | if (Catch.get() != S->getCatchStmt(I)) |
| 5802 | AnyCatchChanged = true; |
| 5803 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5804 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5805 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5806 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5807 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5808 | if (S->getFinallyStmt()) { |
| 5809 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5810 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5811 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | // If nothing changed, just retain this statement. |
| 5815 | if (!getDerived().AlwaysRebuild() && |
| 5816 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5817 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5818 | Finally.get() == S->getFinallyStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5819 | return SemaRef.Owned(S); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5820 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5821 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5822 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 5823 | CatchStmts, Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5824 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5825 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5826 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5827 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5828 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5829 | // Transform the @catch parameter, if there is one. |
| 5830 | VarDecl *Var = 0; |
| 5831 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5832 | TypeSourceInfo *TSInfo = 0; |
| 5833 | if (FromVar->getTypeSourceInfo()) { |
| 5834 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5835 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5836 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5837 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5838 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5839 | QualType T; |
| 5840 | if (TSInfo) |
| 5841 | T = TSInfo->getType(); |
| 5842 | else { |
| 5843 | T = getDerived().TransformType(FromVar->getType()); |
| 5844 | if (T.isNull()) |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5845 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5846 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5847 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5848 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5849 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5850 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5851 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5852 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5853 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5854 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5855 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5856 | |
| 5857 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5858 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5859 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5860 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5861 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5862 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5863 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5864 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5865 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5866 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5867 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5868 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5869 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5870 | // If nothing changed, just retain this statement. |
| 5871 | if (!getDerived().AlwaysRebuild() && |
| 5872 | Body.get() == S->getFinallyBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5873 | return SemaRef.Owned(S); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5874 | |
| 5875 | // Build a new statement. |
| 5876 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5877 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5878 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5879 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5880 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5881 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5882 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5883 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5884 | if (S->getThrowExpr()) { |
| 5885 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5886 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5887 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5888 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5889 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5890 | if (!getDerived().AlwaysRebuild() && |
| 5891 | Operand.get() == S->getThrowExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5892 | return getSema().Owned(S); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5893 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5894 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5895 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5896 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5897 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5898 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5899 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5901 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5902 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5903 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5904 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5905 | Object = |
| 5906 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5907 | Object.get()); |
| 5908 | if (Object.isInvalid()) |
| 5909 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5910 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5911 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5912 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5913 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5914 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5915 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5916 | // If nothing change, just retain the current statement. |
| 5917 | if (!getDerived().AlwaysRebuild() && |
| 5918 | Object.get() == S->getSynchExpr() && |
| 5919 | Body.get() == S->getSynchBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5920 | return SemaRef.Owned(S); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5921 | |
| 5922 | // Build a new statement. |
| 5923 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5924 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5928 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5929 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5930 | ObjCAutoreleasePoolStmt *S) { |
| 5931 | // Transform the body. |
| 5932 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5933 | if (Body.isInvalid()) |
| 5934 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5935 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5936 | // If nothing changed, just retain this statement. |
| 5937 | if (!getDerived().AlwaysRebuild() && |
| 5938 | Body.get() == S->getSubStmt()) |
| 5939 | return SemaRef.Owned(S); |
| 5940 | |
| 5941 | // Build a new statement. |
| 5942 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5943 | S->getAtLoc(), Body.get()); |
| 5944 | } |
| 5945 | |
| 5946 | template<typename Derived> |
| 5947 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5948 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5949 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5950 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5951 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5952 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5953 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5954 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5955 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5956 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5957 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5958 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5959 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5960 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5961 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5962 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5963 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5964 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5965 | // If nothing changed, just retain this statement. |
| 5966 | if (!getDerived().AlwaysRebuild() && |
| 5967 | Element.get() == S->getElement() && |
| 5968 | Collection.get() == S->getCollection() && |
| 5969 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5970 | return SemaRef.Owned(S); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5971 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5972 | // Build a new statement. |
| 5973 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5974 | Element.get(), |
| 5975 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5976 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5977 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 5980 | template <typename Derived> |
| 5981 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5982 | // Transform the exception declaration, if any. |
| 5983 | VarDecl *Var = 0; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 5984 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 5985 | TypeSourceInfo *T = |
| 5986 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5987 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5988 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5989 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 5990 | Var = getDerived().RebuildExceptionDecl( |
| 5991 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 5992 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5993 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5994 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5996 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5997 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5998 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5999 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6000 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6001 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6002 | if (!getDerived().AlwaysRebuild() && !Var && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6003 | Handler.get() == S->getHandlerBlock()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6004 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6005 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6006 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6007 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6008 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6009 | template <typename Derived> |
| 6010 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6011 | // Transform the try block itself. |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6012 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6013 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6014 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6015 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6016 | // Transform the handlers. |
| 6017 | bool HandlerChanged = false; |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6018 | SmallVector<Stmt *, 8> Handlers; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6019 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6020 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6021 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6022 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6024 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 6025 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 6026 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6027 | |
David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 6028 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6029 | !HandlerChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6030 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6031 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6032 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6033 | Handlers); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6035 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6036 | template<typename Derived> |
| 6037 | StmtResult |
| 6038 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6039 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 6040 | if (Range.isInvalid()) |
| 6041 | return StmtError(); |
| 6042 | |
| 6043 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 6044 | if (BeginEnd.isInvalid()) |
| 6045 | return StmtError(); |
| 6046 | |
| 6047 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 6048 | if (Cond.isInvalid()) |
| 6049 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6050 | if (Cond.get()) |
| 6051 | Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); |
| 6052 | if (Cond.isInvalid()) |
| 6053 | return StmtError(); |
| 6054 | if (Cond.get()) |
| 6055 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6056 | |
| 6057 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 6058 | if (Inc.isInvalid()) |
| 6059 | return StmtError(); |
Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 6060 | if (Inc.get()) |
| 6061 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6062 | |
| 6063 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 6064 | if (LoopVar.isInvalid()) |
| 6065 | return StmtError(); |
| 6066 | |
| 6067 | StmtResult NewStmt = S; |
| 6068 | if (getDerived().AlwaysRebuild() || |
| 6069 | Range.get() != S->getRangeStmt() || |
| 6070 | BeginEnd.get() != S->getBeginEndStmt() || |
| 6071 | Cond.get() != S->getCond() || |
| 6072 | Inc.get() != S->getInc() || |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6073 | LoopVar.get() != S->getLoopVarStmt()) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6074 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6075 | S->getColonLoc(), Range.get(), |
| 6076 | BeginEnd.get(), Cond.get(), |
| 6077 | Inc.get(), LoopVar.get(), |
| 6078 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6079 | if (NewStmt.isInvalid()) |
| 6080 | return StmtError(); |
| 6081 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6082 | |
| 6083 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 6084 | if (Body.isInvalid()) |
| 6085 | return StmtError(); |
| 6086 | |
| 6087 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 6088 | // it now so we have a new statement to attach the body to. |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6089 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6090 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 6091 | S->getColonLoc(), Range.get(), |
| 6092 | BeginEnd.get(), Cond.get(), |
| 6093 | Inc.get(), LoopVar.get(), |
| 6094 | S->getRParenLoc()); |
Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 6095 | if (NewStmt.isInvalid()) |
| 6096 | return StmtError(); |
| 6097 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 6098 | |
| 6099 | if (NewStmt.get() == S) |
| 6100 | return SemaRef.Owned(S); |
| 6101 | |
| 6102 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 6103 | } |
| 6104 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6105 | template<typename Derived> |
| 6106 | StmtResult |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6107 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 6108 | MSDependentExistsStmt *S) { |
| 6109 | // Transform the nested-name-specifier, if any. |
| 6110 | NestedNameSpecifierLoc QualifierLoc; |
| 6111 | if (S->getQualifierLoc()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6112 | QualifierLoc |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6113 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 6114 | if (!QualifierLoc) |
| 6115 | return StmtError(); |
| 6116 | } |
| 6117 | |
| 6118 | // Transform the declaration name. |
| 6119 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 6120 | if (NameInfo.getName()) { |
| 6121 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6122 | if (!NameInfo.getName()) |
| 6123 | return StmtError(); |
| 6124 | } |
| 6125 | |
| 6126 | // Check whether anything changed. |
| 6127 | if (!getDerived().AlwaysRebuild() && |
| 6128 | QualifierLoc == S->getQualifierLoc() && |
| 6129 | NameInfo.getName() == S->getNameInfo().getName()) |
| 6130 | return S; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6131 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6132 | // Determine whether this name exists, if we can. |
| 6133 | CXXScopeSpec SS; |
| 6134 | SS.Adopt(QualifierLoc); |
| 6135 | bool Dependent = false; |
| 6136 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { |
| 6137 | case Sema::IER_Exists: |
| 6138 | if (S->isIfExists()) |
| 6139 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6140 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6141 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 6142 | |
| 6143 | case Sema::IER_DoesNotExist: |
| 6144 | if (S->isIfNotExists()) |
| 6145 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6146 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6147 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6148 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6149 | case Sema::IER_Dependent: |
| 6150 | Dependent = true; |
| 6151 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6152 | |
Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 6153 | case Sema::IER_Error: |
| 6154 | return StmtError(); |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6155 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6156 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6157 | // We need to continue with the instantiation, so do so now. |
| 6158 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 6159 | if (SubStmt.isInvalid()) |
| 6160 | return StmtError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6161 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6162 | // If we have resolved the name, just transform to the substatement. |
| 6163 | if (!Dependent) |
| 6164 | return SubStmt; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6165 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 6166 | // The name is still dependent, so build a dependent expression again. |
| 6167 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 6168 | S->isIfExists(), |
| 6169 | QualifierLoc, |
| 6170 | NameInfo, |
| 6171 | SubStmt.get()); |
| 6172 | } |
| 6173 | |
| 6174 | template<typename Derived> |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 6175 | ExprResult |
| 6176 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 6177 | NestedNameSpecifierLoc QualifierLoc; |
| 6178 | if (E->getQualifierLoc()) { |
| 6179 | QualifierLoc |
| 6180 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6181 | if (!QualifierLoc) |
| 6182 | return ExprError(); |
| 6183 | } |
| 6184 | |
| 6185 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 6186 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 6187 | if (!PD) |
| 6188 | return ExprError(); |
| 6189 | |
| 6190 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 6191 | if (Base.isInvalid()) |
| 6192 | return ExprError(); |
| 6193 | |
| 6194 | return new (SemaRef.getASTContext()) |
| 6195 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 6196 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 6197 | QualifierLoc, E->getMemberLoc()); |
| 6198 | } |
| 6199 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6200 | template <typename Derived> |
| 6201 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6202 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6203 | if (TryBlock.isInvalid()) |
| 6204 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6205 | |
| 6206 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6207 | if (Handler.isInvalid()) |
| 6208 | return StmtError(); |
| 6209 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6210 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 6211 | Handler.get() == S->getHandler()) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6212 | return SemaRef.Owned(S); |
| 6213 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6214 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 6215 | TryBlock.take(), Handler.take()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6216 | } |
| 6217 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6218 | template <typename Derived> |
| 6219 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6220 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6221 | if (Block.isInvalid()) |
| 6222 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6223 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6224 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take()); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6225 | } |
| 6226 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6227 | template <typename Derived> |
| 6228 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6229 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6230 | if (FilterExpr.isInvalid()) |
| 6231 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6232 | |
David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 6233 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6234 | if (Block.isInvalid()) |
| 6235 | return StmtError(); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6236 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6237 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(), |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6238 | Block.take()); |
| 6239 | } |
| 6240 | |
David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 6241 | template <typename Derived> |
| 6242 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 6243 | if (isa<SEHFinallyStmt>(Handler)) |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 6244 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 6245 | else |
| 6246 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 6247 | } |
| 6248 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6249 | template<typename Derived> |
| 6250 | StmtResult |
| 6251 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6252 | DeclarationNameInfo DirName; |
| 6253 | getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0); |
| 6254 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6255 | // Transform the clauses |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6256 | llvm::SmallVector<OMPClause *, 16> TClauses; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6257 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 6258 | TClauses.reserve(Clauses.size()); |
| 6259 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6260 | I != E; ++I) { |
| 6261 | if (*I) { |
| 6262 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6263 | if (!Clause) { |
| 6264 | getSema().EndOpenMPDSABlock(0); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6265 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6266 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6267 | TClauses.push_back(Clause); |
| 6268 | } |
| 6269 | else { |
| 6270 | TClauses.push_back(0); |
| 6271 | } |
| 6272 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6273 | if (!D->getAssociatedStmt()) { |
| 6274 | getSema().EndOpenMPDSABlock(0); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6275 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6276 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6277 | StmtResult AssociatedStmt = |
| 6278 | getDerived().TransformStmt(D->getAssociatedStmt()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6279 | if (AssociatedStmt.isInvalid()) { |
| 6280 | getSema().EndOpenMPDSABlock(0); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6281 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6282 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6283 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6284 | StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses, |
| 6285 | AssociatedStmt.take(), |
| 6286 | D->getLocStart(), |
| 6287 | D->getLocEnd()); |
| 6288 | getSema().EndOpenMPDSABlock(Res.get()); |
| 6289 | return Res; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | template<typename Derived> |
| 6293 | OMPClause * |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6294 | TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
| 6295 | return getDerived().RebuildOMPIfClause(C->getCondition(), C->getLocStart(), |
| 6296 | C->getLParenLoc(), C->getLocEnd()); |
| 6297 | } |
| 6298 | |
| 6299 | template<typename Derived> |
| 6300 | OMPClause * |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6301 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| 6302 | return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(), |
| 6303 | C->getDefaultKindKwLoc(), |
| 6304 | C->getLocStart(), |
| 6305 | C->getLParenLoc(), |
| 6306 | C->getLocEnd()); |
| 6307 | } |
| 6308 | |
| 6309 | template<typename Derived> |
| 6310 | OMPClause * |
| 6311 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6312 | llvm::SmallVector<Expr *, 16> Vars; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6313 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 6314 | for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(), |
| 6315 | E = C->varlist_end(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6316 | I != E; ++I) { |
| 6317 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6318 | if (EVar.isInvalid()) |
| 6319 | return 0; |
| 6320 | Vars.push_back(EVar.take()); |
| 6321 | } |
| 6322 | return getDerived().RebuildOMPPrivateClause(Vars, |
| 6323 | C->getLocStart(), |
| 6324 | C->getLParenLoc(), |
| 6325 | C->getLocEnd()); |
| 6326 | } |
| 6327 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6328 | template<typename Derived> |
| 6329 | OMPClause * |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6330 | TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 6331 | OMPFirstprivateClause *C) { |
| 6332 | llvm::SmallVector<Expr *, 16> Vars; |
| 6333 | Vars.reserve(C->varlist_size()); |
| 6334 | for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(), |
| 6335 | E = C->varlist_end(); |
| 6336 | I != E; ++I) { |
| 6337 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I)); |
| 6338 | if (EVar.isInvalid()) |
| 6339 | return 0; |
| 6340 | Vars.push_back(EVar.take()); |
| 6341 | } |
| 6342 | return getDerived().RebuildOMPFirstprivateClause(Vars, |
| 6343 | C->getLocStart(), |
| 6344 | C->getLParenLoc(), |
| 6345 | C->getLocEnd()); |
| 6346 | } |
| 6347 | |
| 6348 | template<typename Derived> |
| 6349 | OMPClause * |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6350 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 6351 | llvm::SmallVector<Expr *, 16> Vars; |
| 6352 | Vars.reserve(C->varlist_size()); |
Alexey Bataev | 756c196 | 2013-09-24 03:17:45 +0000 | [diff] [blame] | 6353 | for (OMPSharedClause::varlist_iterator I = C->varlist_begin(), |
| 6354 | E = C->varlist_end(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 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().RebuildOMPSharedClause(Vars, |
| 6362 | C->getLocStart(), |
| 6363 | C->getLParenLoc(), |
| 6364 | C->getLocEnd()); |
| 6365 | } |
| 6366 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6367 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6368 | // Expression transformation |
| 6369 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6370 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6371 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6372 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6373 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6374 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6375 | |
| 6376 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6377 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6378 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6379 | NestedNameSpecifierLoc QualifierLoc; |
| 6380 | if (E->getQualifierLoc()) { |
| 6381 | QualifierLoc |
| 6382 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6383 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6384 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6385 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6386 | |
| 6387 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6388 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6389 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6390 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6391 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6392 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6393 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 6394 | if (NameInfo.getName()) { |
| 6395 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 6396 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6397 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 6398 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6399 | |
| 6400 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6401 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6402 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6403 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6404 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6405 | |
| 6406 | // Mark it referenced in the new context regardless. |
| 6407 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6408 | SemaRef.MarkDeclRefReferenced(E); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6409 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6410 | return SemaRef.Owned(E); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 6411 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6412 | |
| 6413 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6414 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6415 | TemplateArgs = &TransArgs; |
| 6416 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6417 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6418 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6419 | E->getNumTemplateArgs(), |
| 6420 | TransArgs)) |
| 6421 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 6422 | } |
| 6423 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6424 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6425 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6428 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6429 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6430 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6431 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6433 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6434 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6435 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6436 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6437 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6439 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6440 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6441 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6442 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6443 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6445 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6446 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6447 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6448 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6449 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6450 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6451 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6452 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6453 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6454 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6455 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6456 | } |
| 6457 | |
| 6458 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6459 | ExprResult |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6460 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 6461 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 6462 | SemaRef.MarkFunctionReferenced(E->getLocStart(), FD); |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 6463 | return SemaRef.MaybeBindToTemporary(E); |
| 6464 | } |
| 6465 | |
| 6466 | template<typename Derived> |
| 6467 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6468 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 6469 | ExprResult ControllingExpr = |
| 6470 | getDerived().TransformExpr(E->getControllingExpr()); |
| 6471 | if (ControllingExpr.isInvalid()) |
| 6472 | return ExprError(); |
| 6473 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6474 | SmallVector<Expr *, 4> AssocExprs; |
| 6475 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6476 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 6477 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 6478 | if (TS) { |
| 6479 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 6480 | if (!AssocType) |
| 6481 | return ExprError(); |
| 6482 | AssocTypes.push_back(AssocType); |
| 6483 | } else { |
| 6484 | AssocTypes.push_back(0); |
| 6485 | } |
| 6486 | |
| 6487 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 6488 | if (AssocExpr.isInvalid()) |
| 6489 | return ExprError(); |
| 6490 | AssocExprs.push_back(AssocExpr.release()); |
| 6491 | } |
| 6492 | |
| 6493 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 6494 | E->getDefaultLoc(), |
| 6495 | E->getRParenLoc(), |
| 6496 | ControllingExpr.release(), |
Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 6497 | AssocTypes, |
| 6498 | AssocExprs); |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | template<typename Derived> |
| 6502 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6503 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6504 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6505 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6506 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6507 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6508 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6509 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6511 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6512 | E->getRParen()); |
| 6513 | } |
| 6514 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 6515 | /// \brief The operand of a unary address-of operator has special rules: it's |
| 6516 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 6517 | /// object available. |
| 6518 | template<typename Derived> |
| 6519 | ExprResult |
| 6520 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 6521 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 6522 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true); |
| 6523 | else |
| 6524 | return getDerived().TransformExpr(E); |
| 6525 | } |
| 6526 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6527 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6528 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6529 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 6530 | ExprResult SubExpr; |
| 6531 | if (E->getOpcode() == UO_AddrOf) |
| 6532 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 6533 | else |
| 6534 | SubExpr = TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6535 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6536 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6537 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6538 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6539 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6540 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6541 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 6542 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6543 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6546 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6547 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6548 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 6549 | // Transform the type. |
| 6550 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6551 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6552 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6553 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6554 | // Transform all of the components into components similar to what the |
| 6555 | // parser uses. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6556 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 6557 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 6558 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6559 | // template code that we don't care. |
| 6560 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6561 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6562 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6563 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6564 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 6565 | const Node &ON = E->getComponent(I); |
| 6566 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 6567 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 6568 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 6569 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6570 | switch (ON.getKind()) { |
| 6571 | case Node::Array: { |
| 6572 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6573 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6574 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6575 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6576 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6577 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 6578 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6579 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6580 | break; |
| 6581 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6582 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6583 | case Node::Field: |
| 6584 | case Node::Identifier: |
| 6585 | Comp.isBrackets = false; |
| 6586 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 6587 | if (!Comp.U.IdentInfo) |
| 6588 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6589 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6590 | break; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6591 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 6592 | case Node::Base: |
| 6593 | // Will be recomputed during the rebuild. |
| 6594 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6595 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6596 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6597 | Components.push_back(Comp); |
| 6598 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6599 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6600 | // If nothing changed, retain the existing expression. |
| 6601 | if (!getDerived().AlwaysRebuild() && |
| 6602 | Type == E->getTypeSourceInfo() && |
| 6603 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6604 | return SemaRef.Owned(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6605 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 6606 | // Build a new offsetof expression. |
| 6607 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 6608 | Components.data(), Components.size(), |
| 6609 | E->getRParenLoc()); |
| 6610 | } |
| 6611 | |
| 6612 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6613 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 6614 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6615 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 6616 | "opaque value expression requires transformation"); |
| 6617 | return SemaRef.Owned(E); |
| 6618 | } |
| 6619 | |
| 6620 | template<typename Derived> |
| 6621 | ExprResult |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6622 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 6623 | // Rebuild the syntactic form. The original syntactic form has |
| 6624 | // opaque-value expressions in it, so strip those away and rebuild |
| 6625 | // the result. This is a really awful way of doing this, but the |
| 6626 | // better solution (rebuilding the semantic expressions and |
| 6627 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 6628 | // TreeTransform to not strip away implicit conversions. |
| 6629 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 6630 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 6631 | if (result.isInvalid()) return ExprError(); |
| 6632 | |
| 6633 | // If that gives us a pseudo-object result back, the pseudo-object |
| 6634 | // expression must have been an lvalue-to-rvalue conversion which we |
| 6635 | // should reapply. |
| 6636 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 6637 | result = SemaRef.checkPseudoObjectRValue(result.take()); |
| 6638 | |
| 6639 | return result; |
| 6640 | } |
| 6641 | |
| 6642 | template<typename Derived> |
| 6643 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6644 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 6645 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6646 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6647 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6648 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 6649 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6650 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6651 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6652 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 6653 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6654 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6655 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6656 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 6657 | E->getKind(), |
| 6658 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6661 | // C++0x [expr.sizeof]p1: |
| 6662 | // The operand is either an expression, which is an unevaluated operand |
| 6663 | // [...] |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 6664 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 6665 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6666 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6667 | ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 6668 | if (SubExpr.isInvalid()) |
| 6669 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6670 | |
Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 6671 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 6672 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6673 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6674 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6675 | E->getOperatorLoc(), |
| 6676 | E->getKind(), |
| 6677 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6680 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6681 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6682 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6683 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6684 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6685 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6686 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6687 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6688 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6689 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6690 | |
| 6691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6692 | if (!getDerived().AlwaysRebuild() && |
| 6693 | LHS.get() == E->getLHS() && |
| 6694 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6695 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6696 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6697 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6698 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6699 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6700 | E->getRBracketLoc()); |
| 6701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6702 | |
| 6703 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6704 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6705 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6706 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6707 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6708 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6709 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6710 | |
| 6711 | // Transform arguments. |
| 6712 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6713 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6714 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6715 | &ArgChanged)) |
| 6716 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6718 | if (!getDerived().AlwaysRebuild() && |
| 6719 | Callee.get() == E->getCallee() && |
| 6720 | !ArgChanged) |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 6721 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6722 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6723 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6724 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6725 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6726 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6727 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6728 | E->getRParenLoc()); |
| 6729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6730 | |
| 6731 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6732 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6733 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6734 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6735 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6736 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6737 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6738 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6739 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6740 | QualifierLoc |
| 6741 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6742 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6743 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6744 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6745 | } |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6746 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6747 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6748 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6749 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6750 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6751 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6752 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6753 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6754 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6755 | if (FoundDecl == E->getMemberDecl()) { |
| 6756 | FoundDecl = Member; |
| 6757 | } else { |
| 6758 | FoundDecl = cast_or_null<NamedDecl>( |
| 6759 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6760 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6761 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6762 | } |
| 6763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6764 | if (!getDerived().AlwaysRebuild() && |
| 6765 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6766 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6767 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6768 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6769 | !E->hasExplicitTemplateArgs()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6770 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6771 | // Mark it referenced in the new context regardless. |
| 6772 | // FIXME: this is a bit instantiation-specific. |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 6773 | SemaRef.MarkMemberReferenced(E); |
| 6774 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6775 | return SemaRef.Owned(E); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6776 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6777 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6778 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6779 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6780 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6781 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6782 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6783 | E->getNumTemplateArgs(), |
| 6784 | TransArgs)) |
| 6785 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6786 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6787 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6788 | // FIXME: Bogus source location for the operator |
| 6789 | SourceLocation FakeOperatorLoc |
| 6790 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6791 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6792 | // FIXME: to do this check properly, we will need to preserve the |
| 6793 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6794 | // base (and therefore couldn't do the check) and a |
| 6795 | // nested-name-qualifier (and therefore could do the lookup). |
| 6796 | NamedDecl *FirstQualifierInScope = 0; |
| 6797 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6798 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6799 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6800 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 6801 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6802 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6803 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6804 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6805 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6806 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6807 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6809 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6810 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6811 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6812 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6813 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6814 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6815 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6816 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6817 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6818 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6819 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6820 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6821 | if (!getDerived().AlwaysRebuild() && |
| 6822 | LHS.get() == E->getLHS() && |
| 6823 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6824 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6825 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 6826 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 6827 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 6828 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6829 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6830 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6831 | } |
| 6832 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6833 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6834 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6835 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6836 | CompoundAssignOperator *E) { |
| 6837 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6840 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6841 | ExprResult TreeTransform<Derived>:: |
| 6842 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6843 | // Just rebuild the common and RHS expressions and see whether we |
| 6844 | // get any changes. |
| 6845 | |
| 6846 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6847 | if (commonExpr.isInvalid()) |
| 6848 | return ExprError(); |
| 6849 | |
| 6850 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6851 | if (rhs.isInvalid()) |
| 6852 | return ExprError(); |
| 6853 | |
| 6854 | if (!getDerived().AlwaysRebuild() && |
| 6855 | commonExpr.get() == e->getCommon() && |
| 6856 | rhs.get() == e->getFalseExpr()) |
| 6857 | return SemaRef.Owned(e); |
| 6858 | |
| 6859 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6860 | e->getQuestionLoc(), |
| 6861 | 0, |
| 6862 | e->getColonLoc(), |
| 6863 | rhs.get()); |
| 6864 | } |
| 6865 | |
| 6866 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6867 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6868 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6869 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6870 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6871 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6872 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6873 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6874 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6875 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6876 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6877 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6878 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6879 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6880 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6881 | if (!getDerived().AlwaysRebuild() && |
| 6882 | Cond.get() == E->getCond() && |
| 6883 | LHS.get() == E->getLHS() && |
| 6884 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6885 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6886 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6887 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6888 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6889 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6890 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6891 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6893 | |
| 6894 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6895 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6896 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6897 | // Implicit casts are eliminated during transformation, since they |
| 6898 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6899 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6901 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6902 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6903 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6904 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6905 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6906 | if (!Type) |
| 6907 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6908 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6909 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6910 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6911 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6912 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6913 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6915 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6916 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6917 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6918 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6919 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6920 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6921 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6922 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6923 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6924 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6925 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6926 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6927 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6928 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6929 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6930 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6931 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6932 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6933 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6934 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6935 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6936 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6937 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6938 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6939 | Init.get() == E->getInitializer()) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 6940 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6941 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6942 | // Note: the expression type doesn't necessarily match the |
| 6943 | // type-as-written, but that's okay, because it should always be |
| 6944 | // derivable from the initializer. |
| 6945 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6946 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6947 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6948 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6950 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6951 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6952 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6953 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6954 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6955 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6956 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6958 | if (!getDerived().AlwaysRebuild() && |
| 6959 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6960 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6961 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6962 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6963 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6964 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6965 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6966 | E->getAccessorLoc(), |
| 6967 | E->getAccessor()); |
| 6968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6969 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6970 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6971 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6973 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6974 | |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6975 | SmallVector<Expr*, 4> Inits; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6976 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6977 | Inits, &InitChanged)) |
| 6978 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6980 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6981 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6982 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6983 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6984 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6986 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6987 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6988 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6989 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6990 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6991 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6992 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6993 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6994 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6995 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6996 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6997 | // transform the designators. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6998 | SmallVector<Expr*, 4> ArrayExprs; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | bool ExprChanged = false; |
| 7000 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 7001 | DEnd = E->designators_end(); |
| 7002 | D != DEnd; ++D) { |
| 7003 | if (D->isFieldDesignator()) { |
| 7004 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 7005 | D->getDotLoc(), |
| 7006 | D->getFieldLoc())); |
| 7007 | continue; |
| 7008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7010 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7011 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7012 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7013 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7014 | |
| 7015 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7016 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7018 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 7019 | ArrayExprs.push_back(Index.release()); |
| 7020 | continue; |
| 7021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7023 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7024 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7025 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 7026 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7027 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7028 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7029 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7030 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7031 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7032 | |
| 7033 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7034 | End.get(), |
| 7035 | D->getLBracketLoc(), |
| 7036 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7037 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7038 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 7039 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7040 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7041 | ArrayExprs.push_back(Start.release()); |
| 7042 | ArrayExprs.push_back(End.release()); |
| 7043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7044 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7045 | if (!getDerived().AlwaysRebuild() && |
| 7046 | Init.get() == E->getInit() && |
| 7047 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7048 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7049 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7050 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7051 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7052 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7054 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7055 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7056 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7057 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7058 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7059 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7060 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 7061 | // FIXME: Will we ever have proper type location here? Will we actually |
| 7062 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7063 | QualType T = getDerived().TransformType(E->getType()); |
| 7064 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7065 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7066 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7067 | if (!getDerived().AlwaysRebuild() && |
| 7068 | T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7069 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7071 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 7072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7073 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7074 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7075 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7076 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 7077 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 7078 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7079 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7080 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7081 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7082 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7083 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7084 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7085 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7086 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7087 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7088 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7089 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7090 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 7091 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7095 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7096 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7097 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7098 | SmallVector<Expr*, 4> Inits; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7099 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 7100 | &ArgumentChanged)) |
| 7101 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7103 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7104 | Inits, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7105 | E->getRParenLoc()); |
| 7106 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7107 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7108 | /// \brief Transform an address-of-label expression. |
| 7109 | /// |
| 7110 | /// By default, the transformation of an address-of-label expression always |
| 7111 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 7112 | /// the corresponding label statement by semantic analysis. |
| 7113 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7114 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7115 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7116 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 7117 | E->getLabel()); |
| 7118 | if (!LD) |
| 7119 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7120 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7121 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7122 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7124 | |
| 7125 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7126 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7127 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7128 | SemaRef.ActOnStartStmtExpr(); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7129 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7130 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7131 | if (SubStmt.isInvalid()) { |
| 7132 | SemaRef.ActOnStmtExprError(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7133 | return ExprError(); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7136 | if (!getDerived().AlwaysRebuild() && |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7137 | SubStmt.get() == E->getSubStmt()) { |
| 7138 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 7139 | SemaRef.ActOnStmtExprError(); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7140 | return SemaRef.MaybeBindToTemporary(E); |
John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 7141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7142 | |
| 7143 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7144 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7145 | E->getRParenLoc()); |
| 7146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7147 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7148 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7149 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7150 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7151 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7152 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7153 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7154 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7155 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7156 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7157 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7158 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7159 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7160 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7161 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7163 | if (!getDerived().AlwaysRebuild() && |
| 7164 | Cond.get() == E->getCond() && |
| 7165 | LHS.get() == E->getLHS() && |
| 7166 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7167 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7168 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7169 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7170 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7171 | E->getRParenLoc()); |
| 7172 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7173 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7174 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7175 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7176 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7177 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7178 | } |
| 7179 | |
| 7180 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7181 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7182 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7183 | switch (E->getOperator()) { |
| 7184 | case OO_New: |
| 7185 | case OO_Delete: |
| 7186 | case OO_Array_New: |
| 7187 | case OO_Array_Delete: |
| 7188 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7189 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7190 | case OO_Call: { |
| 7191 | // This is a call to an object's operator(). |
| 7192 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 7193 | |
| 7194 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7195 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7196 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7197 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7198 | |
| 7199 | // FIXME: Poor location information |
| 7200 | SourceLocation FakeLParenLoc |
| 7201 | = SemaRef.PP.getLocForEndOfToken( |
| 7202 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 7203 | |
| 7204 | // Transform the call arguments. |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7205 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7206 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7207 | Args)) |
| 7208 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7209 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7210 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7211 | Args, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7212 | E->getLocEnd()); |
| 7213 | } |
| 7214 | |
| 7215 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 7216 | case OO_##Name: |
| 7217 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 7218 | #include "clang/Basic/OperatorKinds.def" |
| 7219 | case OO_Subscript: |
| 7220 | // Handled below. |
| 7221 | break; |
| 7222 | |
| 7223 | case OO_Conditional: |
| 7224 | llvm_unreachable("conditional operator is not actually overloadable"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7225 | |
| 7226 | case OO_None: |
| 7227 | case NUM_OVERLOADED_OPERATORS: |
| 7228 | llvm_unreachable("not an overloaded operator?"); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 7229 | } |
| 7230 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7231 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7232 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7233 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7234 | |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 7235 | ExprResult First; |
| 7236 | if (E->getOperator() == OO_Amp) |
| 7237 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 7238 | else |
| 7239 | First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7240 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7241 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7242 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7243 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7244 | if (E->getNumArgs() == 2) { |
| 7245 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 7246 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7247 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7250 | if (!getDerived().AlwaysRebuild() && |
| 7251 | Callee.get() == E->getCallee() && |
| 7252 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7253 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7254 | return SemaRef.MaybeBindToTemporary(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7255 | |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 7256 | Sema::FPContractStateRAII FPContractState(getSema()); |
| 7257 | getSema().FPFeatures.fp_contract = E->isFPContractable(); |
| 7258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7259 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 7260 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7261 | Callee.get(), |
| 7262 | First.get(), |
| 7263 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7264 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7265 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7266 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7267 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7268 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7269 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7270 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7272 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7273 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7274 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 7275 | // Transform the callee. |
| 7276 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 7277 | if (Callee.isInvalid()) |
| 7278 | return ExprError(); |
| 7279 | |
| 7280 | // Transform exec config. |
| 7281 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 7282 | if (EC.isInvalid()) |
| 7283 | return ExprError(); |
| 7284 | |
| 7285 | // Transform arguments. |
| 7286 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7287 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7288 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7289 | &ArgChanged)) |
| 7290 | return ExprError(); |
| 7291 | |
| 7292 | if (!getDerived().AlwaysRebuild() && |
| 7293 | Callee.get() == E->getCallee() && |
| 7294 | !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 7295 | return SemaRef.MaybeBindToTemporary(E); |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7296 | |
| 7297 | // FIXME: Wrong source location information for the '('. |
| 7298 | SourceLocation FakeLParenLoc |
| 7299 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 7300 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7301 | Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 7302 | E->getRParenLoc(), EC.get()); |
| 7303 | } |
| 7304 | |
| 7305 | template<typename Derived> |
| 7306 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7307 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7308 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7309 | if (!Type) |
| 7310 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7311 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7312 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7313 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7314 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7315 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7317 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7318 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7319 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7320 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7321 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7322 | E->getStmtClass(), |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7323 | E->getAngleBrackets().getBegin(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7324 | Type, |
Fariborz Jahanian | f073871 | 2013-02-22 22:02:53 +0000 | [diff] [blame] | 7325 | E->getAngleBrackets().getEnd(), |
| 7326 | // FIXME. this should be '(' location |
| 7327 | E->getAngleBrackets().getEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7328 | SubExpr.get(), |
Abramo Bagnara | 9fb4386 | 2012-10-15 21:08:58 +0000 | [diff] [blame] | 7329 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7332 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7333 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7334 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 7335 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7336 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7337 | |
| 7338 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7339 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7340 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 7341 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7342 | } |
| 7343 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7344 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7345 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7346 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7347 | CXXReinterpretCastExpr *E) { |
| 7348 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7349 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7350 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7351 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7352 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7353 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 7354 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7355 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7357 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7358 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7359 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7360 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7361 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7362 | if (!Type) |
| 7363 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7364 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7365 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 7366 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7367 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7368 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7369 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7370 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7371 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7372 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7373 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7374 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 7375 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 7376 | E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7377 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7378 | E->getRParenLoc()); |
| 7379 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7380 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7381 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7382 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7383 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7384 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7385 | TypeSourceInfo *TInfo |
| 7386 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7387 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7388 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7389 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7390 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7391 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7392 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7393 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7394 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7395 | E->getLocStart(), |
| 7396 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7397 | E->getLocEnd()); |
| 7398 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7399 | |
Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 7400 | // We don't know whether the subexpression is potentially evaluated until |
| 7401 | // after we perform semantic analysis. We speculatively assume it is |
| 7402 | // unevaluated; it will get fixed later if the subexpression is in fact |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7403 | // potentially evaluated. |
Eli Friedman | 15681d6 | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 7404 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, |
| 7405 | Sema::ReuseLambdaContextDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7406 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7407 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7408 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7409 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7411 | if (!getDerived().AlwaysRebuild() && |
| 7412 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7413 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7414 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 7415 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 7416 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7417 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7418 | E->getLocEnd()); |
| 7419 | } |
| 7420 | |
| 7421 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7422 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7423 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 7424 | if (E->isTypeOperand()) { |
| 7425 | TypeSourceInfo *TInfo |
| 7426 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 7427 | if (!TInfo) |
| 7428 | return ExprError(); |
| 7429 | |
| 7430 | if (!getDerived().AlwaysRebuild() && |
| 7431 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7432 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7433 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 7434 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7435 | E->getLocStart(), |
| 7436 | TInfo, |
| 7437 | E->getLocEnd()); |
| 7438 | } |
| 7439 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7440 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7441 | |
| 7442 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 7443 | if (SubExpr.isInvalid()) |
| 7444 | return ExprError(); |
| 7445 | |
| 7446 | if (!getDerived().AlwaysRebuild() && |
| 7447 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7448 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 7449 | |
| 7450 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 7451 | E->getLocStart(), |
| 7452 | SubExpr.get(), |
| 7453 | E->getLocEnd()); |
| 7454 | } |
| 7455 | |
| 7456 | template<typename Derived> |
| 7457 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7458 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7459 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7460 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7461 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7462 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7463 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7464 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7465 | CXXNullPtrLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7466 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7467 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7468 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7469 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7470 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7471 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 7472 | QualType T = getSema().getCurrentThisType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7473 | |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7474 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 7475 | // Make sure that we capture 'this'. |
| 7476 | getSema().CheckCXXThisCapture(E->getLocStart()); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7477 | return SemaRef.Owned(E); |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 7478 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7479 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 7480 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7482 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7483 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7484 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7485 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7486 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7487 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7488 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7489 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7490 | if (!getDerived().AlwaysRebuild() && |
| 7491 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7492 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7493 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 7494 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 7495 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7496 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7497 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7498 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7499 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7500 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7501 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7502 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7503 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7504 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7505 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7506 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 7507 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7508 | Param == E->getParam()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7509 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7510 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 7511 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7512 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7513 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7514 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7515 | ExprResult |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 7516 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7517 | FieldDecl *Field |
| 7518 | = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 7519 | E->getField())); |
| 7520 | if (!Field) |
| 7521 | return ExprError(); |
| 7522 | |
| 7523 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
| 7524 | return SemaRef.Owned(E); |
| 7525 | |
| 7526 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 7527 | } |
| 7528 | |
| 7529 | template<typename Derived> |
| 7530 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7531 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 7532 | CXXScalarValueInitExpr *E) { |
| 7533 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7534 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7535 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7536 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7537 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7538 | T == E->getTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7539 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7540 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7541 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7542 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 7543 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7546 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7547 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7548 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7549 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7550 | TypeSourceInfo *AllocTypeInfo |
| 7551 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 7552 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7553 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7554 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7555 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7556 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7557 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7558 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7559 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7560 | // Transform the placement arguments (if any). |
| 7561 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7562 | SmallVector<Expr*, 8> PlacementArgs; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7563 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7564 | E->getNumPlacementArgs(), true, |
| 7565 | PlacementArgs, &ArgumentChanged)) |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7566 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7567 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7568 | // Transform the initializer (if any). |
| 7569 | Expr *OldInit = E->getInitializer(); |
| 7570 | ExprResult NewInit; |
| 7571 | if (OldInit) |
| 7572 | NewInit = getDerived().TransformExpr(OldInit); |
| 7573 | if (NewInit.isInvalid()) |
| 7574 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7575 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7576 | // Transform new operator and delete operator. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7577 | FunctionDecl *OperatorNew = 0; |
| 7578 | if (E->getOperatorNew()) { |
| 7579 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7580 | getDerived().TransformDecl(E->getLocStart(), |
| 7581 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7582 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7583 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7584 | } |
| 7585 | |
| 7586 | FunctionDecl *OperatorDelete = 0; |
| 7587 | if (E->getOperatorDelete()) { |
| 7588 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7589 | getDerived().TransformDecl(E->getLocStart(), |
| 7590 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7591 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7592 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7593 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7594 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7595 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7596 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7597 | ArraySize.get() == E->getArraySize() && |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7598 | NewInit.get() == OldInit && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7599 | OperatorNew == E->getOperatorNew() && |
| 7600 | OperatorDelete == E->getOperatorDelete() && |
| 7601 | !ArgumentChanged) { |
| 7602 | // Mark any declarations we need as referenced. |
| 7603 | // FIXME: instantiation-specific. |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7604 | if (OperatorNew) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7605 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7606 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7607 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7608 | |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7609 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7610 | QualType ElementType |
| 7611 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 7612 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 7613 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 7614 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7615 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 7616 | } |
| 7617 | } |
| 7618 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7619 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7620 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7622 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7623 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7624 | if (!ArraySize.get()) { |
| 7625 | // If no array size was specified, but the new expression was |
| 7626 | // instantiated with an array type (e.g., "new T" where T is |
| 7627 | // instantiated with "int[4]"), extract the outer bound from the |
| 7628 | // array type as our array size. We do this with constant and |
| 7629 | // dependently-sized array types. |
| 7630 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 7631 | if (!ArrayT) { |
| 7632 | // Do nothing |
| 7633 | } else if (const ConstantArrayType *ConsArrayT |
| 7634 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7635 | ArraySize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7636 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7637 | ConsArrayT->getSize(), |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7638 | SemaRef.Context.getSizeType(), |
| 7639 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7640 | AllocType = ConsArrayT->getElementType(); |
| 7641 | } else if (const DependentSizedArrayType *DepArrayT |
| 7642 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 7643 | if (DepArrayT->getSizeExpr()) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7644 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 7645 | AllocType = DepArrayT->getElementType(); |
| 7646 | } |
| 7647 | } |
| 7648 | } |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7650 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 7651 | E->isGlobalNew(), |
| 7652 | /*FIXME:*/E->getLocStart(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7653 | PlacementArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7654 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 7655 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7656 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 7657 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7658 | ArraySize.get(), |
Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 7659 | E->getDirectInitRange(), |
| 7660 | NewInit.take()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7663 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7664 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7665 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7666 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7667 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7668 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7669 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7670 | // Transform the delete operator, if known. |
| 7671 | FunctionDecl *OperatorDelete = 0; |
| 7672 | if (E->getOperatorDelete()) { |
| 7673 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7674 | getDerived().TransformDecl(E->getLocStart(), |
| 7675 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7676 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7677 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7678 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7680 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7681 | Operand.get() == E->getArgument() && |
| 7682 | OperatorDelete == E->getOperatorDelete()) { |
| 7683 | // Mark any declarations we need as referenced. |
| 7684 | // FIXME: instantiation-specific. |
| 7685 | if (OperatorDelete) |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7686 | SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7687 | |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7688 | if (!E->getArgument()->isTypeDependent()) { |
| 7689 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7690 | E->getDestroyedType()); |
| 7691 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7692 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7693 | SemaRef.MarkFunctionReferenced(E->getLocStart(), |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 7694 | SemaRef.LookupDestructor(Record)); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7695 | } |
| 7696 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7697 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7698 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7699 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7700 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7701 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7702 | E->isGlobalDelete(), |
| 7703 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7704 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7706 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7707 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7708 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7709 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7710 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7711 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7712 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7713 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7714 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7715 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7716 | bool MayBePseudoDestructor = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7717 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7718 | E->getOperatorLoc(), |
| 7719 | E->isArrow()? tok::arrow : tok::period, |
| 7720 | ObjectTypePtr, |
| 7721 | MayBePseudoDestructor); |
| 7722 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7723 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7724 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7725 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7726 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7727 | if (QualifierLoc) { |
| 7728 | QualifierLoc |
| 7729 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7730 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7731 | return ExprError(); |
| 7732 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7733 | CXXScopeSpec SS; |
| 7734 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7735 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7736 | PseudoDestructorTypeStorage Destroyed; |
| 7737 | if (E->getDestroyedTypeInfo()) { |
| 7738 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7739 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7740 | ObjectType, 0, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7741 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7742 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7743 | Destroyed = DestroyedTypeInfo; |
Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 7744 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7745 | // We aren't likely to be able to resolve the identifier down to a type |
| 7746 | // now anyway, so just retain the identifier. |
| 7747 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7748 | E->getDestroyedTypeLoc()); |
| 7749 | } else { |
| 7750 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7751 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7752 | *E->getDestroyedTypeIdentifier(), |
| 7753 | E->getDestroyedTypeLoc(), |
| 7754 | /*Scope=*/0, |
| 7755 | SS, ObjectTypePtr, |
| 7756 | false); |
| 7757 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7758 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7759 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7760 | Destroyed |
| 7761 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7762 | E->getDestroyedTypeLoc()); |
| 7763 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7764 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7765 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7766 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 7767 | CXXScopeSpec EmptySS; |
| 7768 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 7769 | E->getScopeTypeInfo(), ObjectType, 0, EmptySS); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7770 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7771 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7772 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7773 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7774 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7775 | E->getOperatorLoc(), |
| 7776 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7777 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7778 | ScopeTypeInfo, |
| 7779 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7780 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7781 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7782 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7783 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7784 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7785 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7786 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7787 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7788 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7789 | Sema::LookupOrdinaryName); |
| 7790 | |
| 7791 | // Transform all the decls. |
| 7792 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7793 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7794 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7795 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7796 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7797 | if (!InstD) { |
| 7798 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7799 | // This can happen because of dependent hiding. |
| 7800 | if (isa<UsingShadowDecl>(*I)) |
| 7801 | continue; |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7802 | else { |
| 7803 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7804 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7805 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7806 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7807 | |
| 7808 | // Expand using declarations. |
| 7809 | if (isa<UsingDecl>(InstD)) { |
| 7810 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7811 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7812 | E = UD->shadow_end(); I != E; ++I) |
| 7813 | R.addDecl(*I); |
| 7814 | continue; |
| 7815 | } |
| 7816 | |
| 7817 | R.addDecl(InstD); |
| 7818 | } |
| 7819 | |
| 7820 | // Resolve a kind, but don't do any further analysis. If it's |
| 7821 | // ambiguous, the callee needs to deal with it. |
| 7822 | R.resolveKind(); |
| 7823 | |
| 7824 | // Rebuild the nested-name qualifier, if present. |
| 7825 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7826 | if (Old->getQualifierLoc()) { |
| 7827 | NestedNameSpecifierLoc QualifierLoc |
| 7828 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7829 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7830 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7831 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7832 | SS.Adopt(QualifierLoc); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7833 | } |
| 7834 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7835 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7836 | CXXRecordDecl *NamingClass |
| 7837 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7838 | Old->getNameLoc(), |
| 7839 | Old->getNamingClass())); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7840 | if (!NamingClass) { |
| 7841 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7842 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7843 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7844 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7845 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7846 | } |
| 7847 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7848 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 7849 | |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7850 | // If we have neither explicit template arguments, nor the template keyword, |
| 7851 | // it's a normal declaration name. |
| 7852 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7853 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7854 | |
| 7855 | // If we have template arguments, rebuild them, then rebuild the |
| 7856 | // templateid expression. |
| 7857 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 7858 | if (Old->hasExplicitTemplateArgs() && |
| 7859 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7860 | Old->getNumTemplateArgs(), |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7861 | TransArgs)) { |
| 7862 | R.clear(); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7863 | return ExprError(); |
Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 7864 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7865 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 7866 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 7867 | Old->requiresADL(), &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7868 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7869 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7870 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7871 | ExprResult |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7872 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 7873 | bool ArgChanged = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7874 | SmallVector<TypeSourceInfo *, 4> Args; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7875 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 7876 | TypeSourceInfo *From = E->getArg(I); |
| 7877 | TypeLoc FromTL = From->getTypeLoc(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7878 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7879 | TypeLocBuilder TLB; |
| 7880 | TLB.reserve(FromTL.getFullDataSize()); |
| 7881 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 7882 | if (To.isNull()) |
| 7883 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7884 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7885 | if (To == From->getType()) |
| 7886 | Args.push_back(From); |
| 7887 | else { |
| 7888 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7889 | ArgChanged = true; |
| 7890 | } |
| 7891 | continue; |
| 7892 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7893 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7894 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7895 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7896 | // We have a pack expansion. Instantiate it. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 7897 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7898 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 7899 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7900 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7901 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7902 | // Determine whether the set of unexpanded parameter packs can and should |
| 7903 | // be expanded. |
| 7904 | bool Expand = true; |
| 7905 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 7906 | Optional<unsigned> OrigNumExpansions = |
| 7907 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 7908 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7909 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 7910 | PatternTL.getSourceRange(), |
| 7911 | Unexpanded, |
| 7912 | Expand, RetainExpansion, |
| 7913 | NumExpansions)) |
| 7914 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7915 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7916 | if (!Expand) { |
| 7917 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7918 | // transformation on the pack expansion, producing another pack |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7919 | // expansion. |
| 7920 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7921 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7922 | TypeLocBuilder TLB; |
| 7923 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 7924 | |
| 7925 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7926 | if (To.isNull()) |
| 7927 | return ExprError(); |
| 7928 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7929 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7930 | PatternTL.getSourceRange(), |
| 7931 | ExpansionTL.getEllipsisLoc(), |
| 7932 | NumExpansions); |
| 7933 | if (To.isNull()) |
| 7934 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7935 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7936 | PackExpansionTypeLoc ToExpansionTL |
| 7937 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7938 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7939 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7940 | continue; |
| 7941 | } |
| 7942 | |
| 7943 | // Expand the pack expansion by substituting for each argument in the |
| 7944 | // pack(s). |
| 7945 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7946 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 7947 | TypeLocBuilder TLB; |
| 7948 | TLB.reserve(PatternTL.getFullDataSize()); |
| 7949 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7950 | if (To.isNull()) |
| 7951 | return ExprError(); |
| 7952 | |
Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 7953 | if (To->containsUnexpandedParameterPack()) { |
| 7954 | To = getDerived().RebuildPackExpansionType(To, |
| 7955 | PatternTL.getSourceRange(), |
| 7956 | ExpansionTL.getEllipsisLoc(), |
| 7957 | NumExpansions); |
| 7958 | if (To.isNull()) |
| 7959 | return ExprError(); |
| 7960 | |
| 7961 | PackExpansionTypeLoc ToExpansionTL |
| 7962 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7963 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7964 | } |
| 7965 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7966 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7967 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7968 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7969 | if (!RetainExpansion) |
| 7970 | continue; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7971 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7972 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 7973 | // forgetting the partially-substituted parameter pack. |
| 7974 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7975 | |
| 7976 | TypeLocBuilder TLB; |
| 7977 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7978 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7979 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 7980 | if (To.isNull()) |
| 7981 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7982 | |
| 7983 | To = getDerived().RebuildPackExpansionType(To, |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7984 | PatternTL.getSourceRange(), |
| 7985 | ExpansionTL.getEllipsisLoc(), |
| 7986 | NumExpansions); |
| 7987 | if (To.isNull()) |
| 7988 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7989 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7990 | PackExpansionTypeLoc ToExpansionTL |
| 7991 | = TLB.push<PackExpansionTypeLoc>(To); |
| 7992 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 7993 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 7994 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7995 | |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 7996 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 7997 | return SemaRef.Owned(E); |
| 7998 | |
| 7999 | return getDerived().RebuildTypeTrait(E->getTrait(), |
| 8000 | E->getLocStart(), |
| 8001 | Args, |
| 8002 | E->getLocEnd()); |
| 8003 | } |
| 8004 | |
| 8005 | template<typename Derived> |
| 8006 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 8007 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 8008 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 8009 | if (!T) |
| 8010 | return ExprError(); |
| 8011 | |
| 8012 | if (!getDerived().AlwaysRebuild() && |
| 8013 | T == E->getQueriedTypeSourceInfo()) |
| 8014 | return SemaRef.Owned(E); |
| 8015 | |
| 8016 | ExprResult SubExpr; |
| 8017 | { |
| 8018 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8019 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 8020 | if (SubExpr.isInvalid()) |
| 8021 | return ExprError(); |
| 8022 | |
| 8023 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 8024 | return SemaRef.Owned(E); |
| 8025 | } |
| 8026 | |
| 8027 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 8028 | E->getLocStart(), |
| 8029 | T, |
| 8030 | SubExpr.get(), |
| 8031 | E->getLocEnd()); |
| 8032 | } |
| 8033 | |
| 8034 | template<typename Derived> |
| 8035 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 8036 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 8037 | ExprResult SubExpr; |
| 8038 | { |
| 8039 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 8040 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 8041 | if (SubExpr.isInvalid()) |
| 8042 | return ExprError(); |
| 8043 | |
| 8044 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 8045 | return SemaRef.Owned(E); |
| 8046 | } |
| 8047 | |
| 8048 | return getDerived().RebuildExpressionTrait( |
| 8049 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 8050 | } |
| 8051 | |
| 8052 | template<typename Derived> |
| 8053 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8054 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8055 | DependentScopeDeclRefExpr *E) { |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8056 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false); |
| 8057 | } |
| 8058 | |
| 8059 | template<typename Derived> |
| 8060 | ExprResult |
| 8061 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 8062 | DependentScopeDeclRefExpr *E, |
| 8063 | bool IsAddressOfOperand) { |
Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 8064 | assert(E->getQualifierLoc()); |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8065 | NestedNameSpecifierLoc QualifierLoc |
| 8066 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8067 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8068 | return ExprError(); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8069 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8070 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8071 | // TODO: If this is a conversion-function-id, verify that the |
| 8072 | // destination type name (if present) resolves the same way after |
| 8073 | // instantiation as it did in the local scope. |
| 8074 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8075 | DeclarationNameInfo NameInfo |
| 8076 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 8077 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8078 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8079 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 8080 | if (!E->hasExplicitTemplateArgs()) { |
| 8081 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8082 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8083 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 8084 | // if name has not changed, DNLoc has not changed either. |
| 8085 | NameInfo.getName() == E->getDeclName()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8086 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8087 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8088 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8089 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8090 | NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8091 | /*TemplateArgs*/ 0, |
| 8092 | IsAddressOfOperand); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 8093 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8094 | |
| 8095 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8096 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8097 | E->getNumTemplateArgs(), |
| 8098 | TransArgs)) |
| 8099 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8100 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 8101 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8102 | TemplateKWLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8103 | NameInfo, |
Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 8104 | &TransArgs, |
| 8105 | IsAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8106 | } |
| 8107 | |
| 8108 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8109 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8110 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8111 | // CXXConstructExprs other than for list-initialization and |
| 8112 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 8113 | // a 1-argument construction we just transform that argument. |
Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 8114 | if ((E->getNumArgs() == 1 || |
| 8115 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8116 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 8117 | !E->isListInitialization()) |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 8118 | return getDerived().TransformExpr(E->getArg(0)); |
| 8119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8120 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 8121 | |
| 8122 | QualType T = getDerived().TransformType(E->getType()); |
| 8123 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8124 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8125 | |
| 8126 | CXXConstructorDecl *Constructor |
| 8127 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8128 | getDerived().TransformDecl(E->getLocStart(), |
| 8129 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8130 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8131 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8133 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8134 | SmallVector<Expr*, 8> Args; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8135 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8136 | &ArgumentChanged)) |
| 8137 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8138 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8139 | if (!getDerived().AlwaysRebuild() && |
| 8140 | T == E->getType() && |
| 8141 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8142 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 8143 | // Mark the constructor as referenced. |
| 8144 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8145 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8146 | return SemaRef.Owned(E); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 8147 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8148 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 8149 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 8150 | Constructor, E->isElidable(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8151 | Args, |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 8152 | E->hadMultipleCandidates(), |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8153 | E->isListInitialization(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 8154 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 8155 | E->getConstructionKind(), |
Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 8156 | E->getParenOrBraceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8159 | /// \brief Transform a C++ temporary-binding expression. |
| 8160 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8161 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 8162 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8163 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8164 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8165 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8166 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8168 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8169 | /// \brief Transform a C++ expression that contains cleanups that should |
| 8170 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8171 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8172 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8173 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8174 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8175 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 8176 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 8177 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8180 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8181 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8182 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8183 | CXXTemporaryObjectExpr *E) { |
| 8184 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8185 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8186 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8187 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8188 | CXXConstructorDecl *Constructor |
| 8189 | = cast_or_null<CXXConstructorDecl>( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8190 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8191 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8192 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8193 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8194 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8195 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8196 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8197 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8198 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8199 | &ArgumentChanged)) |
| 8200 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8202 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8203 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8204 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8205 | !ArgumentChanged) { |
| 8206 | // FIXME: Instantiation-specific |
Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8207 | SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8208 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 8209 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8210 | |
Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 8211 | // FIXME: Pass in E->isListInitialization(). |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8212 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 8213 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8214 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8215 | E->getLocEnd()); |
| 8216 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8217 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8218 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8219 | ExprResult |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8220 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8221 | |
| 8222 | // Transform any init-capture expressions before entering the scope of the |
| 8223 | // lambda body, because they are not semantically within that scope. |
| 8224 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 8225 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
| 8226 | E->explicit_capture_begin()); |
| 8227 | |
| 8228 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 8229 | CEnd = E->capture_end(); |
| 8230 | C != CEnd; ++C) { |
| 8231 | if (!C->isInitCapture()) |
| 8232 | continue; |
| 8233 | EnterExpressionEvaluationContext EEEC(getSema(), |
| 8234 | Sema::PotentiallyEvaluated); |
| 8235 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 8236 | C->getCapturedVar()->getInit(), |
| 8237 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
| 8238 | |
| 8239 | if (NewExprInitResult.isInvalid()) |
| 8240 | return ExprError(); |
| 8241 | Expr *NewExprInit = NewExprInitResult.get(); |
| 8242 | |
| 8243 | VarDecl *OldVD = C->getCapturedVar(); |
| 8244 | QualType NewInitCaptureType = |
| 8245 | getSema().performLambdaInitCaptureInitialization(C->getLocation(), |
| 8246 | OldVD->getType()->isReferenceType(), OldVD->getIdentifier(), |
| 8247 | NewExprInit); |
| 8248 | NewExprInitResult = NewExprInit; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8249 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 8250 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
| 8251 | |
| 8252 | } |
| 8253 | |
Faisal Vali | 524ca28 | 2013-11-12 01:40:44 +0000 | [diff] [blame] | 8254 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8255 | // Transform the template parameters, and add them to the current |
| 8256 | // instantiation scope. The null case is handled correctly. |
| 8257 | LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList( |
| 8258 | E->getTemplateParameterList()); |
| 8259 | |
| 8260 | // Check to see if the TypeSourceInfo of the call operator needs to |
| 8261 | // be transformed, and if so do the transformation in the |
| 8262 | // CurrentInstantiationScope. |
| 8263 | |
| 8264 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 8265 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 8266 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
| 8267 | TypeSourceInfo *NewCallOpTSI = 0; |
| 8268 | |
| 8269 | const bool CallOpWasAlreadyTransformed = |
| 8270 | getDerived().AlreadyTransformed(OldCallOpTSI->getType()); |
| 8271 | |
| 8272 | // Use the Old Call Operator's TypeSourceInfo if it is already transformed. |
| 8273 | if (CallOpWasAlreadyTransformed) |
| 8274 | NewCallOpTSI = OldCallOpTSI; |
| 8275 | else { |
| 8276 | // Transform the TypeSourceInfo of the Original Lambda's Call Operator. |
| 8277 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 8278 | // it introduces a mapping of the original to the newly created |
| 8279 | // transformed parameters. |
| 8280 | |
| 8281 | TypeLocBuilder NewCallOpTLBuilder; |
| 8282 | QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder, |
| 8283 | OldCallOpFPTL, |
| 8284 | 0, 0); |
| 8285 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 8286 | NewCallOpType); |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8287 | } |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8288 | // Extract the ParmVarDecls from the NewCallOpTSI and add them to |
| 8289 | // the vector below - this will be used to synthesize the |
| 8290 | // NewCallOperator. Additionally, add the parameters of the untransformed |
| 8291 | // lambda call operator to the CurrentInstantiationScope. |
| 8292 | SmallVector<ParmVarDecl *, 4> Params; |
| 8293 | { |
| 8294 | FunctionProtoTypeLoc NewCallOpFPTL = |
| 8295 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>(); |
| 8296 | ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray(); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 8297 | const unsigned NewNumArgs = NewCallOpFPTL.getNumParams(); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8298 | |
| 8299 | for (unsigned I = 0; I < NewNumArgs; ++I) { |
| 8300 | // If this call operator's type does not require transformation, |
| 8301 | // the parameters do not get added to the current instantiation scope, |
| 8302 | // - so ADD them! This allows the following to compile when the enclosing |
| 8303 | // template is specialized and the entire lambda expression has to be |
| 8304 | // transformed. |
| 8305 | // template<class T> void foo(T t) { |
| 8306 | // auto L = [](auto a) { |
| 8307 | // auto M = [](char b) { <-- note: non-generic lambda |
| 8308 | // auto N = [](auto c) { |
| 8309 | // int x = sizeof(a); |
| 8310 | // x = sizeof(b); <-- specifically this line |
| 8311 | // x = sizeof(c); |
| 8312 | // }; |
| 8313 | // }; |
| 8314 | // }; |
| 8315 | // } |
| 8316 | // foo('a') |
| 8317 | if (CallOpWasAlreadyTransformed) |
| 8318 | getDerived().transformedLocalDecl(NewParamDeclArray[I], |
| 8319 | NewParamDeclArray[I]); |
| 8320 | // Add to Params array, so these parameters can be used to create |
| 8321 | // the newly transformed call operator. |
| 8322 | Params.push_back(NewParamDeclArray[I]); |
| 8323 | } |
| 8324 | } |
| 8325 | |
| 8326 | if (!NewCallOpTSI) |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8327 | return ExprError(); |
| 8328 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8329 | // Create the local class that will describe the lambda. |
| 8330 | CXXRecordDecl *Class |
| 8331 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8332 | NewCallOpTSI, |
Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 8333 | /*KnownDependent=*/false, |
| 8334 | E->getCaptureDefault()); |
| 8335 | |
Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 8336 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 8337 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8338 | // Build the call operator. |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8339 | CXXMethodDecl *NewCallOperator |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8340 | = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8341 | NewCallOpTSI, |
Douglas Gregor | adb376e | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 8342 | E->getCallOperator()->getLocEnd(), |
Richard Smith | 505df23 | 2012-07-22 23:45:10 +0000 | [diff] [blame] | 8343 | Params); |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8344 | LSI->CallOperator = NewCallOperator; |
Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 8345 | |
Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 8346 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 8347 | |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8348 | return getDerived().TransformLambdaScope(E, NewCallOperator, |
| 8349 | InitCaptureExprsAndTypes); |
Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | template<typename Derived> |
| 8353 | ExprResult |
| 8354 | TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8355 | CXXMethodDecl *CallOperator, |
| 8356 | ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8357 | bool Invalid = false; |
| 8358 | |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8359 | // Introduce the context of the call operator. |
Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 8360 | Sema::ContextRAII SavedContext(getSema(), CallOperator, |
| 8361 | /*NewThisContext*/false); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8362 | |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8363 | LambdaScopeInfo *const LSI = getSema().getCurLambda(); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8364 | // Enter the scope of the lambda. |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 8365 | getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8366 | E->getCaptureDefault(), |
James Dennett | ddd36ff | 2013-08-09 23:08:25 +0000 | [diff] [blame] | 8367 | E->getCaptureDefaultLoc(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8368 | E->hasExplicitParameters(), |
| 8369 | E->hasExplicitResultType(), |
| 8370 | E->isMutable()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8371 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8372 | // Transform captures. |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8373 | bool FinishedExplicitCaptures = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8374 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8375 | CEnd = E->capture_end(); |
| 8376 | C != CEnd; ++C) { |
| 8377 | // When we hit the first implicit capture, tell Sema that we've finished |
| 8378 | // the list of explicit captures. |
| 8379 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 8380 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8381 | FinishedExplicitCaptures = true; |
| 8382 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8383 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8384 | // Capturing 'this' is trivial. |
| 8385 | if (C->capturesThis()) { |
| 8386 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); |
| 8387 | continue; |
| 8388 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8389 | |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8390 | // Rebuild init-captures, including the implied field declaration. |
| 8391 | if (C->isInitCapture()) { |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8392 | |
| 8393 | InitCaptureInfoTy InitExprTypePair = |
| 8394 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 8395 | ExprResult Init = InitExprTypePair.first; |
| 8396 | QualType InitQualType = InitExprTypePair.second; |
| 8397 | if (Init.isInvalid() || InitQualType.isNull()) { |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8398 | Invalid = true; |
| 8399 | continue; |
| 8400 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8401 | VarDecl *OldVD = C->getCapturedVar(); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8402 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 8403 | OldVD->getLocation(), InitExprTypePair.second, |
| 8404 | OldVD->getIdentifier(), Init.get()); |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8405 | if (!NewVD) |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8406 | Invalid = true; |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8407 | else { |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8408 | getDerived().transformedLocalDecl(OldVD, NewVD); |
Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 8409 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 8410 | getSema().buildInitCaptureField(LSI, NewVD); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8411 | continue; |
| 8412 | } |
| 8413 | |
| 8414 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 8415 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8416 | // Determine the capture kind for Sema. |
| 8417 | Sema::TryCaptureKind Kind |
| 8418 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 8419 | : C->getCaptureKind() == LCK_ByCopy |
| 8420 | ? Sema::TryCapture_ExplicitByVal |
| 8421 | : Sema::TryCapture_ExplicitByRef; |
| 8422 | SourceLocation EllipsisLoc; |
| 8423 | if (C->isPackExpansion()) { |
| 8424 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 8425 | bool ShouldExpand = false; |
| 8426 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8427 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8428 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 8429 | C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8430 | Unexpanded, |
| 8431 | ShouldExpand, RetainExpansion, |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 8432 | NumExpansions)) { |
| 8433 | Invalid = true; |
| 8434 | continue; |
| 8435 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8436 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8437 | if (ShouldExpand) { |
| 8438 | // The transform has determined that we should perform an expansion; |
| 8439 | // transform and capture each of the arguments. |
| 8440 | // expansion of the pattern. Do so. |
| 8441 | VarDecl *Pack = C->getCapturedVar(); |
| 8442 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8443 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8444 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8445 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8446 | Pack)); |
| 8447 | if (!CapturedVar) { |
| 8448 | Invalid = true; |
| 8449 | continue; |
| 8450 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8451 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8452 | // Capture the transformed variable. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8453 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 8454 | } |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8455 | continue; |
| 8456 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8457 | |
Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 8458 | EllipsisLoc = C->getEllipsisLoc(); |
| 8459 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8460 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8461 | // Transform the captured variable. |
| 8462 | VarDecl *CapturedVar |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8463 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8464 | C->getCapturedVar())); |
| 8465 | if (!CapturedVar) { |
| 8466 | Invalid = true; |
| 8467 | continue; |
| 8468 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8469 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8470 | // Capture the transformed variable. |
Douglas Gregor | fdf598e | 2012-02-18 09:37:24 +0000 | [diff] [blame] | 8471 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8472 | } |
| 8473 | if (!FinishedExplicitCaptures) |
| 8474 | getSema().finishLambdaExplicitCaptures(LSI); |
| 8475 | |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8476 | |
| 8477 | // Enter a new evaluation context to insulate the lambda from any |
| 8478 | // cleanups from the enclosing full-expression. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8479 | getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8480 | |
| 8481 | if (Invalid) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8482 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 8483 | /*IsInstantiation=*/true); |
| 8484 | return ExprError(); |
| 8485 | } |
| 8486 | |
| 8487 | // Instantiate the body of the lambda expression. |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8488 | StmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 8489 | if (Body.isInvalid()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8490 | getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8491 | /*IsInstantiation=*/true); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8492 | return ExprError(); |
Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 8493 | } |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 8494 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8495 | return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), |
Douglas Gregor | b61e809 | 2012-04-04 17:40:10 +0000 | [diff] [blame] | 8496 | /*CurScope=*/0, /*IsInstantiation=*/true); |
Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 8497 | } |
| 8498 | |
| 8499 | template<typename Derived> |
| 8500 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8501 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8502 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8503 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 8504 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8505 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8507 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 8508 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8509 | Args.reserve(E->arg_size()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8510 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 8511 | &ArgumentChanged)) |
| 8512 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8513 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8514 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8515 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8516 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8517 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8518 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8519 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 8520 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8521 | E->getLParenLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 8522 | Args, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8523 | E->getRParenLoc()); |
| 8524 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8526 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8527 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 8528 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8529 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8530 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8531 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8532 | Expr *OldBase; |
| 8533 | QualType BaseType; |
| 8534 | QualType ObjectType; |
| 8535 | if (!E->isImplicitAccess()) { |
| 8536 | OldBase = E->getBase(); |
| 8537 | Base = getDerived().TransformExpr(OldBase); |
| 8538 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8539 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8540 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8541 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8542 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8543 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8544 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8545 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8546 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 8547 | ObjectTy, |
| 8548 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8549 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8550 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8551 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8552 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8553 | BaseType = ((Expr*) Base.get())->getType(); |
| 8554 | } else { |
| 8555 | OldBase = 0; |
| 8556 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 8557 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 8558 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8559 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8560 | // Transform the first part of the nested-name-specifier that qualifies |
| 8561 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 8562 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 8563 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8564 | E->getFirstQualifierFoundInScope(), |
| 8565 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8566 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8567 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8568 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8569 | QualifierLoc |
| 8570 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 8571 | ObjectType, |
| 8572 | FirstQualifierInScope); |
| 8573 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8574 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 8575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8576 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8577 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 8578 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8579 | // TODO: If this is a conversion-function-id, verify that the |
| 8580 | // destination type name (if present) resolves the same way after |
| 8581 | // instantiation as it did in the local scope. |
| 8582 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8583 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8584 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8585 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8586 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8587 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8588 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8589 | // This is a reference to a member without an explicitly-specified |
| 8590 | // template argument list. Optimize for this common case. |
| 8591 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8592 | Base.get() == OldBase && |
| 8593 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8594 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8595 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8596 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8597 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8598 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8599 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8600 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8601 | E->isArrow(), |
| 8602 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8603 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8604 | TemplateKWLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8605 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8606 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8607 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8608 | } |
| 8609 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8610 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8611 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8612 | E->getNumTemplateArgs(), |
| 8613 | TransArgs)) |
| 8614 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8615 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8616 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8617 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8618 | E->isArrow(), |
| 8619 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 8620 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8621 | TemplateKWLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 8622 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8623 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8624 | &TransArgs); |
| 8625 | } |
| 8626 | |
| 8627 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8628 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8629 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8630 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8631 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8632 | QualType BaseType; |
| 8633 | if (!Old->isImplicitAccess()) { |
| 8634 | Base = getDerived().TransformExpr(Old->getBase()); |
| 8635 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8636 | return ExprError(); |
Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 8637 | Base = getSema().PerformMemberExprBaseConversion(Base.take(), |
| 8638 | Old->isArrow()); |
| 8639 | if (Base.isInvalid()) |
| 8640 | return ExprError(); |
| 8641 | BaseType = Base.get()->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8642 | } else { |
| 8643 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 8644 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8645 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8646 | NestedNameSpecifierLoc QualifierLoc; |
| 8647 | if (Old->getQualifierLoc()) { |
| 8648 | QualifierLoc |
| 8649 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 8650 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8651 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8652 | } |
| 8653 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8654 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 8655 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8656 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8657 | Sema::LookupOrdinaryName); |
| 8658 | |
| 8659 | // Transform all the decls. |
| 8660 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 8661 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8662 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 8663 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 8664 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8665 | if (!InstD) { |
| 8666 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 8667 | // This can happen because of dependent hiding. |
| 8668 | if (isa<UsingShadowDecl>(*I)) |
| 8669 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8670 | else { |
| 8671 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8672 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 8673 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 8674 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8675 | |
| 8676 | // Expand using declarations. |
| 8677 | if (isa<UsingDecl>(InstD)) { |
| 8678 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 8679 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 8680 | E = UD->shadow_end(); I != E; ++I) |
| 8681 | R.addDecl(*I); |
| 8682 | continue; |
| 8683 | } |
| 8684 | |
| 8685 | R.addDecl(InstD); |
| 8686 | } |
| 8687 | |
| 8688 | R.resolveKind(); |
| 8689 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8690 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 8691 | if (Old->getNamingClass()) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8692 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8693 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8694 | Old->getMemberLoc(), |
| 8695 | Old->getNamingClass())); |
| 8696 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8697 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8698 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 8699 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 8700 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8701 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8702 | TemplateArgumentListInfo TransArgs; |
| 8703 | if (Old->hasExplicitTemplateArgs()) { |
| 8704 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 8705 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8706 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 8707 | Old->getNumTemplateArgs(), |
| 8708 | TransArgs)) |
| 8709 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8710 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8711 | |
| 8712 | // FIXME: to do this check properly, we will need to preserve the |
| 8713 | // first-qualifier-in-scope here, just in case we had a dependent |
| 8714 | // base (and therefore couldn't do the check) and a |
| 8715 | // nested-name-qualifier (and therefore could do the lookup). |
| 8716 | NamedDecl *FirstQualifierInScope = 0; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8717 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8718 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 8719 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8720 | Old->getOperatorLoc(), |
| 8721 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 8722 | QualifierLoc, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 8723 | TemplateKWLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 8724 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 8725 | R, |
| 8726 | (Old->hasExplicitTemplateArgs() |
| 8727 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8728 | } |
| 8729 | |
| 8730 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8731 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8732 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 8733 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8734 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 8735 | if (SubExpr.isInvalid()) |
| 8736 | return ExprError(); |
| 8737 | |
| 8738 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8739 | return SemaRef.Owned(E); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 8740 | |
| 8741 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 8742 | } |
| 8743 | |
| 8744 | template<typename Derived> |
| 8745 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8746 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8747 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 8748 | if (Pattern.isInvalid()) |
| 8749 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8750 | |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 8751 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 8752 | return SemaRef.Owned(E); |
| 8753 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 8754 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 8755 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8756 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8757 | |
| 8758 | template<typename Derived> |
| 8759 | ExprResult |
| 8760 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 8761 | // If E is not value-dependent, then nothing will change when we transform it. |
| 8762 | // Note: This is an instantiation-centric view. |
| 8763 | if (!E->isValueDependent()) |
| 8764 | return SemaRef.Owned(E); |
| 8765 | |
| 8766 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 8767 | // produce a diagnostic when given only a single unexpanded parameter pack, |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8768 | // so |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8769 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 8770 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8771 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8772 | Optional<unsigned> NumExpansions; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8773 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 8774 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 8775 | ShouldExpand, RetainExpansion, |
| 8776 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8777 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8778 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8779 | if (RetainExpansion) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8780 | return SemaRef.Owned(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8781 | |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8782 | NamedDecl *Pack = E->getPack(); |
| 8783 | if (!ShouldExpand) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8784 | Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8785 | Pack)); |
| 8786 | if (!Pack) |
| 8787 | return ExprError(); |
| 8788 | } |
| 8789 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8790 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8791 | // We now know the length of the parameter pack, so build a new expression |
| 8792 | // that stores that length. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8793 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 8794 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 8795 | NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 8796 | } |
| 8797 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 8798 | template<typename Derived> |
| 8799 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 8800 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 8801 | SubstNonTypeTemplateParmPackExpr *E) { |
| 8802 | // Default behavior is to do nothing with this transformation. |
| 8803 | return SemaRef.Owned(E); |
| 8804 | } |
| 8805 | |
| 8806 | template<typename Derived> |
| 8807 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 8808 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 8809 | SubstNonTypeTemplateParmExpr *E) { |
| 8810 | // Default behavior is to do nothing with this transformation. |
| 8811 | return SemaRef.Owned(E); |
| 8812 | } |
| 8813 | |
| 8814 | template<typename Derived> |
| 8815 | ExprResult |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 8816 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 8817 | // Default behavior is to do nothing with this transformation. |
| 8818 | return SemaRef.Owned(E); |
| 8819 | } |
| 8820 | |
| 8821 | template<typename Derived> |
| 8822 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8823 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 8824 | MaterializeTemporaryExpr *E) { |
| 8825 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 8826 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8827 | |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 8828 | template<typename Derived> |
| 8829 | ExprResult |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 8830 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 8831 | CXXStdInitializerListExpr *E) { |
| 8832 | return getDerived().TransformExpr(E->getSubExpr()); |
| 8833 | } |
| 8834 | |
| 8835 | template<typename Derived> |
| 8836 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8837 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8838 | return SemaRef.MaybeBindToTemporary(E); |
| 8839 | } |
| 8840 | |
| 8841 | template<typename Derived> |
| 8842 | ExprResult |
| 8843 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
Jordy Rose | 8986c599 | 2012-03-12 17:53:02 +0000 | [diff] [blame] | 8844 | return SemaRef.Owned(E); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8845 | } |
| 8846 | |
| 8847 | template<typename Derived> |
| 8848 | ExprResult |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 8849 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 8850 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 8851 | if (SubExpr.isInvalid()) |
| 8852 | return ExprError(); |
| 8853 | |
| 8854 | if (!getDerived().AlwaysRebuild() && |
| 8855 | SubExpr.get() == E->getSubExpr()) |
| 8856 | return SemaRef.Owned(E); |
| 8857 | |
| 8858 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8859 | } |
| 8860 | |
| 8861 | template<typename Derived> |
| 8862 | ExprResult |
| 8863 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 8864 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8865 | SmallVector<Expr *, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8866 | bool ArgChanged = false; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8867 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8868 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 8869 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8870 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8871 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8872 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8873 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8874 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 8875 | Elements.data(), |
| 8876 | Elements.size()); |
| 8877 | } |
| 8878 | |
| 8879 | template<typename Derived> |
| 8880 | ExprResult |
| 8881 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8882 | ObjCDictionaryLiteral *E) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8883 | // Transform each of the elements. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8884 | SmallVector<ObjCDictionaryElement, 8> Elements; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8885 | bool ArgChanged = false; |
| 8886 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 8887 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8888 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8889 | if (OrigElement.isPackExpansion()) { |
| 8890 | // This key/value element is a pack expansion. |
| 8891 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 8892 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 8893 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 8894 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 8895 | |
| 8896 | // Determine whether the set of unexpanded parameter packs can |
| 8897 | // and should be expanded. |
| 8898 | bool Expand = true; |
| 8899 | bool RetainExpansion = false; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8900 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 8901 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8902 | SourceRange PatternRange(OrigElement.Key->getLocStart(), |
| 8903 | OrigElement.Value->getLocEnd()); |
| 8904 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 8905 | PatternRange, |
| 8906 | Unexpanded, |
| 8907 | Expand, RetainExpansion, |
| 8908 | NumExpansions)) |
| 8909 | return ExprError(); |
| 8910 | |
| 8911 | if (!Expand) { |
| 8912 | // The transform has determined that we should perform a simple |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8913 | // transformation on the pack expansion, producing another pack |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8914 | // expansion. |
| 8915 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 8916 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8917 | if (Key.isInvalid()) |
| 8918 | return ExprError(); |
| 8919 | |
| 8920 | if (Key.get() != OrigElement.Key) |
| 8921 | ArgChanged = true; |
| 8922 | |
| 8923 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8924 | if (Value.isInvalid()) |
| 8925 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8926 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8927 | if (Value.get() != OrigElement.Value) |
| 8928 | ArgChanged = true; |
| 8929 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8930 | ObjCDictionaryElement Expansion = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8931 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 8932 | }; |
| 8933 | Elements.push_back(Expansion); |
| 8934 | continue; |
| 8935 | } |
| 8936 | |
| 8937 | // Record right away that the argument was changed. This needs |
| 8938 | // to happen even if the array expands to nothing. |
| 8939 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8940 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8941 | // The transform has determined that we should perform an elementwise |
| 8942 | // expansion of the pattern. Do so. |
| 8943 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 8944 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 8945 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8946 | if (Key.isInvalid()) |
| 8947 | return ExprError(); |
| 8948 | |
| 8949 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 8950 | if (Value.isInvalid()) |
| 8951 | return ExprError(); |
| 8952 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8953 | ObjCDictionaryElement Element = { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8954 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 8955 | }; |
| 8956 | |
| 8957 | // If any unexpanded parameter packs remain, we still have a |
| 8958 | // pack expansion. |
| 8959 | if (Key.get()->containsUnexpandedParameterPack() || |
| 8960 | Value.get()->containsUnexpandedParameterPack()) |
| 8961 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8962 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8963 | Elements.push_back(Element); |
| 8964 | } |
| 8965 | |
| 8966 | // We've finished with this pack expansion. |
| 8967 | continue; |
| 8968 | } |
| 8969 | |
| 8970 | // Transform and check key. |
| 8971 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 8972 | if (Key.isInvalid()) |
| 8973 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8974 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8975 | if (Key.get() != OrigElement.Key) |
| 8976 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8977 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8978 | // Transform and check value. |
| 8979 | ExprResult Value |
| 8980 | = getDerived().TransformExpr(OrigElement.Value); |
| 8981 | if (Value.isInvalid()) |
| 8982 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8983 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8984 | if (Value.get() != OrigElement.Value) |
| 8985 | ArgChanged = true; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8986 | |
| 8987 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 8988 | Key.get(), Value.get(), SourceLocation(), None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8989 | }; |
| 8990 | Elements.push_back(Element); |
| 8991 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8992 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 8993 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 8994 | return SemaRef.MaybeBindToTemporary(E); |
| 8995 | |
| 8996 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 8997 | Elements.data(), |
| 8998 | Elements.size()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8999 | } |
| 9000 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9001 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9002 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9003 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9004 | TypeSourceInfo *EncodedTypeInfo |
| 9005 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 9006 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9007 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9008 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9009 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9010 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9011 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9012 | |
| 9013 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 9014 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9015 | E->getRParenLoc()); |
| 9016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9018 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9019 | ExprResult TreeTransform<Derived>:: |
| 9020 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 9021 | // This is a kind of implicit conversion, and it needs to get dropped |
| 9022 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 9023 | // do, as well a more specific one: this expression is only valid when |
| 9024 | // it appears *immediately* as an argument expression. |
| 9025 | return getDerived().TransformExpr(E->getSubExpr()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9026 | } |
| 9027 | |
| 9028 | template<typename Derived> |
| 9029 | ExprResult TreeTransform<Derived>:: |
| 9030 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9031 | TypeSourceInfo *TSInfo |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9032 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9033 | if (!TSInfo) |
| 9034 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9035 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9036 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9037 | if (Result.isInvalid()) |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9038 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9039 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9040 | if (!getDerived().AlwaysRebuild() && |
| 9041 | TSInfo == E->getTypeInfoAsWritten() && |
| 9042 | Result.get() == E->getSubExpr()) |
| 9043 | return SemaRef.Owned(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9044 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9045 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9046 | E->getBridgeKeywordLoc(), TSInfo, |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9047 | Result.get()); |
| 9048 | } |
| 9049 | |
| 9050 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9051 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9052 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9053 | // Transform arguments. |
| 9054 | bool ArgChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9055 | SmallVector<Expr*, 8> Args; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9056 | Args.reserve(E->getNumArgs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9057 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9058 | &ArgChanged)) |
| 9059 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9060 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9061 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 9062 | // Class message: transform the receiver type. |
| 9063 | TypeSourceInfo *ReceiverTypeInfo |
| 9064 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 9065 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9066 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9067 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9068 | // If nothing changed, just retain the existing message send. |
| 9069 | if (!getDerived().AlwaysRebuild() && |
| 9070 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9071 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9072 | |
| 9073 | // Build a new class message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9074 | SmallVector<SourceLocation, 16> SelLocs; |
| 9075 | E->getSelectorLocs(SelLocs); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9076 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 9077 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9078 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9079 | E->getMethodDecl(), |
| 9080 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9081 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9082 | E->getRightLoc()); |
| 9083 | } |
| 9084 | |
| 9085 | // Instance message: transform the receiver |
| 9086 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 9087 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9088 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9089 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 9090 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9091 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9092 | |
| 9093 | // If nothing changed, just retain the existing message send. |
| 9094 | if (!getDerived().AlwaysRebuild() && |
| 9095 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9096 | return SemaRef.MaybeBindToTemporary(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9097 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9098 | // Build a new instance message send. |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9099 | SmallVector<SourceLocation, 16> SelLocs; |
| 9100 | E->getSelectorLocs(SelLocs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9101 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9102 | E->getSelector(), |
Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 9103 | SelLocs, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9104 | E->getMethodDecl(), |
| 9105 | E->getLeftLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9106 | Args, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9107 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9108 | } |
| 9109 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9110 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9111 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9112 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9113 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9114 | } |
| 9115 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9116 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9117 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9118 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9119 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9120 | } |
| 9121 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9122 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9123 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9124 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9125 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9126 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9127 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9128 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9129 | |
| 9130 | // We don't need to transform the ivar; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9131 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9132 | // If nothing changed, just retain the existing expression. |
| 9133 | if (!getDerived().AlwaysRebuild() && |
| 9134 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9135 | return SemaRef.Owned(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9136 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9137 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9138 | E->getLocation(), |
| 9139 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9140 | } |
| 9141 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9142 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9143 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9144 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9145 | // 'super' and types never change. Property never changes. Just |
| 9146 | // retain the existing expression. |
| 9147 | if (!E->isObjectReceiver()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9148 | return SemaRef.Owned(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9149 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9150 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9151 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9152 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9153 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9154 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9155 | // We don't need to transform the property; it will never change. |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9156 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 9157 | // If nothing changed, just retain the existing expression. |
| 9158 | if (!getDerived().AlwaysRebuild() && |
| 9159 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9160 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9161 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9162 | if (E->isExplicitProperty()) |
| 9163 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 9164 | E->getExplicitProperty(), |
| 9165 | E->getLocation()); |
| 9166 | |
| 9167 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 9168 | SemaRef.Context.PseudoObjectTy, |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 9169 | E->getImplicitPropertyGetter(), |
| 9170 | E->getImplicitPropertySetter(), |
| 9171 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9172 | } |
| 9173 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9174 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9175 | ExprResult |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9176 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 9177 | // Transform the base expression. |
| 9178 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9179 | if (Base.isInvalid()) |
| 9180 | return ExprError(); |
| 9181 | |
| 9182 | // Transform the key expression. |
| 9183 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 9184 | if (Key.isInvalid()) |
| 9185 | return ExprError(); |
| 9186 | |
| 9187 | // If nothing changed, just retain the existing expression. |
| 9188 | if (!getDerived().AlwaysRebuild() && |
| 9189 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 9190 | return SemaRef.Owned(E); |
| 9191 | |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9192 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 9193 | Base.get(), Key.get(), |
| 9194 | E->getAtIndexMethodDecl(), |
| 9195 | E->setAtIndexMethodDecl()); |
| 9196 | } |
| 9197 | |
| 9198 | template<typename Derived> |
| 9199 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9200 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9201 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9202 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9203 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9204 | return ExprError(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9205 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9206 | // If nothing changed, just retain the existing expression. |
| 9207 | if (!getDerived().AlwaysRebuild() && |
| 9208 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9209 | return SemaRef.Owned(E); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9210 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9211 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 9212 | E->getOpLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 9213 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9214 | } |
| 9215 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9216 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9217 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9218 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9219 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9220 | SmallVector<Expr*, 8> SubExprs; |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9221 | SubExprs.reserve(E->getNumSubExprs()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9222 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9223 | SubExprs, &ArgumentChanged)) |
| 9224 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9226 | if (!getDerived().AlwaysRebuild() && |
| 9227 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 9228 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9229 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9230 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9231 | SubExprs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9232 | E->getRParenLoc()); |
| 9233 | } |
| 9234 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9235 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9236 | ExprResult |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 9237 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 9238 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 9239 | if (SrcExpr.isInvalid()) |
| 9240 | return ExprError(); |
| 9241 | |
| 9242 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9243 | if (!Type) |
| 9244 | return ExprError(); |
| 9245 | |
| 9246 | if (!getDerived().AlwaysRebuild() && |
| 9247 | Type == E->getTypeSourceInfo() && |
| 9248 | SrcExpr.get() == E->getSrcExpr()) |
| 9249 | return SemaRef.Owned(E); |
| 9250 | |
| 9251 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 9252 | SrcExpr.get(), Type, |
| 9253 | E->getRParenLoc()); |
| 9254 | } |
| 9255 | |
| 9256 | template<typename Derived> |
| 9257 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9258 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9259 | BlockDecl *oldBlock = E->getBlockDecl(); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9260 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9261 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 9262 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 9263 | |
| 9264 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 9265 | blockScope->TheDecl->setBlockMissingReturnType( |
| 9266 | oldBlock->blockMissingReturnType()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9267 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9268 | SmallVector<ParmVarDecl*, 4> params; |
| 9269 | SmallVector<QualType, 4> paramTypes; |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9270 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 9271 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9272 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 9273 | oldBlock->param_begin(), |
| 9274 | oldBlock->param_size(), |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9275 | 0, paramTypes, ¶ms)) { |
| 9276 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9277 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9278 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9279 | |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9280 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9281 | QualType exprResultType = |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 9282 | getDerived().TransformType(exprFunctionType->getReturnType()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 9283 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9284 | QualType functionType = |
| 9285 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9286 | exprFunctionType->getExtProtoInfo()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9287 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9288 | |
| 9289 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9290 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 9291 | blockScope->TheDecl->setParams(params); |
Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 9292 | |
| 9293 | if (!oldBlock->blockMissingReturnType()) { |
| 9294 | blockScope->HasImplicitReturnType = false; |
| 9295 | blockScope->ReturnType = exprResultType; |
| 9296 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9297 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9298 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9299 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9300 | if (body.isInvalid()) { |
| 9301 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9302 | return ExprError(); |
Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 9303 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 9304 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9305 | #ifndef NDEBUG |
| 9306 | // In builds with assertions, make sure that we captured everything we |
| 9307 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9308 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 9309 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 9310 | e = oldBlock->capture_end(); i != e; ++i) { |
| 9311 | VarDecl *oldCapture = i->getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9312 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9313 | // Ignore parameter packs. |
| 9314 | if (isa<ParmVarDecl>(oldCapture) && |
| 9315 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 9316 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9317 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 9318 | VarDecl *newCapture = |
| 9319 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 9320 | oldCapture)); |
| 9321 | assert(blockScope->CaptureMap.count(newCapture)); |
| 9322 | } |
Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 9323 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 9324 | } |
| 9325 | #endif |
| 9326 | |
| 9327 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 9328 | /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9329 | } |
| 9330 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9331 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9332 | ExprResult |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9333 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 9334 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 9335 | } |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9336 | |
| 9337 | template<typename Derived> |
| 9338 | ExprResult |
| 9339 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9340 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 9341 | bool ArgumentChanged = false; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9342 | SmallVector<Expr*, 8> SubExprs; |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9343 | SubExprs.reserve(E->getNumSubExprs()); |
| 9344 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 9345 | SubExprs, &ArgumentChanged)) |
| 9346 | return ExprError(); |
| 9347 | |
| 9348 | if (!getDerived().AlwaysRebuild() && |
| 9349 | !ArgumentChanged) |
| 9350 | return SemaRef.Owned(E); |
| 9351 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9352 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 9353 | RetTy, E->getOp(), E->getRParenLoc()); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 9354 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9356 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9357 | // Type reconstruction |
| 9358 | //===----------------------------------------------------------------------===// |
| 9359 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9360 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9361 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 9362 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9363 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9364 | getDerived().getBaseEntity()); |
| 9365 | } |
| 9366 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9367 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9368 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 9369 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9370 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9371 | getDerived().getBaseEntity()); |
| 9372 | } |
| 9373 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9374 | template<typename Derived> |
| 9375 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9376 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 9377 | bool WrittenAsLValue, |
| 9378 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 9379 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9380 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9381 | } |
| 9382 | |
| 9383 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9384 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9385 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 9386 | QualType ClassType, |
| 9387 | SourceLocation Sigil) { |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 9388 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 9389 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9390 | } |
| 9391 | |
| 9392 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9393 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9394 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 9395 | ArrayType::ArraySizeModifier SizeMod, |
| 9396 | const llvm::APInt *Size, |
| 9397 | Expr *SizeExpr, |
| 9398 | unsigned IndexTypeQuals, |
| 9399 | SourceRange BracketsRange) { |
| 9400 | if (SizeExpr || !Size) |
| 9401 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 9402 | IndexTypeQuals, BracketsRange, |
| 9403 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9404 | |
| 9405 | QualType Types[] = { |
| 9406 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 9407 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 9408 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9409 | }; |
Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 9410 | const unsigned NumTypes = llvm::array_lengthof(Types); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9411 | QualType SizeType; |
| 9412 | for (unsigned I = 0; I != NumTypes; ++I) |
| 9413 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 9414 | SizeType = Types[I]; |
| 9415 | break; |
| 9416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9417 | |
Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 9418 | // Note that we can return a VariableArrayType here in the case where |
| 9419 | // the element type was a dependent VariableArrayType. |
| 9420 | IntegerLiteral *ArraySize |
| 9421 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 9422 | /*FIXME*/BracketsRange.getBegin()); |
| 9423 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9424 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9425 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9427 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9428 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9429 | QualType |
| 9430 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9431 | ArrayType::ArraySizeModifier SizeMod, |
| 9432 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9433 | unsigned IndexTypeQuals, |
| 9434 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9435 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9436 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9437 | } |
| 9438 | |
| 9439 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9440 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9441 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9442 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9443 | unsigned IndexTypeQuals, |
| 9444 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9445 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 9446 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9447 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9448 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9449 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9450 | QualType |
| 9451 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9452 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9453 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9454 | unsigned IndexTypeQuals, |
| 9455 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9456 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9457 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9458 | IndexTypeQuals, BracketsRange); |
| 9459 | } |
| 9460 | |
| 9461 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9462 | QualType |
| 9463 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9464 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9465 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9466 | unsigned IndexTypeQuals, |
| 9467 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9468 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9469 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9470 | IndexTypeQuals, BracketsRange); |
| 9471 | } |
| 9472 | |
| 9473 | template<typename Derived> |
| 9474 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9475 | unsigned NumElements, |
| 9476 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9477 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 9478 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9480 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9481 | template<typename Derived> |
| 9482 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 9483 | unsigned NumElements, |
| 9484 | SourceLocation AttributeLoc) { |
| 9485 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 9486 | NumElements, true); |
| 9487 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 9488 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 9489 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9490 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9492 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9493 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9494 | QualType |
| 9495 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9496 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9497 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9498 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9500 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9501 | template<typename Derived> |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 9502 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 9503 | QualType T, |
| 9504 | llvm::MutableArrayRef<QualType> ParamTypes, |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9505 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 9506 | return SemaRef.BuildFunctionType(T, ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9507 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 9508 | getDerived().getBaseEntity(), |
Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 9509 | EPI); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9511 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9512 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 9513 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 9514 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 9515 | } |
| 9516 | |
| 9517 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9518 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 9519 | assert(D && "no decl found"); |
| 9520 | if (D->isInvalidDecl()) return QualType(); |
| 9521 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 9522 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9523 | TypeDecl *Ty; |
| 9524 | if (isa<UsingDecl>(D)) { |
| 9525 | UsingDecl *Using = cast<UsingDecl>(D); |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 9526 | assert(Using->hasTypename() && |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9527 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 9528 | |
| 9529 | // A valid resolved using typename decl points to exactly one type decl. |
| 9530 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 9531 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9532 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 9533 | } else { |
| 9534 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 9535 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 9536 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 9537 | } |
| 9538 | |
| 9539 | return SemaRef.Context.getTypeDeclType(Ty); |
| 9540 | } |
| 9541 | |
| 9542 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9543 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 9544 | SourceLocation Loc) { |
| 9545 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9546 | } |
| 9547 | |
| 9548 | template<typename Derived> |
| 9549 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 9550 | return SemaRef.Context.getTypeOfType(Underlying); |
| 9551 | } |
| 9552 | |
| 9553 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 9554 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 9555 | SourceLocation Loc) { |
| 9556 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9557 | } |
| 9558 | |
| 9559 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 9560 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 9561 | UnaryTransformType::UTTKind UKind, |
| 9562 | SourceLocation Loc) { |
| 9563 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 9564 | } |
| 9565 | |
| 9566 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9567 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 9568 | TemplateName Template, |
| 9569 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 9570 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9571 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9572 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9573 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 9574 | template<typename Derived> |
Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 9575 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 9576 | SourceLocation KWLoc) { |
| 9577 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 9578 | } |
| 9579 | |
| 9580 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9581 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9582 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9583 | bool TemplateKW, |
| 9584 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9585 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9586 | Template); |
| 9587 | } |
| 9588 | |
| 9589 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9590 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9591 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 9592 | const IdentifierInfo &Name, |
| 9593 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9594 | QualType ObjectType, |
| 9595 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9596 | UnqualifiedId TemplateName; |
| 9597 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9598 | Sema::TemplateTy Template; |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9599 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9600 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9601 | SS, TemplateKWLoc, TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9602 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9603 | /*EnteringContext=*/false, |
| 9604 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 9605 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 9606 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9607 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9608 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9609 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9610 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9611 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9612 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9613 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9614 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9615 | // FIXME: Bogus location information. |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9616 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 9617 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9618 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9619 | Sema::TemplateTy Template; |
| 9620 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9621 | SS, TemplateKWLoc, Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 9622 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 9623 | /*EnteringContext=*/false, |
| 9624 | Template); |
Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 9625 | return Template.get(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9626 | } |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9627 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 9628 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9629 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9630 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 9631 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9632 | Expr *OrigCallee, |
| 9633 | Expr *First, |
| 9634 | Expr *Second) { |
| 9635 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 9636 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9638 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9639 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9640 | if (!First->getType()->isOverloadableType() && |
| 9641 | !Second->getType()->isOverloadableType()) |
| 9642 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 9643 | Callee->getLocStart(), |
| 9644 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 9645 | } else if (Op == OO_Arrow) { |
| 9646 | // -> is never a builtin operation. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9647 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 9648 | } else if (Second == 0 || isPostIncDec) { |
| 9649 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9650 | // The argument is not of overloadable type, so try to create a |
| 9651 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9652 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9653 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9654 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9655 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9656 | } |
| 9657 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9658 | if (!First->getType()->isOverloadableType() && |
| 9659 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9660 | // Neither of the arguments is an overloadable type, so try to |
| 9661 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9662 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9663 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9664 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9665 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9666 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9667 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9668 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9669 | } |
| 9670 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9671 | |
| 9672 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9673 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9674 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9675 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9676 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9677 | assert(ULE->requiresADL()); |
| 9678 | |
| 9679 | // FIXME: Do we have to check |
| 9680 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 9681 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9682 | } else { |
Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 9683 | // If we've resolved this to a particular non-member function, just call |
| 9684 | // that function. If we resolved it to a member function, |
| 9685 | // CreateOverloaded* will find that function for us. |
| 9686 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 9687 | if (!isa<CXXMethodDecl>(ND)) |
| 9688 | Functions.addDecl(ND); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 9689 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9690 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9691 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9692 | Expr *Args[2] = { First, Second }; |
| 9693 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9694 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9695 | // Create the overloaded operator invocation for unary operators. |
| 9696 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9697 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9698 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9699 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9701 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 9702 | if (Op == OO_Subscript) { |
| 9703 | SourceLocation LBrace; |
| 9704 | SourceLocation RBrace; |
| 9705 | |
| 9706 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 9707 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 9708 | LBrace = SourceLocation::getFromRawEncoding( |
| 9709 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 9710 | RBrace = SourceLocation::getFromRawEncoding( |
| 9711 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 9712 | } else { |
| 9713 | LBrace = Callee->getLocStart(); |
| 9714 | RBrace = OpLoc; |
| 9715 | } |
| 9716 | |
| 9717 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 9718 | First, Second); |
| 9719 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 9720 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9721 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 9722 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9723 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9724 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 9725 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9726 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9727 | |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9728 | return Result; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9730 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9731 | template<typename Derived> |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9732 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9733 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9734 | SourceLocation OperatorLoc, |
| 9735 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 9736 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9737 | TypeSourceInfo *ScopeType, |
| 9738 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9739 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9740 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9741 | QualType BaseType = Base->getType(); |
| 9742 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9743 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9744 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 9745 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 9746 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9747 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9748 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9749 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 9750 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9751 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9752 | /*FIXME?*/true); |
| 9753 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9754 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 9755 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9756 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 9757 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 9758 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 9759 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 9760 | |
Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 9761 | // The scope type is now known to be a valid nested name specifier |
| 9762 | // component. Tack it on to the end of the nested name specifier. |
| 9763 | if (ScopeType) |
| 9764 | SS.Extend(SemaRef.Context, SourceLocation(), |
| 9765 | ScopeType->getTypeLoc(), CCLoc); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9766 | |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9767 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9768 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9769 | OperatorLoc, isArrow, |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9770 | SS, TemplateKWLoc, |
| 9771 | /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9772 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 9773 | /*TemplateArgs*/ 0); |
| 9774 | } |
| 9775 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9776 | template<typename Derived> |
| 9777 | StmtResult |
| 9778 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 9779 | SourceLocation Loc = S->getLocStart(); |
| 9780 | unsigned NumParams = S->getCapturedDecl()->getNumParams(); |
| 9781 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0, |
| 9782 | S->getCapturedRegionKind(), NumParams); |
| 9783 | StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 9784 | |
| 9785 | if (Body.isInvalid()) { |
| 9786 | getSema().ActOnCapturedRegionError(); |
| 9787 | return StmtError(); |
| 9788 | } |
| 9789 | |
| 9790 | return getSema().ActOnCapturedRegionEnd(Body.take()); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 9791 | } |
| 9792 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 9793 | } // end namespace clang |
| 9794 | |
| 9795 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |