John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 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 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
John McCall | 2d88708 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 16 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 17 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 18 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 19 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 20 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 21 | #include "clang/AST/Decl.h" |
John McCall | 7cd088e | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 23 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprCXX.h" |
| 25 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 26 | #include "clang/AST/Stmt.h" |
| 27 | #include "clang/AST/StmtCXX.h" |
| 28 | #include "clang/AST/StmtObjC.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Ownership.h" |
| 30 | #include "clang/Sema/Designator.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 7e44e3f | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 33 | #include "TypeLocBuilder.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 34 | #include <algorithm> |
| 35 | |
| 36 | namespace clang { |
John McCall | 781472f | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 37 | using namespace sema; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 39 | /// \brief A semantic tree transformation that allows one to transform one |
| 40 | /// abstract syntax tree into another. |
| 41 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 43 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 44 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 45 | /// instantiation is implemented as a tree transformation where the |
| 46 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 47 | /// template arguments for their corresponding template parameters; a similar |
| 48 | /// transformation is performed for non-type template parameters and |
| 49 | /// template template parameters. |
| 50 | /// |
| 51 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 52 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 53 | /// override any of the transformation or rebuild operators by providing an |
| 54 | /// operation with the same signature as the default implementation. The |
| 55 | /// overridding function should not be virtual. |
| 56 | /// |
| 57 | /// Semantic tree transformations are split into two stages, either of which |
| 58 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 59 | /// or the parts of an AST node using the various transformation functions, |
| 60 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 61 | /// node of the appropriate kind from the pieces. The default transformation |
| 62 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 63 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 64 | /// were changed by the transformation, invokes the rebuild operation to create |
| 65 | /// a new AST node. |
| 66 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 67 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 68 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 69 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 70 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 71 | /// new implementations. |
| 72 | /// |
| 73 | /// For more fine-grained transformations, subclasses can replace any of the |
| 74 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 75 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 76 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 78 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 79 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 80 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 81 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 82 | /// be able to use more efficient rebuild steps. |
| 83 | /// |
| 84 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 85 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 87 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 88 | /// default locations and entity names used for type-checking |
| 89 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 90 | template<typename Derived> |
| 91 | class TreeTransform { |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 92 | /// \brief Private RAII object that helps us forget and then re-remember |
| 93 | /// the template argument corresponding to a partially-substituted parameter |
| 94 | /// pack. |
| 95 | class ForgetPartiallySubstitutedPackRAII { |
| 96 | Derived &Self; |
| 97 | TemplateArgument Old; |
| 98 | |
| 99 | public: |
| 100 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 101 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 102 | } |
| 103 | |
| 104 | ~ForgetPartiallySubstitutedPackRAII() { |
| 105 | Self.RememberPartiallySubstitutedPack(Old); |
| 106 | } |
| 107 | }; |
| 108 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 109 | protected: |
| 110 | Sema &SemaRef; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 111 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | public: |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 114 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 116 | /// \brief Retrieves a reference to the derived class. |
| 117 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 118 | |
| 119 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | const Derived &getDerived() const { |
| 121 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | } |
| 123 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 124 | static inline ExprResult Owned(Expr *E) { return E; } |
| 125 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 126 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 127 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 128 | /// this tree transform. |
| 129 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 130 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 131 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 132 | /// if none of the children have changed. |
| 133 | /// |
| 134 | /// Subclasses may override this function to specify when the transformation |
| 135 | /// should rebuild all AST nodes. |
| 136 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 137 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 138 | /// \brief Returns the location of the entity being transformed, if that |
| 139 | /// information was not available elsewhere in the AST. |
| 140 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 142 | /// provide an alternative implementation that provides better location |
| 143 | /// information. |
| 144 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 146 | /// \brief Returns the name of the entity being transformed, if that |
| 147 | /// information was not available elsewhere in the AST. |
| 148 | /// |
| 149 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 150 | /// implementation with a more precise name. |
| 151 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 152 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 153 | /// \brief Sets the "base" location and entity when that |
| 154 | /// information is known based on another transformation. |
| 155 | /// |
| 156 | /// By default, the source location and entity are ignored. Subclasses can |
| 157 | /// override this function to provide a customized implementation. |
| 158 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 159 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 160 | /// \brief RAII object that temporarily sets the base location and entity |
| 161 | /// used for reporting diagnostics in types. |
| 162 | class TemporaryBase { |
| 163 | TreeTransform &Self; |
| 164 | SourceLocation OldLocation; |
| 165 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 167 | public: |
| 168 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 169 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 170 | OldLocation = Self.getDerived().getBaseLocation(); |
| 171 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | ae201f7 | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 172 | |
| 173 | if (Location.isValid()) |
| 174 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 177 | ~TemporaryBase() { |
| 178 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 179 | } |
| 180 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | |
| 182 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 183 | /// transformed. |
| 184 | /// |
| 185 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 187 | /// not change. For example, template instantiation need not traverse |
| 188 | /// non-dependent types. |
| 189 | bool AlreadyTransformed(QualType T) { |
| 190 | return T.isNull(); |
| 191 | } |
| 192 | |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 193 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 194 | /// because it is a default argument. |
| 195 | /// |
| 196 | /// Subclasses can provide an alternative implementation of this routine to |
| 197 | /// determine which kinds of call arguments get dropped. By default, |
| 198 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 199 | bool DropCallArgument(Expr *E) { |
| 200 | return E->isDefaultArgument(); |
| 201 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 202 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 203 | /// \brief Determine whether we should expand a pack expansion with the |
| 204 | /// given set of parameter packs into separate arguments by repeatedly |
| 205 | /// transforming the pattern. |
| 206 | /// |
Douglas Gregor | b99268b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 207 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 208 | /// Subclasses can override this routine to provide different behavior. |
| 209 | /// |
| 210 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 211 | /// pack expansion. |
| 212 | /// |
| 213 | /// \param PatternRange The source range that covers the entire pattern of |
| 214 | /// the pack expansion. |
| 215 | /// |
| 216 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 217 | /// pattern. |
| 218 | /// |
| 219 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 220 | /// \p Unexpanded. |
| 221 | /// |
| 222 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 223 | /// expand the corresponding pack expansions into separate arguments. When |
| 224 | /// set, \c NumExpansions must also be set. |
| 225 | /// |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 226 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 227 | /// pack expansion after all of the expanded arguments. This is used |
| 228 | /// when extending explicitly-specified template argument packs per |
| 229 | /// C++0x [temp.arg.explicit]p9. |
| 230 | /// |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 231 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 232 | /// the expanded form of the corresponding pack expansion. This is both an |
| 233 | /// input and an output parameter, which can be set by the caller if the |
| 234 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 235 | /// and will be set by the callee when the number of expansions is known. |
| 236 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 237 | /// set this value in other cases. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 238 | /// |
| 239 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 240 | /// are to be instantiated with arguments of different lengths), false |
| 241 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 242 | /// must be set. |
| 243 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 244 | SourceRange PatternRange, |
| 245 | const UnexpandedParameterPack *Unexpanded, |
| 246 | unsigned NumUnexpanded, |
| 247 | bool &ShouldExpand, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 248 | bool &RetainExpansion, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 249 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 250 | ShouldExpand = false; |
| 251 | return false; |
| 252 | } |
| 253 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 254 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 255 | /// when performing an instantiation that must preserve the parameter pack |
| 256 | /// use. |
| 257 | /// |
| 258 | /// This routine is meant to be overridden by the template instantiator. |
| 259 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 260 | return TemplateArgument(); |
| 261 | } |
| 262 | |
| 263 | /// \brief "Remember" the partially-substituted pack template argument |
| 264 | /// after 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 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 269 | |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 270 | /// \brief Note to the derived class when a function parameter pack is |
| 271 | /// being expanded. |
| 272 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 273 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 274 | /// \brief Transforms the given type into another type. |
| 275 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 276 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 277 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 278 | /// function. This is expensive, but we don't mind, because |
| 279 | /// this method is deprecated anyway; all users should be |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 280 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 281 | /// |
| 282 | /// \returns the transformed type. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 283 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 285 | /// \brief Transforms the given type-with-location into a new |
| 286 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 287 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 288 | /// By default, this routine transforms a type by delegating to the |
| 289 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 290 | /// may override this function (to take over all type |
| 291 | /// transformations) or some set of the TransformXXXType functions |
| 292 | /// to alter the transformation. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 293 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 294 | |
| 295 | /// \brief Transform the given type-with-location into a new |
| 296 | /// type, collecting location information in the given builder |
| 297 | /// as necessary. |
| 298 | /// |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 299 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 300 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 301 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 302 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 303 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 304 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 305 | /// statement or the TransformExpr() function to transform an expression. |
| 306 | /// Subclasses may override this function to transform statements using some |
| 307 | /// other mechanism. |
| 308 | /// |
| 309 | /// \returns the transformed statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 310 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 312 | /// \brief Transform the given expression. |
| 313 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 314 | /// By default, this routine transforms an expression by delegating to the |
| 315 | /// appropriate TransformXXXExpr function to build a new expression. |
| 316 | /// Subclasses may override this function to transform expressions using some |
| 317 | /// other mechanism. |
| 318 | /// |
| 319 | /// \returns the transformed expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 320 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 321 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 322 | /// \brief Transform the given list of expressions. |
| 323 | /// |
| 324 | /// This routine transforms a list of expressions by invoking |
| 325 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 326 | /// support for variadic templates by expanding any pack expansions (if the |
| 327 | /// derived class permits such expansion) along the way. When pack expansions |
| 328 | /// are present, the number of outputs may not equal the number of inputs. |
| 329 | /// |
| 330 | /// \param Inputs The set of expressions to be transformed. |
| 331 | /// |
| 332 | /// \param NumInputs The number of expressions in \c Inputs. |
| 333 | /// |
| 334 | /// \param IsCall If \c true, then this transform is being performed on |
| 335 | /// function-call arguments, and any arguments that should be dropped, will |
| 336 | /// be. |
| 337 | /// |
| 338 | /// \param Outputs The transformed input expressions will be added to this |
| 339 | /// vector. |
| 340 | /// |
| 341 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 342 | /// due to transformation. |
| 343 | /// |
| 344 | /// \returns true if an error occurred, false otherwise. |
| 345 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
| 346 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 347 | bool *ArgChanged = 0); |
| 348 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 349 | /// \brief Transform the given declaration, which is referenced from a type |
| 350 | /// or expression. |
| 351 | /// |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 352 | /// By default, acts as the identity function on declarations. Subclasses |
| 353 | /// may override this function to provide alternate behavior. |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 354 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 355 | |
| 356 | /// \brief Transform the definition of the given declaration. |
| 357 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 359 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 360 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 361 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 364 | /// \brief Transform the given declaration, which was the first part of a |
| 365 | /// nested-name-specifier in a member access expression. |
| 366 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 367 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 368 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 369 | /// the \c T in \c x->T::member |
| 370 | /// |
| 371 | /// By default, invokes TransformDecl() to transform the declaration. |
| 372 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 373 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 374 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 375 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 376 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 377 | /// \brief Transform the given nested-name-specifier. |
| 378 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 379 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 380 | /// nested-name-specifier. Subclasses may override this function to provide |
| 381 | /// alternate behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 383 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 384 | QualType ObjectType = QualType(), |
| 385 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 386 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 387 | /// \brief Transform the given declaration name. |
| 388 | /// |
| 389 | /// By default, transforms the types of conversion function, constructor, |
| 390 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 391 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 392 | /// override this function to provide alternate behavior. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 393 | DeclarationNameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 394 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 398 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 400 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 401 | TemplateName TransformTemplateName(TemplateName Name, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 402 | QualType ObjectType = QualType(), |
| 403 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// \brief Transform the given template argument. |
| 406 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 407 | /// By default, this operation transforms the type, expression, or |
| 408 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 409 | /// new template argument from the transformed result. Subclasses may |
| 410 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 411 | /// |
| 412 | /// Returns true if there was an error. |
| 413 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 414 | TemplateArgumentLoc &Output); |
| 415 | |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 416 | /// \brief Transform the given set of template arguments. |
| 417 | /// |
| 418 | /// By default, this operation transforms all of the template arguments |
| 419 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 420 | /// the transformed arguments to the output list. |
| 421 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 422 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 423 | /// a convenience function. Subclasses that wish to override this behavior |
| 424 | /// should override the iterator-based member template version. |
| 425 | /// |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 426 | /// \param Inputs The set of template arguments to be transformed. |
| 427 | /// |
| 428 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 429 | /// |
| 430 | /// \param Outputs The set of transformed template arguments output by this |
| 431 | /// routine. |
| 432 | /// |
| 433 | /// Returns true if an error occurred. |
| 434 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 435 | unsigned NumInputs, |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 436 | TemplateArgumentListInfo &Outputs) { |
| 437 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 438 | } |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 439 | |
| 440 | /// \brief Transform the given set of template arguments. |
| 441 | /// |
| 442 | /// By default, this operation transforms all of the template arguments |
| 443 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 444 | /// the transformed arguments to the output list. |
| 445 | /// |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 446 | /// \param First An iterator to the first template argument. |
| 447 | /// |
| 448 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 449 | /// |
| 450 | /// \param Outputs The set of transformed template arguments output by this |
| 451 | /// routine. |
| 452 | /// |
| 453 | /// Returns true if an error occurred. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 454 | template<typename InputIterator> |
| 455 | bool TransformTemplateArguments(InputIterator First, |
| 456 | InputIterator Last, |
| 457 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 458 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 459 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 460 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 461 | TemplateArgumentLoc &ArgLoc); |
| 462 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 463 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 464 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 465 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 466 | getDerived().getBaseLocation()); |
| 467 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 468 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 469 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 470 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 471 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 472 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 473 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 474 | QualType |
| 475 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 476 | TemplateSpecializationTypeLoc TL, |
| 477 | TemplateName Template); |
| 478 | |
| 479 | QualType |
| 480 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 481 | DependentTemplateSpecializationTypeLoc TL, |
| 482 | NestedNameSpecifier *Prefix); |
| 483 | |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 484 | /// \brief Transforms the parameters of a function type into the |
| 485 | /// given vectors. |
| 486 | /// |
| 487 | /// The result vectors should be kept in sync; null entries in the |
| 488 | /// variables vector are acceptable. |
| 489 | /// |
| 490 | /// Return true on error. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 491 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 492 | ParmVarDecl **Params, unsigned NumParams, |
| 493 | const QualType *ParamTypes, |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 494 | llvm::SmallVectorImpl<QualType> &PTypes, |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 495 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 496 | |
| 497 | /// \brief Transforms a single function-type parameter. Return null |
| 498 | /// on error. |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 499 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 500 | llvm::Optional<unsigned> NumExpansions); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 501 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 502 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 503 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 504 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 505 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 507 | #define STMT(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 508 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 509 | #define EXPR(Node, Parent) \ |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 510 | ExprResult Transform##Node(Node *E); |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 511 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 512 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 513 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 514 | /// \brief Build a new pointer type given its pointee type. |
| 515 | /// |
| 516 | /// By default, performs semantic analysis when building the pointer type. |
| 517 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 518 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 519 | |
| 520 | /// \brief Build a new block pointer type given its pointee type. |
| 521 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 523 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 524 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 525 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 526 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 527 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 528 | /// By default, performs semantic analysis when building the |
| 529 | /// reference type. Subclasses may override this routine to provide |
| 530 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 532 | /// \param LValue whether the type was written with an lvalue sigil |
| 533 | /// or an rvalue sigil. |
| 534 | QualType RebuildReferenceType(QualType ReferentType, |
| 535 | bool LValue, |
| 536 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 538 | /// \brief Build a new member pointer type given the pointee type and the |
| 539 | /// class type it refers into. |
| 540 | /// |
| 541 | /// By default, performs semantic analysis when building the member pointer |
| 542 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 543 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 544 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 545 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 546 | /// \brief Build a new array type given the element type, size |
| 547 | /// modifier, size of the array (if known), size expression, and index type |
| 548 | /// qualifiers. |
| 549 | /// |
| 550 | /// By default, performs semantic analysis when building the array type. |
| 551 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | QualType RebuildArrayType(QualType ElementType, |
| 554 | ArrayType::ArraySizeModifier SizeMod, |
| 555 | const llvm::APInt *Size, |
| 556 | Expr *SizeExpr, |
| 557 | unsigned IndexTypeQuals, |
| 558 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// \brief Build a new constant array type given the element type, size |
| 561 | /// modifier, (known) size of the array, and index type qualifiers. |
| 562 | /// |
| 563 | /// By default, performs semantic analysis when building the array type. |
| 564 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 566 | ArrayType::ArraySizeModifier SizeMod, |
| 567 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 568 | unsigned IndexTypeQuals, |
| 569 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 570 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 571 | /// \brief Build a new incomplete array type given the element type, size |
| 572 | /// modifier, and index type qualifiers. |
| 573 | /// |
| 574 | /// By default, performs semantic analysis when building the array type. |
| 575 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 576 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 577 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 578 | unsigned IndexTypeQuals, |
| 579 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 580 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 581 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 582 | /// size modifier, size expression, and index type qualifiers. |
| 583 | /// |
| 584 | /// By default, performs semantic analysis when building the array type. |
| 585 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 587 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 588 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 589 | unsigned IndexTypeQuals, |
| 590 | SourceRange BracketsRange); |
| 591 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 592 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 593 | /// size modifier, size expression, and index type qualifiers. |
| 594 | /// |
| 595 | /// By default, performs semantic analysis when building the array type. |
| 596 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 597 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 598 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 599 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 600 | unsigned IndexTypeQuals, |
| 601 | SourceRange BracketsRange); |
| 602 | |
| 603 | /// \brief Build a new vector type given the element type and |
| 604 | /// number of elements. |
| 605 | /// |
| 606 | /// By default, performs semantic analysis when building the vector type. |
| 607 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 608 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 609 | VectorType::VectorKind VecKind); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 611 | /// \brief Build a new extended vector type given the element type and |
| 612 | /// number of elements. |
| 613 | /// |
| 614 | /// By default, performs semantic analysis when building the vector type. |
| 615 | /// Subclasses may override this routine to provide different behavior. |
| 616 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 617 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
| 619 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 620 | /// given the element type and number of elements. |
| 621 | /// |
| 622 | /// By default, performs semantic analysis when building the vector type. |
| 623 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 625 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 626 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 628 | /// \brief Build a new function type. |
| 629 | /// |
| 630 | /// By default, performs semantic analysis when building the function type. |
| 631 | /// Subclasses may override this routine to provide different behavior. |
| 632 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 634 | unsigned NumParamTypes, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 635 | bool Variadic, unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 636 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 637 | const FunctionType::ExtInfo &Info); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 639 | /// \brief Build a new unprototyped function type. |
| 640 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 641 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 642 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 643 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 644 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 645 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 646 | /// \brief Build a new typedef type. |
| 647 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 648 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 649 | } |
| 650 | |
| 651 | /// \brief Build a new class/struct/union type. |
| 652 | QualType RebuildRecordType(RecordDecl *Record) { |
| 653 | return SemaRef.Context.getTypeDeclType(Record); |
| 654 | } |
| 655 | |
| 656 | /// \brief Build a new Enum type. |
| 657 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 658 | return SemaRef.Context.getTypeDeclType(Enum); |
| 659 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 660 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 662 | /// |
| 663 | /// By default, performs semantic analysis when building the typeof type. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 665 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 666 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 667 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 668 | /// |
| 669 | /// By default, builds a new TypeOfType with the given underlying type. |
| 670 | QualType RebuildTypeOfType(QualType Underlying); |
| 671 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 673 | /// |
| 674 | /// By default, performs semantic analysis when building the decltype type. |
| 675 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 676 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 678 | /// \brief Build a new template specialization type. |
| 679 | /// |
| 680 | /// By default, performs semantic analysis when building the template |
| 681 | /// specialization type. Subclasses may override this routine to provide |
| 682 | /// different behavior. |
| 683 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 684 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 685 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 686 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 687 | /// \brief Build a new parenthesized type. |
| 688 | /// |
| 689 | /// By default, builds a new ParenType type from the inner type. |
| 690 | /// Subclasses may override this routine to provide different behavior. |
| 691 | QualType RebuildParenType(QualType InnerType) { |
| 692 | return SemaRef.Context.getParenType(InnerType); |
| 693 | } |
| 694 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | /// \brief Build a new qualified name type. |
| 696 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 697 | /// By default, builds a new ElaboratedType type from the keyword, |
| 698 | /// the nested-name-specifier and the named type. |
| 699 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 700 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 701 | ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 702 | NestedNameSpecifier *NNS, QualType Named) { |
| 703 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 705 | |
| 706 | /// \brief Build a new typename type that refers to a template-id. |
| 707 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 708 | /// By default, builds a new DependentNameType type from the |
| 709 | /// nested-name-specifier and the given type. Subclasses may override |
| 710 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 711 | QualType RebuildDependentTemplateSpecializationType( |
| 712 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 713 | NestedNameSpecifier *Qualifier, |
| 714 | SourceRange QualifierRange, |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 715 | const IdentifierInfo *Name, |
| 716 | SourceLocation NameLoc, |
| 717 | const TemplateArgumentListInfo &Args) { |
| 718 | // Rebuild the template name. |
| 719 | // TODO: avoid TemplateName abstraction |
| 720 | TemplateName InstName = |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 721 | getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 722 | QualType(), 0); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 723 | |
Douglas Gregor | 96fb42e | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 724 | if (InstName.isNull()) |
| 725 | return QualType(); |
| 726 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 727 | // If it's still dependent, make a dependent specialization. |
| 728 | if (InstName.getAsDependentTemplateName()) |
| 729 | return SemaRef.Context.getDependentTemplateSpecializationType( |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 730 | Keyword, Qualifier, Name, Args); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 731 | |
| 732 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 733 | // specialization. |
| 734 | QualType T = |
| 735 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 736 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 737 | |
Abramo Bagnara | 22f638a | 2010-08-10 13:46:45 +0000 | [diff] [blame] | 738 | // NOTE: NNS is already recorded in template specialization type T. |
| 739 | return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 741 | |
| 742 | /// \brief Build a new typename type that refers to an identifier. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 745 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 746 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 747 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 748 | NestedNameSpecifier *NNS, |
| 749 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 750 | SourceLocation KeywordLoc, |
| 751 | SourceRange NNSRange, |
| 752 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 753 | CXXScopeSpec SS; |
| 754 | SS.setScopeRep(NNS); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 755 | SS.setRange(NNSRange); |
| 756 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 757 | if (NNS->isDependent()) { |
| 758 | // If the name is still dependent, just build a new dependent name type. |
| 759 | if (!SemaRef.computeDeclContext(SS)) |
| 760 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 761 | } |
| 762 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 763 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 764 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, |
| 765 | KeywordLoc, NNSRange, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 766 | |
| 767 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 768 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 769 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 770 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 771 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 772 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 773 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 774 | if (!DC) |
| 775 | return QualType(); |
| 776 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 777 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 778 | return QualType(); |
| 779 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 780 | TagDecl *Tag = 0; |
| 781 | SemaRef.LookupQualifiedName(Result, DC); |
| 782 | switch (Result.getResultKind()) { |
| 783 | case LookupResult::NotFound: |
| 784 | case LookupResult::NotFoundInCurrentInstantiation: |
| 785 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 786 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 787 | case LookupResult::Found: |
| 788 | Tag = Result.getAsSingle<TagDecl>(); |
| 789 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 790 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 791 | case LookupResult::FoundOverloaded: |
| 792 | case LookupResult::FoundUnresolvedValue: |
| 793 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 794 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 795 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 796 | case LookupResult::Ambiguous: |
| 797 | // Let the LookupResult structure handle ambiguities. |
| 798 | return QualType(); |
| 799 | } |
| 800 | |
| 801 | if (!Tag) { |
Nick Lewycky | 446e402 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 802 | // Check where the name exists but isn't a tag type and use that to emit |
| 803 | // better diagnostics. |
| 804 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 805 | SemaRef.LookupQualifiedName(Result, DC); |
| 806 | switch (Result.getResultKind()) { |
| 807 | case LookupResult::Found: |
| 808 | case LookupResult::FoundOverloaded: |
| 809 | case LookupResult::FoundUnresolvedValue: { |
| 810 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| 811 | unsigned Kind = 0; |
| 812 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
| 813 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2; |
| 814 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 815 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 816 | break; |
| 817 | } |
| 818 | default: |
| 819 | // FIXME: Would be nice to highlight just the source range. |
| 820 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 821 | << Kind << Id << DC; |
| 822 | break; |
| 823 | } |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 824 | return QualType(); |
| 825 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 826 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 827 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 828 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 829 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 830 | return QualType(); |
| 831 | } |
| 832 | |
| 833 | // Build the elaborated-type-specifier type. |
| 834 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 835 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 836 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 838 | /// \brief Build a new pack expansion type. |
| 839 | /// |
| 840 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 841 | /// Subclasses may override this routine to provide different behavior. |
| 842 | QualType RebuildPackExpansionType(QualType Pattern, |
| 843 | SourceRange PatternRange, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 844 | SourceLocation EllipsisLoc, |
| 845 | llvm::Optional<unsigned> NumExpansions) { |
| 846 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 847 | NumExpansions); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 850 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 851 | /// identifier that names the next step in the nested-name-specifier. |
| 852 | /// |
| 853 | /// By default, performs semantic analysis when building the new |
| 854 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 855 | /// different behavior. |
| 856 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 857 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 858 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 859 | QualType ObjectType, |
| 860 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 861 | |
| 862 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 863 | /// namespace named in the next step in the nested-name-specifier. |
| 864 | /// |
| 865 | /// By default, performs semantic analysis when building the new |
| 866 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 867 | /// different behavior. |
| 868 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 869 | SourceRange Range, |
| 870 | NamespaceDecl *NS); |
| 871 | |
| 872 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 873 | /// type named in the next step in the nested-name-specifier. |
| 874 | /// |
| 875 | /// By default, performs semantic analysis when building the new |
| 876 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 877 | /// different behavior. |
| 878 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 879 | SourceRange Range, |
| 880 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 881 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 882 | |
| 883 | /// \brief Build a new template name given a nested name specifier, a flag |
| 884 | /// indicating whether the "template" keyword was provided, and the template |
| 885 | /// that the template name refers to. |
| 886 | /// |
| 887 | /// By default, builds the new template name directly. Subclasses may override |
| 888 | /// this routine to provide different behavior. |
| 889 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 890 | bool TemplateKW, |
| 891 | TemplateDecl *Template); |
| 892 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 893 | /// \brief Build a new template name given a nested name specifier and the |
| 894 | /// name that is referred to as a template. |
| 895 | /// |
| 896 | /// By default, performs semantic analysis to determine whether the name can |
| 897 | /// be resolved to a specific template, then builds the appropriate kind of |
| 898 | /// template name. Subclasses may override this routine to provide different |
| 899 | /// behavior. |
| 900 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 901 | SourceRange QualifierRange, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 902 | const IdentifierInfo &II, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 903 | QualType ObjectType, |
| 904 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 906 | /// \brief Build a new template name given a nested name specifier and the |
| 907 | /// overloaded operator name that is referred to as a template. |
| 908 | /// |
| 909 | /// By default, performs semantic analysis to determine whether the name can |
| 910 | /// be resolved to a specific template, then builds the appropriate kind of |
| 911 | /// template name. Subclasses may override this routine to provide different |
| 912 | /// behavior. |
| 913 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 914 | OverloadedOperatorKind Operator, |
| 915 | QualType ObjectType); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 916 | |
| 917 | /// \brief Build a new template name given a template template parameter pack |
| 918 | /// and the |
| 919 | /// |
| 920 | /// By default, performs semantic analysis to determine whether the name can |
| 921 | /// be resolved to a specific template, then builds the appropriate kind of |
| 922 | /// template name. Subclasses may override this routine to provide different |
| 923 | /// behavior. |
| 924 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 925 | const TemplateArgument &ArgPack) { |
| 926 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 927 | } |
| 928 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 929 | /// \brief Build a new compound statement. |
| 930 | /// |
| 931 | /// By default, performs semantic analysis to build the new statement. |
| 932 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 933 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 934 | MultiStmtArg Statements, |
| 935 | SourceLocation RBraceLoc, |
| 936 | bool IsStmtExpr) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 937 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 938 | IsStmtExpr); |
| 939 | } |
| 940 | |
| 941 | /// \brief Build a new case statement. |
| 942 | /// |
| 943 | /// By default, performs semantic analysis to build the new statement. |
| 944 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 945 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 946 | Expr *LHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 947 | SourceLocation EllipsisLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 948 | Expr *RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 949 | SourceLocation ColonLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 950 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 951 | ColonLoc); |
| 952 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 954 | /// \brief Attach the body to a new case statement. |
| 955 | /// |
| 956 | /// By default, performs semantic analysis to build the new statement. |
| 957 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 958 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 959 | getSema().ActOnCaseStmtBody(S, Body); |
| 960 | return S; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 961 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 962 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 963 | /// \brief Build a new default statement. |
| 964 | /// |
| 965 | /// By default, performs semantic analysis to build the new statement. |
| 966 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 967 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 968 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 969 | Stmt *SubStmt) { |
| 970 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 971 | /*CurScope=*/0); |
| 972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 974 | /// \brief Build a new label statement. |
| 975 | /// |
| 976 | /// By default, performs semantic analysis to build the new statement. |
| 977 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 978 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, IdentifierInfo *Id, |
| 979 | SourceLocation ColonLoc, Stmt *SubStmt, |
| 980 | bool HasUnusedAttr) { |
Argyrios Kyrtzidis | 1a18600 | 2010-09-28 14:54:07 +0000 | [diff] [blame] | 981 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt, |
| 982 | HasUnusedAttr); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 983 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 985 | /// \brief Build a new "if" statement. |
| 986 | /// |
| 987 | /// By default, performs semantic analysis to build the new statement. |
| 988 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 989 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 990 | VarDecl *CondVar, Stmt *Then, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 991 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 992 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 995 | /// \brief Start building a new switch statement. |
| 996 | /// |
| 997 | /// By default, performs semantic analysis to build the new statement. |
| 998 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 999 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1000 | Expr *Cond, VarDecl *CondVar) { |
| 1001 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1002 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1003 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1005 | /// \brief Attach the body to the switch statement. |
| 1006 | /// |
| 1007 | /// By default, performs semantic analysis to build the new statement. |
| 1008 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1009 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1010 | Stmt *Switch, Stmt *Body) { |
| 1011 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /// \brief Build a new while statement. |
| 1015 | /// |
| 1016 | /// By default, performs semantic analysis to build the new statement. |
| 1017 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1018 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 1019 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1020 | VarDecl *CondVar, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1021 | Stmt *Body) { |
| 1022 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1023 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1025 | /// \brief Build a new do-while statement. |
| 1026 | /// |
| 1027 | /// By default, performs semantic analysis to build the new statement. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1029 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1030 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1031 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1032 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1033 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /// \brief Build a new for statement. |
| 1037 | /// |
| 1038 | /// By default, performs semantic analysis to build the new statement. |
| 1039 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1040 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1041 | Stmt *Init, Sema::FullExprArg Cond, |
| 1042 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1043 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1044 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1045 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1048 | /// \brief Build a new goto statement. |
| 1049 | /// |
| 1050 | /// By default, performs semantic analysis to build the new statement. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1052 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1053 | LabelDecl *Label) { |
| 1054 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getIdentifier()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /// \brief Build a new indirect goto statement. |
| 1058 | /// |
| 1059 | /// By default, performs semantic analysis to build the new statement. |
| 1060 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1061 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1062 | SourceLocation StarLoc, |
| 1063 | Expr *Target) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1064 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1067 | /// \brief Build a new return statement. |
| 1068 | /// |
| 1069 | /// By default, performs semantic analysis to build the new statement. |
| 1070 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1071 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1072 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1074 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1075 | /// \brief Build a new declaration 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 | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1079 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1081 | SourceLocation EndLoc) { |
| 1082 | return getSema().Owned( |
| 1083 | new (getSema().Context) DeclStmt( |
| 1084 | DeclGroupRef::Create(getSema().Context, |
| 1085 | Decls, NumDecls), |
| 1086 | StartLoc, EndLoc)); |
| 1087 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1089 | /// \brief Build a new inline asm statement. |
| 1090 | /// |
| 1091 | /// By default, performs semantic analysis to build the new statement. |
| 1092 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1093 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1094 | bool IsSimple, |
| 1095 | bool IsVolatile, |
| 1096 | unsigned NumOutputs, |
| 1097 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1098 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1099 | MultiExprArg Constraints, |
| 1100 | MultiExprArg Exprs, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1101 | Expr *AsmString, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1102 | MultiExprArg Clobbers, |
| 1103 | SourceLocation RParenLoc, |
| 1104 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1105 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1106 | NumInputs, Names, move(Constraints), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1107 | Exprs, AsmString, Clobbers, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1108 | RParenLoc, MSAsm); |
| 1109 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1110 | |
| 1111 | /// \brief Build a new Objective-C @try statement. |
| 1112 | /// |
| 1113 | /// By default, performs semantic analysis to build the new statement. |
| 1114 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1115 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1116 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1117 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1118 | Stmt *Finally) { |
| 1119 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1120 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1123 | /// \brief Rebuild an Objective-C exception declaration. |
| 1124 | /// |
| 1125 | /// By default, performs semantic analysis to build the new declaration. |
| 1126 | /// Subclasses may override this routine to provide different behavior. |
| 1127 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1128 | TypeSourceInfo *TInfo, QualType T) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1129 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1130 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1131 | ExceptionDecl->getLocation()); |
| 1132 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1133 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1134 | /// \brief Build a new Objective-C @catch statement. |
| 1135 | /// |
| 1136 | /// By default, performs semantic analysis to build the new statement. |
| 1137 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1138 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1139 | SourceLocation RParenLoc, |
| 1140 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1141 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1142 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1143 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1144 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1145 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1146 | /// \brief Build a new Objective-C @finally statement. |
| 1147 | /// |
| 1148 | /// By default, performs semantic analysis to build the new statement. |
| 1149 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1150 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1151 | Stmt *Body) { |
| 1152 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1153 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1154 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1155 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1156 | /// |
| 1157 | /// By default, performs semantic analysis to build the new statement. |
| 1158 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1159 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1160 | Expr *Operand) { |
| 1161 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1162 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1163 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1164 | /// \brief Build a new Objective-C @synchronized statement. |
| 1165 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1166 | /// By default, performs semantic analysis to build the new statement. |
| 1167 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1168 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1169 | Expr *Object, |
| 1170 | Stmt *Body) { |
| 1171 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, |
| 1172 | Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1173 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1174 | |
| 1175 | /// \brief Build a new Objective-C fast enumeration 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 | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1179 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1180 | SourceLocation LParenLoc, |
| 1181 | Stmt *Element, |
| 1182 | Expr *Collection, |
| 1183 | SourceLocation RParenLoc, |
| 1184 | Stmt *Body) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1185 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1186 | Element, |
| 1187 | Collection, |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1188 | RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1189 | Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1190 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1191 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1192 | /// \brief Build a new C++ exception declaration. |
| 1193 | /// |
| 1194 | /// By default, performs semantic analysis to build the new decaration. |
| 1195 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1196 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1197 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1198 | IdentifierInfo *Name, |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1199 | SourceLocation Loc) { |
| 1200 | return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /// \brief Build a new C++ catch statement. |
| 1204 | /// |
| 1205 | /// By default, performs semantic analysis to build the new statement. |
| 1206 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1207 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1208 | VarDecl *ExceptionDecl, |
| 1209 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1210 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1211 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1214 | /// \brief Build a new C++ try statement. |
| 1215 | /// |
| 1216 | /// By default, performs semantic analysis to build the new statement. |
| 1217 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1218 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1219 | Stmt *TryBlock, |
| 1220 | MultiStmtArg Handlers) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1221 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1222 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | /// \brief Build a new expression that references a declaration. |
| 1225 | /// |
| 1226 | /// By default, performs semantic analysis to build the new expression. |
| 1227 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1228 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1229 | LookupResult &R, |
| 1230 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1231 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | /// \brief Build a new expression that references a declaration. |
| 1236 | /// |
| 1237 | /// By default, performs semantic analysis to build the new expression. |
| 1238 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1239 | ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1240 | SourceRange QualifierRange, |
| 1241 | ValueDecl *VD, |
| 1242 | const DeclarationNameInfo &NameInfo, |
| 1243 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1244 | CXXScopeSpec SS; |
| 1245 | SS.setScopeRep(Qualifier); |
| 1246 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1247 | |
| 1248 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1249 | |
| 1250 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1251 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1252 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1253 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1255 | /// By default, performs semantic analysis to build the new expression. |
| 1256 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1257 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1258 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1259 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1262 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1264 | /// By default, performs semantic analysis to build the new expression. |
| 1265 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1266 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1267 | SourceLocation OperatorLoc, |
| 1268 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1269 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1270 | SourceRange QualifierRange, |
| 1271 | TypeSourceInfo *ScopeType, |
| 1272 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1273 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1274 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1275 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1276 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1278 | /// By default, performs semantic analysis to build the new expression. |
| 1279 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1280 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1281 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1282 | Expr *SubExpr) { |
| 1283 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1284 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1286 | /// \brief Build a new builtin offsetof expression. |
| 1287 | /// |
| 1288 | /// By default, performs semantic analysis to build the new expression. |
| 1289 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1290 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1291 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1292 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1293 | unsigned NumComponents, |
| 1294 | SourceLocation RParenLoc) { |
| 1295 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1296 | NumComponents, RParenLoc); |
| 1297 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1298 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1299 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1300 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1301 | /// By default, performs semantic analysis to build the new expression. |
| 1302 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1303 | ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1304 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1306 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | /// By default, performs semantic analysis to build the new expression. |
| 1313 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1314 | ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | bool isSizeOf, SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1316 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1317 | = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1318 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1319 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | return move(Result); |
| 1322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// By default, performs semantic analysis to build the new expression. |
| 1327 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1328 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1330 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1332 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1333 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | RBracketLoc); |
| 1335 | } |
| 1336 | |
| 1337 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | /// By default, performs semantic analysis to build the new expression. |
| 1340 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1341 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | MultiExprArg Args, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1343 | SourceLocation RParenLoc, |
| 1344 | Expr *ExecConfig = 0) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1345 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1346 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1351 | /// By default, performs semantic analysis to build the new expression. |
| 1352 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1353 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1354 | bool isArrow, |
| 1355 | NestedNameSpecifier *Qualifier, |
| 1356 | SourceRange QualifierRange, |
| 1357 | const DeclarationNameInfo &MemberNameInfo, |
| 1358 | ValueDecl *Member, |
| 1359 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1360 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1361 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1362 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1363 | // We have a reference to an unnamed field. This is always the |
| 1364 | // base of an anonymous struct/union member access, i.e. the |
| 1365 | // field is always of record type. |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1366 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1367 | assert(Member->getType()->isRecordType() && |
| 1368 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1370 | if (getSema().PerformObjectMemberConversion(Base, Qualifier, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1371 | FoundDecl, Member)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1372 | return ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1373 | |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1374 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1376 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1377 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1378 | cast<FieldDecl>(Member)->getType(), |
| 1379 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1380 | return getSema().Owned(ME); |
| 1381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1383 | CXXScopeSpec SS; |
| 1384 | if (Qualifier) { |
| 1385 | SS.setRange(QualifierRange); |
| 1386 | SS.setScopeRep(Qualifier); |
| 1387 | } |
| 1388 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1389 | getSema().DefaultFunctionArrayConversion(Base); |
| 1390 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1391 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1392 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1393 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1394 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1395 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1396 | R.resolveKind(); |
| 1397 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1398 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1399 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1400 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1401 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | /// By default, performs semantic analysis to build the new expression. |
| 1406 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1407 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1408 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1409 | Expr *LHS, Expr *RHS) { |
| 1410 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | /// By default, performs semantic analysis to build the new expression. |
| 1416 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1417 | ExprResult RebuildConditionalOperator(Expr *Cond, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | SourceLocation QuestionLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1419 | Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1420 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1421 | Expr *RHS) { |
| 1422 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1423 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | /// By default, performs semantic analysis to build the new expression. |
| 1429 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1430 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1431 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1432 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1433 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1434 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1435 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1440 | /// By default, performs semantic analysis to build the new expression. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1442 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1443 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1444 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1445 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1446 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1447 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1450 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1451 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1452 | /// By default, performs semantic analysis to build the new expression. |
| 1453 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1454 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | SourceLocation OpLoc, |
| 1456 | SourceLocation AccessorLoc, |
| 1457 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1458 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1459 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1460 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1461 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1462 | OpLoc, /*IsArrow*/ false, |
| 1463 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1464 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1465 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1467 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1468 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1469 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | /// By default, performs semantic analysis to build the new expression. |
| 1471 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1472 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1473 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1474 | SourceLocation RBraceLoc, |
| 1475 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1476 | ExprResult Result |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1477 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1478 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1479 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1480 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1481 | // Patch in the result type we were given, which may have been computed |
| 1482 | // when the initial InitListExpr was built. |
| 1483 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1484 | ILE->setType(ResultTy); |
| 1485 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1486 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1488 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | /// By default, performs semantic analysis to build the new expression. |
| 1491 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1492 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | MultiExprArg ArrayExprs, |
| 1494 | SourceLocation EqualOrColonLoc, |
| 1495 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1496 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1497 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1499 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1501 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | ArrayExprs.release(); |
| 1504 | return move(Result); |
| 1505 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1506 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1508 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1509 | /// By default, builds the implicit value initialization without performing |
| 1510 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1511 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1512 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1514 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1515 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1517 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | /// By default, performs semantic analysis to build the new expression. |
| 1519 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1520 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1521 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1522 | SourceLocation RParenLoc) { |
| 1523 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1524 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1525 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1529 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | /// By default, performs semantic analysis to build the new expression. |
| 1531 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1532 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | MultiExprArg SubExprs, |
| 1534 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1535 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1536 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1540 | /// |
| 1541 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1542 | /// rather than attempting to map the label statement itself. |
| 1543 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1544 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 1545 | SourceLocation LabelLoc, LabelDecl *Label) { |
| 1546 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc,Label->getIdentifier()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1547 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1551 | /// By default, performs semantic analysis to build the new expression. |
| 1552 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1553 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1554 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1556 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1558 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | /// \brief Build a new __builtin_choose_expr expression. |
| 1560 | /// |
| 1561 | /// By default, performs semantic analysis to build the new expression. |
| 1562 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1563 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1564 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | SourceLocation RParenLoc) { |
| 1566 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1567 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | RParenLoc); |
| 1569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1570 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | /// \brief Build a new overloaded operator call expression. |
| 1572 | /// |
| 1573 | /// By default, performs semantic analysis to build the new expression. |
| 1574 | /// The semantic analysis provides the behavior of template instantiation, |
| 1575 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1576 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1577 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1578 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1579 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1580 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1581 | Expr *Callee, |
| 1582 | Expr *First, |
| 1583 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1584 | |
| 1585 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1586 | /// reinterpret_cast. |
| 1587 | /// |
| 1588 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1589 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1590 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1591 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1592 | Stmt::StmtClass Class, |
| 1593 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1594 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | SourceLocation RAngleLoc, |
| 1596 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1597 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1598 | SourceLocation RParenLoc) { |
| 1599 | switch (Class) { |
| 1600 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1601 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1602 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1603 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | |
| 1605 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1606 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1608 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1611 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1612 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1613 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1617 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1618 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1619 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1621 | default: |
| 1622 | assert(false && "Invalid C++ named cast"); |
| 1623 | break; |
| 1624 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1626 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1628 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1629 | /// \brief Build a new C++ static_cast expression. |
| 1630 | /// |
| 1631 | /// By default, performs semantic analysis to build the new expression. |
| 1632 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1633 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1635 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | SourceLocation RAngleLoc, |
| 1637 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1638 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1639 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1640 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1641 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1642 | SourceRange(LAngleLoc, RAngleLoc), |
| 1643 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | /// \brief Build a new C++ dynamic_cast expression. |
| 1647 | /// |
| 1648 | /// By default, performs semantic analysis to build the new expression. |
| 1649 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1650 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1651 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1652 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | SourceLocation RAngleLoc, |
| 1654 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1655 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1657 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1658 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1659 | SourceRange(LAngleLoc, RAngleLoc), |
| 1660 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1664 | /// |
| 1665 | /// By default, performs semantic analysis to build the new expression. |
| 1666 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1667 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1668 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1669 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1670 | SourceLocation RAngleLoc, |
| 1671 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1672 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1674 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1675 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1676 | SourceRange(LAngleLoc, RAngleLoc), |
| 1677 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | /// \brief Build a new C++ const_cast expression. |
| 1681 | /// |
| 1682 | /// By default, performs semantic analysis to build the new expression. |
| 1683 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1684 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1685 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1686 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | SourceLocation RAngleLoc, |
| 1688 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1689 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1690 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1691 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1692 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1693 | SourceRange(LAngleLoc, RAngleLoc), |
| 1694 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1697 | /// \brief Build a new C++ functional-style cast expression. |
| 1698 | /// |
| 1699 | /// By default, performs semantic analysis to build the new expression. |
| 1700 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1701 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1702 | SourceLocation LParenLoc, |
| 1703 | Expr *Sub, |
| 1704 | SourceLocation RParenLoc) { |
| 1705 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1706 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1707 | RParenLoc); |
| 1708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1709 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | /// \brief Build a new C++ typeid(type) expression. |
| 1711 | /// |
| 1712 | /// By default, performs semantic analysis to build the new expression. |
| 1713 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1714 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1715 | SourceLocation TypeidLoc, |
| 1716 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1717 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1718 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1719 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1722 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | /// \brief Build a new C++ typeid(expr) expression. |
| 1724 | /// |
| 1725 | /// By default, performs semantic analysis to build the new expression. |
| 1726 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1727 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1728 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1729 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1731 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1732 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1735 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1736 | /// |
| 1737 | /// By default, performs semantic analysis to build the new expression. |
| 1738 | /// Subclasses may override this routine to provide different behavior. |
| 1739 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1740 | SourceLocation TypeidLoc, |
| 1741 | TypeSourceInfo *Operand, |
| 1742 | SourceLocation RParenLoc) { |
| 1743 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1744 | RParenLoc); |
| 1745 | } |
| 1746 | |
| 1747 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1748 | /// |
| 1749 | /// By default, performs semantic analysis to build the new expression. |
| 1750 | /// Subclasses may override this routine to provide different behavior. |
| 1751 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1752 | SourceLocation TypeidLoc, |
| 1753 | Expr *Operand, |
| 1754 | SourceLocation RParenLoc) { |
| 1755 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1756 | RParenLoc); |
| 1757 | } |
| 1758 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | /// \brief Build a new C++ "this" expression. |
| 1760 | /// |
| 1761 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1762 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1763 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1764 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1765 | QualType ThisType, |
| 1766 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1768 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1769 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | /// \brief Build a new C++ throw expression. |
| 1773 | /// |
| 1774 | /// By default, performs semantic analysis to build the new expression. |
| 1775 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1776 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1777 | return getSema().ActOnCXXThrow(ThrowLoc, Sub); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | /// \brief Build a new C++ default-argument expression. |
| 1781 | /// |
| 1782 | /// By default, builds a new default-argument expression, which does not |
| 1783 | /// require any semantic analysis. Subclasses may override this routine to |
| 1784 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1785 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1786 | ParmVarDecl *Param) { |
| 1787 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1788 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | /// \brief Build a new C++ zero-initialization expression. |
| 1792 | /// |
| 1793 | /// By default, performs semantic analysis to build the new expression. |
| 1794 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1795 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1796 | SourceLocation LParenLoc, |
| 1797 | SourceLocation RParenLoc) { |
| 1798 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1799 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1800 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1801 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1802 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1803 | /// \brief Build a new C++ "new" expression. |
| 1804 | /// |
| 1805 | /// By default, performs semantic analysis to build the new expression. |
| 1806 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1807 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1808 | bool UseGlobal, |
| 1809 | SourceLocation PlacementLParen, |
| 1810 | MultiExprArg PlacementArgs, |
| 1811 | SourceLocation PlacementRParen, |
| 1812 | SourceRange TypeIdParens, |
| 1813 | QualType AllocatedType, |
| 1814 | TypeSourceInfo *AllocatedTypeInfo, |
| 1815 | Expr *ArraySize, |
| 1816 | SourceLocation ConstructorLParen, |
| 1817 | MultiExprArg ConstructorArgs, |
| 1818 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1820 | PlacementLParen, |
| 1821 | move(PlacementArgs), |
| 1822 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1823 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1824 | AllocatedType, |
| 1825 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1826 | ArraySize, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1827 | ConstructorLParen, |
| 1828 | move(ConstructorArgs), |
| 1829 | ConstructorRParen); |
| 1830 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1832 | /// \brief Build a new C++ "delete" expression. |
| 1833 | /// |
| 1834 | /// By default, performs semantic analysis to build the new expression. |
| 1835 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1836 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1837 | bool IsGlobalDelete, |
| 1838 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1839 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1840 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1841 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1842 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1844 | /// \brief Build a new unary type trait 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 | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1848 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1849 | SourceLocation StartLoc, |
| 1850 | TypeSourceInfo *T, |
| 1851 | SourceLocation RParenLoc) { |
| 1852 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1855 | /// \brief Build a new binary type trait expression. |
| 1856 | /// |
| 1857 | /// By default, performs semantic analysis to build the new expression. |
| 1858 | /// Subclasses may override this routine to provide different behavior. |
| 1859 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1860 | SourceLocation StartLoc, |
| 1861 | TypeSourceInfo *LhsT, |
| 1862 | TypeSourceInfo *RhsT, |
| 1863 | SourceLocation RParenLoc) { |
| 1864 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1865 | } |
| 1866 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1868 | /// expression. |
| 1869 | /// |
| 1870 | /// By default, performs semantic analysis to build the new expression. |
| 1871 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1872 | ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1873 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1874 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1875 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1876 | CXXScopeSpec SS; |
| 1877 | SS.setRange(QualifierRange); |
| 1878 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1879 | |
| 1880 | if (TemplateArgs) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1881 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1882 | *TemplateArgs); |
| 1883 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1884 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /// \brief Build a new template-id expression. |
| 1888 | /// |
| 1889 | /// By default, performs semantic analysis to build the new expression. |
| 1890 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1891 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1892 | LookupResult &R, |
| 1893 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1894 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1895 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | /// \brief Build a new object-construction expression. |
| 1899 | /// |
| 1900 | /// By default, performs semantic analysis to build the new expression. |
| 1901 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1902 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1903 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1904 | CXXConstructorDecl *Constructor, |
| 1905 | bool IsElidable, |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1906 | MultiExprArg Args, |
| 1907 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1908 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 1909 | SourceRange ParenRange) { |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1910 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1911 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1912 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1913 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1914 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1915 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1916 | move_arg(ConvertedArgs), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1917 | RequiresZeroInit, ConstructKind, |
| 1918 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /// \brief Build a new object-construction expression. |
| 1922 | /// |
| 1923 | /// By default, performs semantic analysis to build the new expression. |
| 1924 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1925 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 1926 | SourceLocation LParenLoc, |
| 1927 | MultiExprArg Args, |
| 1928 | SourceLocation RParenLoc) { |
| 1929 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1930 | LParenLoc, |
| 1931 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1932 | RParenLoc); |
| 1933 | } |
| 1934 | |
| 1935 | /// \brief Build a new object-construction expression. |
| 1936 | /// |
| 1937 | /// By default, performs semantic analysis to build the new expression. |
| 1938 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1939 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 1940 | SourceLocation LParenLoc, |
| 1941 | MultiExprArg Args, |
| 1942 | SourceLocation RParenLoc) { |
| 1943 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1944 | LParenLoc, |
| 1945 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1946 | RParenLoc); |
| 1947 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1948 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | /// \brief Build a new member reference expression. |
| 1950 | /// |
| 1951 | /// By default, performs semantic analysis to build the new expression. |
| 1952 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1953 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1954 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1955 | bool IsArrow, |
| 1956 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1957 | NestedNameSpecifier *Qualifier, |
| 1958 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1959 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1960 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1961 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1963 | SS.setRange(QualifierRange); |
| 1964 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1966 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1967 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1968 | SS, FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1969 | MemberNameInfo, |
| 1970 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1973 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1974 | /// |
| 1975 | /// By default, performs semantic analysis to build the new expression. |
| 1976 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1977 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1978 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1979 | SourceLocation OperatorLoc, |
| 1980 | bool IsArrow, |
| 1981 | NestedNameSpecifier *Qualifier, |
| 1982 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1983 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1984 | LookupResult &R, |
| 1985 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1986 | CXXScopeSpec SS; |
| 1987 | SS.setRange(QualifierRange); |
| 1988 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1989 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1990 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1991 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1992 | SS, FirstQualifierInScope, |
| 1993 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 1996 | /// \brief Build a new noexcept expression. |
| 1997 | /// |
| 1998 | /// By default, performs semantic analysis to build the new expression. |
| 1999 | /// Subclasses may override this routine to provide different behavior. |
| 2000 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2001 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2002 | } |
| 2003 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2004 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2005 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2006 | SourceLocation PackLoc, |
| 2007 | SourceLocation RParenLoc, |
| 2008 | unsigned Length) { |
| 2009 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2010 | OperatorLoc, Pack, PackLoc, |
| 2011 | RParenLoc, Length); |
| 2012 | } |
| 2013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | /// \brief Build a new Objective-C @encode expression. |
| 2015 | /// |
| 2016 | /// By default, performs semantic analysis to build the new expression. |
| 2017 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2018 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2019 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2020 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2021 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2022 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2023 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2024 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2025 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2026 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2027 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2028 | SourceLocation SelectorLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2029 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2030 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2031 | MultiExprArg Args, |
| 2032 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2033 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2034 | ReceiverTypeInfo->getType(), |
| 2035 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2036 | Sel, Method, LBracLoc, SelectorLoc, |
| 2037 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2041 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2042 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2043 | SourceLocation SelectorLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2044 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2045 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2046 | MultiExprArg Args, |
| 2047 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2048 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2049 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2050 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2051 | Sel, Method, LBracLoc, SelectorLoc, |
| 2052 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2055 | /// \brief Build a new Objective-C ivar reference expression. |
| 2056 | /// |
| 2057 | /// By default, performs semantic analysis to build the new expression. |
| 2058 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2059 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2060 | SourceLocation IvarLoc, |
| 2061 | bool IsArrow, bool IsFreeIvar) { |
| 2062 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2063 | CXXScopeSpec SS; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2064 | Expr *Base = BaseArg; |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2065 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2066 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2067 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2068 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2069 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2070 | false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2071 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2072 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2073 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2074 | if (Result.get()) |
| 2075 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2076 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2077 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2078 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2079 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2080 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2081 | /*TemplateArgs=*/0); |
| 2082 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2083 | |
| 2084 | /// \brief Build a new Objective-C property reference expression. |
| 2085 | /// |
| 2086 | /// By default, performs semantic analysis to build the new expression. |
| 2087 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2088 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2089 | ObjCPropertyDecl *Property, |
| 2090 | SourceLocation PropertyLoc) { |
| 2091 | CXXScopeSpec SS; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2092 | Expr *Base = BaseArg; |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2093 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2094 | Sema::LookupMemberName); |
| 2095 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2096 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2097 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2098 | SS, 0, false); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2099 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2100 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2101 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2102 | if (Result.get()) |
| 2103 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2104 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2105 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2106 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2107 | SS, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2108 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2109 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2110 | /*TemplateArgs=*/0); |
| 2111 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2112 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2113 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2114 | /// |
| 2115 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2116 | /// Subclasses may override this routine to provide different behavior. |
| 2117 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2118 | ObjCMethodDecl *Getter, |
| 2119 | ObjCMethodDecl *Setter, |
| 2120 | SourceLocation PropertyLoc) { |
| 2121 | // Since these expressions can only be value-dependent, we do not |
| 2122 | // need to perform semantic analysis again. |
| 2123 | return Owned( |
| 2124 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2125 | VK_LValue, OK_ObjCProperty, |
| 2126 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2129 | /// \brief Build a new Objective-C "isa" expression. |
| 2130 | /// |
| 2131 | /// By default, performs semantic analysis to build the new expression. |
| 2132 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2133 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2134 | bool IsArrow) { |
| 2135 | CXXScopeSpec SS; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2136 | Expr *Base = BaseArg; |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2137 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2138 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2139 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2140 | /*FIME:*/IsaLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2141 | SS, 0, false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2142 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2143 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2144 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2145 | if (Result.get()) |
| 2146 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2147 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2148 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2149 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2150 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2151 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2152 | /*TemplateArgs=*/0); |
| 2153 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2155 | /// \brief Build a new shuffle vector expression. |
| 2156 | /// |
| 2157 | /// By default, performs semantic analysis to build the new expression. |
| 2158 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2159 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2160 | MultiExprArg SubExprs, |
| 2161 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2162 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2163 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2164 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2165 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2166 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2167 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2169 | // Build a reference to the __builtin_shufflevector builtin |
| 2170 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2173 | VK_LValue, BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2174 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2175 | |
| 2176 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | unsigned NumSubExprs = SubExprs.size(); |
| 2178 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2179 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 2180 | Subs, NumSubExprs, |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2181 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2182 | Expr::getValueKindForType(Builtin->getResultType()), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2183 | RParenLoc); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2184 | ExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2186 | // Type-check the __builtin_shufflevector expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2187 | ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2188 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2189 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2190 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2191 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2192 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2193 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2194 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2195 | /// \brief Build a new template argument pack expansion. |
| 2196 | /// |
| 2197 | /// By default, performs semantic analysis to build a new pack expansion |
| 2198 | /// for a template argument. Subclasses may override this routine to provide |
| 2199 | /// different behavior. |
| 2200 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2201 | SourceLocation EllipsisLoc, |
| 2202 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2203 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2204 | case TemplateArgument::Expression: { |
| 2205 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2206 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2207 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2208 | if (Result.isInvalid()) |
| 2209 | return TemplateArgumentLoc(); |
| 2210 | |
| 2211 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2212 | } |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2213 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2214 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2215 | return TemplateArgumentLoc(TemplateArgument( |
| 2216 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2217 | NumExpansions), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2218 | Pattern.getTemplateQualifierRange(), |
| 2219 | Pattern.getTemplateNameLoc(), |
| 2220 | EllipsisLoc); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2221 | |
| 2222 | case TemplateArgument::Null: |
| 2223 | case TemplateArgument::Integral: |
| 2224 | case TemplateArgument::Declaration: |
| 2225 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2226 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2227 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2228 | |
| 2229 | case TemplateArgument::Type: |
| 2230 | if (TypeSourceInfo *Expansion |
| 2231 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2232 | EllipsisLoc, |
| 2233 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2234 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2235 | Expansion); |
| 2236 | break; |
| 2237 | } |
| 2238 | |
| 2239 | return TemplateArgumentLoc(); |
| 2240 | } |
| 2241 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2242 | /// \brief Build a new expression pack expansion. |
| 2243 | /// |
| 2244 | /// By default, performs semantic analysis to build a new pack expansion |
| 2245 | /// for an expression. Subclasses may override this routine to provide |
| 2246 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2247 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2248 | llvm::Optional<unsigned> NumExpansions) { |
| 2249 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2252 | private: |
| 2253 | QualType TransformTypeInObjectScope(QualType T, |
| 2254 | QualType ObjectType, |
| 2255 | NamedDecl *FirstQualifierInScope, |
| 2256 | NestedNameSpecifier *Prefix); |
| 2257 | |
| 2258 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T, |
| 2259 | QualType ObjectType, |
| 2260 | NamedDecl *FirstQualifierInScope, |
| 2261 | NestedNameSpecifier *Prefix); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2262 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2263 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2264 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2265 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2266 | if (!S) |
| 2267 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2268 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2269 | switch (S->getStmtClass()) { |
| 2270 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2271 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2272 | // Transform individual statement nodes |
| 2273 | #define STMT(Node, Parent) \ |
| 2274 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2275 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2276 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2277 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2279 | // Transform expressions by calling TransformExpr. |
| 2280 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2281 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2282 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2283 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2284 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2285 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2286 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2287 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2288 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2289 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2293 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2295 | |
| 2296 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2297 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2298 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2299 | if (!E) |
| 2300 | return SemaRef.Owned(E); |
| 2301 | |
| 2302 | switch (E->getStmtClass()) { |
| 2303 | case Stmt::NoStmtClass: break; |
| 2304 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2305 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2307 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2308 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2311 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | template<typename Derived> |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2315 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2316 | unsigned NumInputs, |
| 2317 | bool IsCall, |
| 2318 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 2319 | bool *ArgChanged) { |
| 2320 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2321 | // If requested, drop call arguments that need to be dropped. |
| 2322 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2323 | if (ArgChanged) |
| 2324 | *ArgChanged = true; |
| 2325 | |
| 2326 | break; |
| 2327 | } |
| 2328 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2329 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2330 | Expr *Pattern = Expansion->getPattern(); |
| 2331 | |
| 2332 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2333 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2334 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2335 | |
| 2336 | // Determine whether the set of unexpanded parameter packs can and should |
| 2337 | // be expanded. |
| 2338 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2339 | bool RetainExpansion = false; |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2340 | llvm::Optional<unsigned> OrigNumExpansions |
| 2341 | = Expansion->getNumExpansions(); |
| 2342 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2343 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2344 | Pattern->getSourceRange(), |
| 2345 | Unexpanded.data(), |
| 2346 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2347 | Expand, RetainExpansion, |
| 2348 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2349 | return true; |
| 2350 | |
| 2351 | if (!Expand) { |
| 2352 | // The transform has determined that we should perform a simple |
| 2353 | // transformation on the pack expansion, producing another pack |
| 2354 | // expansion. |
| 2355 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2356 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2357 | if (OutPattern.isInvalid()) |
| 2358 | return true; |
| 2359 | |
| 2360 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2361 | Expansion->getEllipsisLoc(), |
| 2362 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2363 | if (Out.isInvalid()) |
| 2364 | return true; |
| 2365 | |
| 2366 | if (ArgChanged) |
| 2367 | *ArgChanged = true; |
| 2368 | Outputs.push_back(Out.get()); |
| 2369 | continue; |
| 2370 | } |
| 2371 | |
| 2372 | // The transform has determined that we should perform an elementwise |
| 2373 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2374 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2375 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2376 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2377 | if (Out.isInvalid()) |
| 2378 | return true; |
| 2379 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2380 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2381 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2382 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2383 | if (Out.isInvalid()) |
| 2384 | return true; |
| 2385 | } |
| 2386 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2387 | if (ArgChanged) |
| 2388 | *ArgChanged = true; |
| 2389 | Outputs.push_back(Out.get()); |
| 2390 | } |
| 2391 | |
| 2392 | continue; |
| 2393 | } |
| 2394 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2395 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2396 | if (Result.isInvalid()) |
| 2397 | return true; |
| 2398 | |
| 2399 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2400 | *ArgChanged = true; |
| 2401 | |
| 2402 | Outputs.push_back(Result.get()); |
| 2403 | } |
| 2404 | |
| 2405 | return false; |
| 2406 | } |
| 2407 | |
| 2408 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2409 | NestedNameSpecifier * |
| 2410 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2411 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2412 | QualType ObjectType, |
| 2413 | NamedDecl *FirstQualifierInScope) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2414 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2415 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2416 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2417 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2418 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2419 | ObjectType, |
| 2420 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2421 | if (!Prefix) |
| 2422 | return 0; |
| 2423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2424 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2425 | switch (NNS->getKind()) { |
| 2426 | case NestedNameSpecifier::Identifier: |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2427 | if (Prefix) { |
| 2428 | // The object type and qualifier-in-scope really apply to the |
| 2429 | // leftmost entity. |
| 2430 | ObjectType = QualType(); |
| 2431 | FirstQualifierInScope = 0; |
| 2432 | } |
| 2433 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2434 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2435 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2436 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2437 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2438 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | |
| 2440 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2441 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2442 | ObjectType, |
| 2443 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2444 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2445 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2446 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2447 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2448 | getDerived().TransformDecl(Range.getBegin(), |
| 2449 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2450 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2451 | Prefix == NNS->getPrefix() && |
| 2452 | NS == NNS->getAsNamespace()) |
| 2453 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2454 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2455 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2457 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2458 | case NestedNameSpecifier::Global: |
| 2459 | // There is no meaningful transformation that one could perform on the |
| 2460 | // global scope. |
| 2461 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2462 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2463 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2464 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2465 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2466 | QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0), |
| 2467 | ObjectType, |
| 2468 | FirstQualifierInScope, |
| 2469 | Prefix); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2470 | if (T.isNull()) |
| 2471 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2472 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2473 | if (!getDerived().AlwaysRebuild() && |
| 2474 | Prefix == NNS->getPrefix() && |
| 2475 | T == QualType(NNS->getAsType(), 0)) |
| 2476 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2477 | |
| 2478 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2479 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2480 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2481 | } |
| 2482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2483 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2484 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2485 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2489 | DeclarationNameInfo |
| 2490 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2491 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2492 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2493 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2494 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2495 | |
| 2496 | switch (Name.getNameKind()) { |
| 2497 | case DeclarationName::Identifier: |
| 2498 | case DeclarationName::ObjCZeroArgSelector: |
| 2499 | case DeclarationName::ObjCOneArgSelector: |
| 2500 | case DeclarationName::ObjCMultiArgSelector: |
| 2501 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2502 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2503 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2504 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2505 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2506 | case DeclarationName::CXXConstructorName: |
| 2507 | case DeclarationName::CXXDestructorName: |
| 2508 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2509 | TypeSourceInfo *NewTInfo; |
| 2510 | CanQualType NewCanTy; |
| 2511 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2512 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2513 | if (!NewTInfo) |
| 2514 | return DeclarationNameInfo(); |
| 2515 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2516 | } |
| 2517 | else { |
| 2518 | NewTInfo = 0; |
| 2519 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2520 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2521 | if (NewT.isNull()) |
| 2522 | return DeclarationNameInfo(); |
| 2523 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2525 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2526 | DeclarationName NewName |
| 2527 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2528 | NewCanTy); |
| 2529 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2530 | NewNameInfo.setName(NewName); |
| 2531 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2532 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2533 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2536 | assert(0 && "Unknown name kind."); |
| 2537 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2541 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2542 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2543 | QualType ObjectType, |
| 2544 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2545 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2546 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2547 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2548 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2549 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2550 | /*FIXME*/ SourceRange(Loc), |
| 2551 | ObjectType, |
| 2552 | FirstQualifierInScope); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2553 | if (!NNS) |
| 2554 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2555 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2556 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2558 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2559 | if (!TransTemplate) |
| 2560 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2562 | if (!getDerived().AlwaysRebuild() && |
| 2563 | NNS == QTN->getQualifier() && |
| 2564 | TransTemplate == Template) |
| 2565 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2566 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2567 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2568 | TransTemplate); |
| 2569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2570 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2571 | // These should be getting filtered out before they make it into the AST. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2572 | llvm_unreachable("overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2575 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2576 | NestedNameSpecifier *NNS = DTN->getQualifier(); |
| 2577 | if (NNS) { |
| 2578 | NNS = getDerived().TransformNestedNameSpecifier(NNS, |
| 2579 | /*FIXME:*/SourceRange(Loc), |
| 2580 | ObjectType, |
| 2581 | FirstQualifierInScope); |
| 2582 | if (!NNS) return TemplateName(); |
| 2583 | |
| 2584 | // These apply to the scope specifier, not the template. |
| 2585 | ObjectType = QualType(); |
| 2586 | FirstQualifierInScope = 0; |
| 2587 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2588 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2589 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2590 | NNS == DTN->getQualifier() && |
| 2591 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2592 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2593 | |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2594 | if (DTN->isIdentifier()) { |
| 2595 | // FIXME: Bad range |
| 2596 | SourceRange QualifierRange(getDerived().getBaseLocation()); |
| 2597 | return getDerived().RebuildTemplateName(NNS, QualifierRange, |
| 2598 | *DTN->getIdentifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2599 | ObjectType, |
| 2600 | FirstQualifierInScope); |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2601 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2602 | |
| 2603 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2604 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2605 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2606 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2607 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2608 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2609 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2610 | if (!TransTemplate) |
| 2611 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2612 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2613 | if (!getDerived().AlwaysRebuild() && |
| 2614 | TransTemplate == Template) |
| 2615 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2616 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2617 | return TemplateName(TransTemplate); |
| 2618 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 | |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 2620 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2621 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2622 | TemplateTemplateParmDecl *TransParam |
| 2623 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2624 | getDerived().TransformDecl(Loc, SubstPack->getParameterPack())); |
| 2625 | if (!TransParam) |
| 2626 | return TemplateName(); |
| 2627 | |
| 2628 | if (!getDerived().AlwaysRebuild() && |
| 2629 | TransParam == SubstPack->getParameterPack()) |
| 2630 | return Name; |
| 2631 | |
| 2632 | return getDerived().RebuildTemplateName(TransParam, |
| 2633 | SubstPack->getArgumentPack()); |
| 2634 | } |
| 2635 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2636 | // These should be getting filtered out before they reach the AST. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2637 | llvm_unreachable("overloaded function decl survived to here"); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2638 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2642 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2643 | const TemplateArgument &Arg, |
| 2644 | TemplateArgumentLoc &Output) { |
| 2645 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2646 | switch (Arg.getKind()) { |
| 2647 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2648 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2649 | break; |
| 2650 | |
| 2651 | case TemplateArgument::Type: |
| 2652 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2653 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2654 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2655 | break; |
| 2656 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2657 | case TemplateArgument::Template: |
| 2658 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2659 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2660 | |
| 2661 | case TemplateArgument::TemplateExpansion: |
| 2662 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc); |
| 2663 | break; |
| 2664 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2665 | case TemplateArgument::Expression: |
| 2666 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2667 | break; |
| 2668 | |
| 2669 | case TemplateArgument::Declaration: |
| 2670 | case TemplateArgument::Integral: |
| 2671 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2672 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | template<typename Derived> |
| 2678 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2679 | const TemplateArgumentLoc &Input, |
| 2680 | TemplateArgumentLoc &Output) { |
| 2681 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2682 | switch (Arg.getKind()) { |
| 2683 | case TemplateArgument::Null: |
| 2684 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2685 | Output = Input; |
| 2686 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2688 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2689 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2690 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2691 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2692 | |
| 2693 | DI = getDerived().TransformType(DI); |
| 2694 | if (!DI) return true; |
| 2695 | |
| 2696 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2697 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2698 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2699 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2700 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2701 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2702 | DeclarationName Name; |
| 2703 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2704 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2705 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2706 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2707 | if (!D) return true; |
| 2708 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2709 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2710 | if (SourceExpr) { |
| 2711 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2712 | Sema::Unevaluated); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2713 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2714 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2718 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2719 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2720 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2721 | case TemplateArgument::Template: { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2722 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2723 | TemplateName Template |
| 2724 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2725 | if (Template.isNull()) |
| 2726 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2727 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2728 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2729 | Input.getTemplateQualifierRange(), |
| 2730 | Input.getTemplateNameLoc()); |
| 2731 | return false; |
| 2732 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2733 | |
| 2734 | case TemplateArgument::TemplateExpansion: |
| 2735 | llvm_unreachable("Caller should expand pack expansions"); |
| 2736 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2737 | case TemplateArgument::Expression: { |
| 2738 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2739 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2740 | Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2742 | Expr *InputExpr = Input.getSourceExpression(); |
| 2743 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2744 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2745 | ExprResult E |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2746 | = getDerived().TransformExpr(InputExpr); |
| 2747 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2748 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2749 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2750 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2751 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2752 | case TemplateArgument::Pack: { |
| 2753 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2754 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2755 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2756 | AEnd = Arg.pack_end(); |
| 2757 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2758 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2759 | // FIXME: preserve source information here when we start |
| 2760 | // caring about parameter packs. |
| 2761 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2762 | TemplateArgumentLoc InputArg; |
| 2763 | TemplateArgumentLoc OutputArg; |
| 2764 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2765 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2766 | return true; |
| 2767 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2768 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2769 | } |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2770 | |
| 2771 | TemplateArgument *TransformedArgsPtr |
| 2772 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2773 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2774 | TransformedArgsPtr); |
| 2775 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2776 | TransformedArgs.size()), |
| 2777 | Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2778 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2779 | } |
| 2780 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2782 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2783 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2786 | /// \brief Iterator adaptor that invents template argument location information |
| 2787 | /// for each of the template arguments in its underlying iterator. |
| 2788 | template<typename Derived, typename InputIterator> |
| 2789 | class TemplateArgumentLocInventIterator { |
| 2790 | TreeTransform<Derived> &Self; |
| 2791 | InputIterator Iter; |
| 2792 | |
| 2793 | public: |
| 2794 | typedef TemplateArgumentLoc value_type; |
| 2795 | typedef TemplateArgumentLoc reference; |
| 2796 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2797 | difference_type; |
| 2798 | typedef std::input_iterator_tag iterator_category; |
| 2799 | |
| 2800 | class pointer { |
| 2801 | TemplateArgumentLoc Arg; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2802 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2803 | public: |
| 2804 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2805 | |
| 2806 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2807 | }; |
| 2808 | |
| 2809 | TemplateArgumentLocInventIterator() { } |
| 2810 | |
| 2811 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2812 | InputIterator Iter) |
| 2813 | : Self(Self), Iter(Iter) { } |
| 2814 | |
| 2815 | TemplateArgumentLocInventIterator &operator++() { |
| 2816 | ++Iter; |
| 2817 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2820 | TemplateArgumentLocInventIterator operator++(int) { |
| 2821 | TemplateArgumentLocInventIterator Old(*this); |
| 2822 | ++(*this); |
| 2823 | return Old; |
| 2824 | } |
| 2825 | |
| 2826 | reference operator*() const { |
| 2827 | TemplateArgumentLoc Result; |
| 2828 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 2829 | return Result; |
| 2830 | } |
| 2831 | |
| 2832 | pointer operator->() const { return pointer(**this); } |
| 2833 | |
| 2834 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 2835 | const TemplateArgumentLocInventIterator &Y) { |
| 2836 | return X.Iter == Y.Iter; |
| 2837 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2838 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2839 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 2840 | const TemplateArgumentLocInventIterator &Y) { |
| 2841 | return X.Iter != Y.Iter; |
| 2842 | } |
| 2843 | }; |
| 2844 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2845 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2846 | template<typename InputIterator> |
| 2847 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 2848 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2849 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2850 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2851 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2852 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2853 | |
| 2854 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 2855 | // Unpack argument packs, which we translate them into separate |
| 2856 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2857 | // FIXME: We could do much better if we could guarantee that the |
| 2858 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 2859 | // all of the template arguments in the argument pack. |
| 2860 | typedef TemplateArgumentLocInventIterator<Derived, |
| 2861 | TemplateArgument::pack_iterator> |
| 2862 | PackLocIterator; |
| 2863 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 2864 | In.getArgument().pack_begin()), |
| 2865 | PackLocIterator(*this, |
| 2866 | In.getArgument().pack_end()), |
| 2867 | Outputs)) |
| 2868 | return true; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2869 | |
| 2870 | continue; |
| 2871 | } |
| 2872 | |
| 2873 | if (In.getArgument().isPackExpansion()) { |
| 2874 | // We have a pack expansion, for which we will be substituting into |
| 2875 | // the pattern. |
| 2876 | SourceLocation Ellipsis; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2877 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2878 | TemplateArgumentLoc Pattern |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2879 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 2880 | getSema().Context); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2881 | |
| 2882 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2883 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2884 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2885 | |
| 2886 | // Determine whether the set of unexpanded parameter packs can and should |
| 2887 | // be expanded. |
| 2888 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2889 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2890 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2891 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 2892 | Pattern.getSourceRange(), |
| 2893 | Unexpanded.data(), |
| 2894 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2895 | Expand, |
| 2896 | RetainExpansion, |
| 2897 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2898 | return true; |
| 2899 | |
| 2900 | if (!Expand) { |
| 2901 | // The transform has determined that we should perform a simple |
| 2902 | // transformation on the pack expansion, producing another pack |
| 2903 | // expansion. |
| 2904 | TemplateArgumentLoc OutPattern; |
| 2905 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2906 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 2907 | return true; |
| 2908 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2909 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 2910 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2911 | if (Out.getArgument().isNull()) |
| 2912 | return true; |
| 2913 | |
| 2914 | Outputs.addArgument(Out); |
| 2915 | continue; |
| 2916 | } |
| 2917 | |
| 2918 | // The transform has determined that we should perform an elementwise |
| 2919 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2920 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2921 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2922 | |
| 2923 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 2924 | return true; |
| 2925 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2926 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2927 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 2928 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2929 | if (Out.getArgument().isNull()) |
| 2930 | return true; |
| 2931 | } |
| 2932 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2933 | Outputs.addArgument(Out); |
| 2934 | } |
| 2935 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 2936 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 2937 | // forgetting the partially-substituted parameter pack. |
| 2938 | if (RetainExpansion) { |
| 2939 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 2940 | |
| 2941 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 2942 | return true; |
| 2943 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2944 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 2945 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 2946 | if (Out.getArgument().isNull()) |
| 2947 | return true; |
| 2948 | |
| 2949 | Outputs.addArgument(Out); |
| 2950 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2951 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2952 | continue; |
| 2953 | } |
| 2954 | |
| 2955 | // The simple case: |
| 2956 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2957 | return true; |
| 2958 | |
| 2959 | Outputs.addArgument(Out); |
| 2960 | } |
| 2961 | |
| 2962 | return false; |
| 2963 | |
| 2964 | } |
| 2965 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2966 | //===----------------------------------------------------------------------===// |
| 2967 | // Type transformation |
| 2968 | //===----------------------------------------------------------------------===// |
| 2969 | |
| 2970 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2971 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2972 | if (getDerived().AlreadyTransformed(T)) |
| 2973 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2975 | // Temporary workaround. All of these transformations should |
| 2976 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 2977 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 2978 | getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2979 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2980 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2981 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2982 | if (!NewDI) |
| 2983 | return QualType(); |
| 2984 | |
| 2985 | return NewDI->getType(); |
| 2986 | } |
| 2987 | |
| 2988 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2989 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2990 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2991 | return DI; |
| 2992 | |
| 2993 | TypeLocBuilder TLB; |
| 2994 | |
| 2995 | TypeLoc TL = DI->getTypeLoc(); |
| 2996 | TLB.reserve(TL.getFullDataSize()); |
| 2997 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2998 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2999 | if (Result.isNull()) |
| 3000 | return 0; |
| 3001 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3002 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | template<typename Derived> |
| 3006 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3007 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3008 | switch (T.getTypeLocClass()) { |
| 3009 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3010 | #define TYPELOC(CLASS, PARENT) \ |
| 3011 | case TypeLoc::CLASS: \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3012 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3013 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3015 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3016 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3017 | return QualType(); |
| 3018 | } |
| 3019 | |
| 3020 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3021 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3022 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3023 | /// types). This is the right thing for template instantiation, but |
| 3024 | /// probably not for other clients. |
| 3025 | template<typename Derived> |
| 3026 | QualType |
| 3027 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3028 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3029 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3030 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3031 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3032 | if (Result.isNull()) |
| 3033 | return QualType(); |
| 3034 | |
| 3035 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3036 | // FIXME: this is the right thing for template instantiation, but |
| 3037 | // probably not for other clients. |
| 3038 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3039 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3040 | |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3041 | if (!Quals.empty()) { |
| 3042 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3043 | TLB.push<QualifiedTypeLoc>(Result); |
| 3044 | // No location information to preserve. |
| 3045 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3046 | |
| 3047 | return Result; |
| 3048 | } |
| 3049 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3050 | /// \brief Transforms a type that was written in a scope specifier, |
| 3051 | /// given an object type, the results of unqualified lookup, and |
| 3052 | /// an already-instantiated prefix. |
| 3053 | /// |
| 3054 | /// The object type is provided iff the scope specifier qualifies the |
| 3055 | /// member of a dependent member-access expression. The prefix is |
| 3056 | /// provided iff the the scope specifier in which this appears has a |
| 3057 | /// prefix. |
| 3058 | /// |
| 3059 | /// This is private to TreeTransform. |
| 3060 | template<typename Derived> |
| 3061 | QualType |
| 3062 | TreeTransform<Derived>::TransformTypeInObjectScope(QualType T, |
| 3063 | QualType ObjectType, |
| 3064 | NamedDecl *UnqualLookup, |
| 3065 | NestedNameSpecifier *Prefix) { |
| 3066 | if (getDerived().AlreadyTransformed(T)) |
| 3067 | return T; |
| 3068 | |
| 3069 | TypeSourceInfo *TSI = |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3070 | SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation()); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3071 | |
| 3072 | TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType, |
| 3073 | UnqualLookup, Prefix); |
| 3074 | if (!TSI) return QualType(); |
| 3075 | return TSI->getType(); |
| 3076 | } |
| 3077 | |
| 3078 | template<typename Derived> |
| 3079 | TypeSourceInfo * |
| 3080 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI, |
| 3081 | QualType ObjectType, |
| 3082 | NamedDecl *UnqualLookup, |
| 3083 | NestedNameSpecifier *Prefix) { |
| 3084 | // TODO: in some cases, we might be some verification to do here. |
| 3085 | if (ObjectType.isNull()) |
| 3086 | return getDerived().TransformType(TSI); |
| 3087 | |
| 3088 | QualType T = TSI->getType(); |
| 3089 | if (getDerived().AlreadyTransformed(T)) |
| 3090 | return TSI; |
| 3091 | |
| 3092 | TypeLocBuilder TLB; |
| 3093 | QualType Result; |
| 3094 | |
| 3095 | if (isa<TemplateSpecializationType>(T)) { |
| 3096 | TemplateSpecializationTypeLoc TL |
| 3097 | = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3098 | |
| 3099 | TemplateName Template = |
| 3100 | getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(), |
| 3101 | ObjectType, UnqualLookup); |
| 3102 | if (Template.isNull()) return 0; |
| 3103 | |
| 3104 | Result = getDerived() |
| 3105 | .TransformTemplateSpecializationType(TLB, TL, Template); |
| 3106 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3107 | DependentTemplateSpecializationTypeLoc TL |
| 3108 | = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3109 | |
| 3110 | Result = getDerived() |
| 3111 | .TransformDependentTemplateSpecializationType(TLB, TL, Prefix); |
| 3112 | } else { |
| 3113 | // Nothing special needs to be done for these. |
| 3114 | Result = getDerived().TransformType(TLB, TSI->getTypeLoc()); |
| 3115 | } |
| 3116 | |
| 3117 | if (Result.isNull()) return 0; |
| 3118 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3119 | } |
| 3120 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3121 | template <class TyLoc> static inline |
| 3122 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3123 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3124 | NewT.setNameLoc(T.getNameLoc()); |
| 3125 | return T.getType(); |
| 3126 | } |
| 3127 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3128 | template<typename Derived> |
| 3129 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3130 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3131 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3132 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3133 | if (T.needsExtraLocalData()) |
| 3134 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3135 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3138 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3139 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3140 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3141 | // FIXME: recurse? |
| 3142 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3143 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3144 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3145 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3146 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3147 | PointerTypeLoc TL) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3148 | QualType PointeeType |
| 3149 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3150 | if (PointeeType.isNull()) |
| 3151 | return QualType(); |
| 3152 | |
| 3153 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3154 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3155 | // A dependent pointer type 'T *' has is being transformed such |
| 3156 | // that an Objective-C class type is being replaced for 'T'. The |
| 3157 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3158 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3159 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3160 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3161 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3162 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3163 | return Result; |
| 3164 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3165 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3166 | if (getDerived().AlwaysRebuild() || |
| 3167 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3168 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3169 | if (Result.isNull()) |
| 3170 | return QualType(); |
| 3171 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3172 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3173 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3174 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3175 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3177 | |
| 3178 | template<typename Derived> |
| 3179 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3180 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3181 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3182 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3183 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3184 | if (PointeeType.isNull()) |
| 3185 | return QualType(); |
| 3186 | |
| 3187 | QualType Result = TL.getType(); |
| 3188 | if (getDerived().AlwaysRebuild() || |
| 3189 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3190 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3191 | TL.getSigilLoc()); |
| 3192 | if (Result.isNull()) |
| 3193 | return QualType(); |
| 3194 | } |
| 3195 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3196 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3197 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3198 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3201 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3202 | /// don't care whether the type itself is an l-value type or an r-value |
| 3203 | /// type; we only care if the type was *written* as an l-value type |
| 3204 | /// or an r-value type. |
| 3205 | template<typename Derived> |
| 3206 | QualType |
| 3207 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3208 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3209 | const ReferenceType *T = TL.getTypePtr(); |
| 3210 | |
| 3211 | // Note that this works with the pointee-as-written. |
| 3212 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3213 | if (PointeeType.isNull()) |
| 3214 | return QualType(); |
| 3215 | |
| 3216 | QualType Result = TL.getType(); |
| 3217 | if (getDerived().AlwaysRebuild() || |
| 3218 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3219 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3220 | T->isSpelledAsLValue(), |
| 3221 | TL.getSigilLoc()); |
| 3222 | if (Result.isNull()) |
| 3223 | return QualType(); |
| 3224 | } |
| 3225 | |
| 3226 | // r-value references can be rebuilt as l-value references. |
| 3227 | ReferenceTypeLoc NewTL; |
| 3228 | if (isa<LValueReferenceType>(Result)) |
| 3229 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3230 | else |
| 3231 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3232 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3233 | |
| 3234 | return Result; |
| 3235 | } |
| 3236 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3237 | template<typename Derived> |
| 3238 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3239 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3240 | LValueReferenceTypeLoc TL) { |
| 3241 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | template<typename Derived> |
| 3245 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3246 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3247 | RValueReferenceTypeLoc TL) { |
| 3248 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3249 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3251 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3253 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3254 | MemberPointerTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3255 | const MemberPointerType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3256 | |
| 3257 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3258 | if (PointeeType.isNull()) |
| 3259 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3260 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3261 | // TODO: preserve source information for this. |
| 3262 | QualType ClassType |
| 3263 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3264 | if (ClassType.isNull()) |
| 3265 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3266 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3267 | QualType Result = TL.getType(); |
| 3268 | if (getDerived().AlwaysRebuild() || |
| 3269 | PointeeType != T->getPointeeType() || |
| 3270 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3271 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 3272 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3273 | if (Result.isNull()) |
| 3274 | return QualType(); |
| 3275 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3276 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3277 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3278 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3279 | |
| 3280 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3283 | template<typename Derived> |
| 3284 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3285 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3286 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3287 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3288 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3289 | if (ElementType.isNull()) |
| 3290 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3292 | QualType Result = TL.getType(); |
| 3293 | if (getDerived().AlwaysRebuild() || |
| 3294 | ElementType != T->getElementType()) { |
| 3295 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3296 | T->getSizeModifier(), |
| 3297 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3298 | T->getIndexTypeCVRQualifiers(), |
| 3299 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3300 | if (Result.isNull()) |
| 3301 | return QualType(); |
| 3302 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3303 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3304 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3305 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3306 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3308 | Expr *Size = TL.getSizeExpr(); |
| 3309 | if (Size) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3310 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3311 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3312 | } |
| 3313 | NewTL.setSizeExpr(Size); |
| 3314 | |
| 3315 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3316 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3318 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3319 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3320 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3321 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3322 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3323 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3324 | if (ElementType.isNull()) |
| 3325 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3327 | QualType Result = TL.getType(); |
| 3328 | if (getDerived().AlwaysRebuild() || |
| 3329 | ElementType != T->getElementType()) { |
| 3330 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3331 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3332 | T->getIndexTypeCVRQualifiers(), |
| 3333 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3334 | if (Result.isNull()) |
| 3335 | return QualType(); |
| 3336 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3337 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3338 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3339 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3340 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3341 | NewTL.setSizeExpr(0); |
| 3342 | |
| 3343 | return Result; |
| 3344 | } |
| 3345 | |
| 3346 | template<typename Derived> |
| 3347 | QualType |
| 3348 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3349 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3350 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3351 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3352 | if (ElementType.isNull()) |
| 3353 | return QualType(); |
| 3354 | |
| 3355 | // Array bounds are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3356 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3357 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3358 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3359 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3360 | if (SizeResult.isInvalid()) |
| 3361 | return QualType(); |
| 3362 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3363 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3364 | |
| 3365 | QualType Result = TL.getType(); |
| 3366 | if (getDerived().AlwaysRebuild() || |
| 3367 | ElementType != T->getElementType() || |
| 3368 | Size != T->getSizeExpr()) { |
| 3369 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3370 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3371 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3372 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3373 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3374 | if (Result.isNull()) |
| 3375 | return QualType(); |
| 3376 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3377 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3378 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3379 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3380 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3381 | NewTL.setSizeExpr(Size); |
| 3382 | |
| 3383 | return Result; |
| 3384 | } |
| 3385 | |
| 3386 | template<typename Derived> |
| 3387 | QualType |
| 3388 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3389 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3390 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3391 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3392 | if (ElementType.isNull()) |
| 3393 | return QualType(); |
| 3394 | |
| 3395 | // Array bounds are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3396 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3397 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3398 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3399 | Expr *origSize = TL.getSizeExpr(); |
| 3400 | if (!origSize) origSize = T->getSizeExpr(); |
| 3401 | |
| 3402 | ExprResult sizeResult |
| 3403 | = getDerived().TransformExpr(origSize); |
| 3404 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3405 | return QualType(); |
| 3406 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3407 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3408 | |
| 3409 | QualType Result = TL.getType(); |
| 3410 | if (getDerived().AlwaysRebuild() || |
| 3411 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3412 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3413 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3414 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3415 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3416 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3417 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3418 | if (Result.isNull()) |
| 3419 | return QualType(); |
| 3420 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3421 | |
| 3422 | // We might have any sort of array type now, but fortunately they |
| 3423 | // all have the same location layout. |
| 3424 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3425 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3426 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3427 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3428 | |
| 3429 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3430 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3431 | |
| 3432 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3433 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3434 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3435 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3436 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3437 | |
| 3438 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3439 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3440 | if (ElementType.isNull()) |
| 3441 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3443 | // Vector sizes are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3444 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3445 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3446 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3447 | if (Size.isInvalid()) |
| 3448 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3450 | QualType Result = TL.getType(); |
| 3451 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3452 | ElementType != T->getElementType() || |
| 3453 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3454 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3455 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3456 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3457 | if (Result.isNull()) |
| 3458 | return QualType(); |
| 3459 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3460 | |
| 3461 | // Result might be dependent or not. |
| 3462 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3463 | DependentSizedExtVectorTypeLoc NewTL |
| 3464 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3465 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3466 | } else { |
| 3467 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3468 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3469 | } |
| 3470 | |
| 3471 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3472 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | |
| 3474 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3475 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3476 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3477 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3478 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3479 | if (ElementType.isNull()) |
| 3480 | return QualType(); |
| 3481 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3482 | QualType Result = TL.getType(); |
| 3483 | if (getDerived().AlwaysRebuild() || |
| 3484 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3485 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3486 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3487 | if (Result.isNull()) |
| 3488 | return QualType(); |
| 3489 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3490 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3491 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3492 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3493 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3494 | return Result; |
| 3495 | } |
| 3496 | |
| 3497 | template<typename Derived> |
| 3498 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3499 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3500 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3501 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3502 | if (ElementType.isNull()) |
| 3503 | return QualType(); |
| 3504 | |
| 3505 | QualType Result = TL.getType(); |
| 3506 | if (getDerived().AlwaysRebuild() || |
| 3507 | ElementType != T->getElementType()) { |
| 3508 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3509 | T->getNumElements(), |
| 3510 | /*FIXME*/ SourceLocation()); |
| 3511 | if (Result.isNull()) |
| 3512 | return QualType(); |
| 3513 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3514 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3515 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3516 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3517 | |
| 3518 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3519 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3520 | |
| 3521 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3522 | ParmVarDecl * |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3523 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 3524 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3525 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3526 | TypeSourceInfo *NewDI = 0; |
| 3527 | |
| 3528 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3529 | // If we're substituting into a pack expansion type and we know the |
| 3530 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3531 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3532 | |
| 3533 | TypeLocBuilder TLB; |
| 3534 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3535 | TLB.reserve(NewTL.getFullDataSize()); |
| 3536 | |
| 3537 | QualType Result = getDerived().TransformType(TLB, |
| 3538 | OldExpansionTL.getPatternLoc()); |
| 3539 | if (Result.isNull()) |
| 3540 | return 0; |
| 3541 | |
| 3542 | Result = RebuildPackExpansionType(Result, |
| 3543 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3544 | OldExpansionTL.getEllipsisLoc(), |
| 3545 | NumExpansions); |
| 3546 | if (Result.isNull()) |
| 3547 | return 0; |
| 3548 | |
| 3549 | PackExpansionTypeLoc NewExpansionTL |
| 3550 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3551 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3552 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3553 | } else |
| 3554 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3555 | if (!NewDI) |
| 3556 | return 0; |
| 3557 | |
| 3558 | if (NewDI == OldDI) |
| 3559 | return OldParm; |
| 3560 | else |
| 3561 | return ParmVarDecl::Create(SemaRef.Context, |
| 3562 | OldParm->getDeclContext(), |
| 3563 | OldParm->getLocation(), |
| 3564 | OldParm->getIdentifier(), |
| 3565 | NewDI->getType(), |
| 3566 | NewDI, |
| 3567 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 3568 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3569 | /* DefArg */ NULL); |
| 3570 | } |
| 3571 | |
| 3572 | template<typename Derived> |
| 3573 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3574 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3575 | ParmVarDecl **Params, unsigned NumParams, |
| 3576 | const QualType *ParamTypes, |
| 3577 | llvm::SmallVectorImpl<QualType> &OutParamTypes, |
| 3578 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { |
| 3579 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3580 | if (ParmVarDecl *OldParm = Params[i]) { |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3581 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3582 | if (OldParm->isParameterPack()) { |
| 3583 | // We have a function parameter pack that may need to be expanded. |
| 3584 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3585 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3586 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3587 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3588 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3589 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3590 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3591 | |
| 3592 | // Determine whether we should expand the parameter packs. |
| 3593 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3594 | bool RetainExpansion = false; |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3595 | llvm::Optional<unsigned> OrigNumExpansions |
| 3596 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3597 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3598 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3599 | Pattern.getSourceRange(), |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3600 | Unexpanded.data(), |
| 3601 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3602 | ShouldExpand, |
| 3603 | RetainExpansion, |
| 3604 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3605 | return true; |
| 3606 | } |
| 3607 | |
| 3608 | if (ShouldExpand) { |
| 3609 | // Expand the function parameter pack into multiple, separate |
| 3610 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3611 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3612 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3613 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3614 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3615 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3616 | OrigNumExpansions); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3617 | if (!NewParm) |
| 3618 | return true; |
| 3619 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3620 | OutParamTypes.push_back(NewParm->getType()); |
| 3621 | if (PVars) |
| 3622 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3623 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3624 | |
| 3625 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3626 | // forgetting the partially-substituted parameter pack. |
| 3627 | if (RetainExpansion) { |
| 3628 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3629 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3630 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3631 | OrigNumExpansions); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3632 | if (!NewParm) |
| 3633 | return true; |
| 3634 | |
| 3635 | OutParamTypes.push_back(NewParm->getType()); |
| 3636 | if (PVars) |
| 3637 | PVars->push_back(NewParm); |
| 3638 | } |
| 3639 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3640 | // We're done with the pack expansion. |
| 3641 | continue; |
| 3642 | } |
| 3643 | |
| 3644 | // We'll substitute the parameter now without expanding the pack |
| 3645 | // expansion. |
| 3646 | } |
| 3647 | |
| 3648 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3649 | ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3650 | NumExpansions); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3651 | if (!NewParm) |
| 3652 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3653 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3654 | OutParamTypes.push_back(NewParm->getType()); |
| 3655 | if (PVars) |
| 3656 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3657 | continue; |
| 3658 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3659 | |
| 3660 | // Deal with the possibility that we don't have a parameter |
| 3661 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3662 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3663 | bool IsPackExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3664 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3665 | if (const PackExpansionType *Expansion |
| 3666 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3667 | // We have a function parameter pack that may need to be expanded. |
| 3668 | QualType Pattern = Expansion->getPattern(); |
| 3669 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3670 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3671 | |
| 3672 | // Determine whether we should expand the parameter packs. |
| 3673 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3674 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3675 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3676 | Unexpanded.data(), |
| 3677 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3678 | ShouldExpand, |
| 3679 | RetainExpansion, |
| 3680 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3681 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | if (ShouldExpand) { |
| 3685 | // Expand the function parameter pack into multiple, separate |
| 3686 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3687 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3688 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3689 | QualType NewType = getDerived().TransformType(Pattern); |
| 3690 | if (NewType.isNull()) |
| 3691 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3693 | OutParamTypes.push_back(NewType); |
| 3694 | if (PVars) |
| 3695 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | // We're done with the pack expansion. |
| 3699 | continue; |
| 3700 | } |
| 3701 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3702 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3703 | // forgetting the partially-substituted parameter pack. |
| 3704 | if (RetainExpansion) { |
| 3705 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3706 | QualType NewType = getDerived().TransformType(Pattern); |
| 3707 | if (NewType.isNull()) |
| 3708 | return true; |
| 3709 | |
| 3710 | OutParamTypes.push_back(NewType); |
| 3711 | if (PVars) |
| 3712 | PVars->push_back(0); |
| 3713 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3714 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3715 | // We'll substitute the parameter now without expanding the pack |
| 3716 | // expansion. |
| 3717 | OldType = Expansion->getPattern(); |
| 3718 | IsPackExpansion = true; |
| 3719 | } |
| 3720 | |
| 3721 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3722 | QualType NewType = getDerived().TransformType(OldType); |
| 3723 | if (NewType.isNull()) |
| 3724 | return true; |
| 3725 | |
| 3726 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3727 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3728 | NumExpansions); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3729 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3730 | OutParamTypes.push_back(NewType); |
| 3731 | if (PVars) |
| 3732 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | return false; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3736 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3737 | |
| 3738 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3739 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3740 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3741 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3742 | // Transform the parameters and return type. |
| 3743 | // |
| 3744 | // We instantiate in source order, with the return type first followed by |
| 3745 | // the parameters, because users tend to expect this (even if they shouldn't |
| 3746 | // rely on it!). |
| 3747 | // |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3748 | // When the function has a trailing return type, we instantiate the |
| 3749 | // parameters before the return type, since the return type can then refer |
| 3750 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 3751 | // |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3752 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3753 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3754 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3755 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3756 | QualType ResultType; |
| 3757 | |
| 3758 | if (TL.getTrailingReturn()) { |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3759 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3760 | TL.getParmArray(), |
| 3761 | TL.getNumArgs(), |
| 3762 | TL.getTypePtr()->arg_type_begin(), |
| 3763 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3764 | return QualType(); |
| 3765 | |
| 3766 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3767 | if (ResultType.isNull()) |
| 3768 | return QualType(); |
| 3769 | } |
| 3770 | else { |
| 3771 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3772 | if (ResultType.isNull()) |
| 3773 | return QualType(); |
| 3774 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3775 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3776 | TL.getParmArray(), |
| 3777 | TL.getNumArgs(), |
| 3778 | TL.getTypePtr()->arg_type_begin(), |
| 3779 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3780 | return QualType(); |
| 3781 | } |
| 3782 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3783 | QualType Result = TL.getType(); |
| 3784 | if (getDerived().AlwaysRebuild() || |
| 3785 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 3786 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3787 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 3788 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 3789 | ParamTypes.data(), |
| 3790 | ParamTypes.size(), |
| 3791 | T->isVariadic(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3792 | T->getTypeQuals(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3793 | T->getRefQualifier(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3794 | T->getExtInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3795 | if (Result.isNull()) |
| 3796 | return QualType(); |
| 3797 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3799 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 3800 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3801 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3802 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3803 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 3804 | NewTL.setArg(i, ParamDecls[i]); |
| 3805 | |
| 3806 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3807 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3809 | template<typename Derived> |
| 3810 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3811 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3812 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3813 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3814 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3815 | if (ResultType.isNull()) |
| 3816 | return QualType(); |
| 3817 | |
| 3818 | QualType Result = TL.getType(); |
| 3819 | if (getDerived().AlwaysRebuild() || |
| 3820 | ResultType != T->getResultType()) |
| 3821 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 3822 | |
| 3823 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 3824 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3825 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3826 | NewTL.setTrailingReturn(false); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3827 | |
| 3828 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3830 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3831 | template<typename Derived> QualType |
| 3832 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3833 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3834 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3835 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3836 | if (!D) |
| 3837 | return QualType(); |
| 3838 | |
| 3839 | QualType Result = TL.getType(); |
| 3840 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 3841 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 3842 | if (Result.isNull()) |
| 3843 | return QualType(); |
| 3844 | } |
| 3845 | |
| 3846 | // We might get an arbitrary type spec type back. We should at |
| 3847 | // least always get a type spec type, though. |
| 3848 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 3849 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3850 | |
| 3851 | return Result; |
| 3852 | } |
| 3853 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3854 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3855 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3856 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3857 | const TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3858 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3859 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3860 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3861 | if (!Typedef) |
| 3862 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3864 | QualType Result = TL.getType(); |
| 3865 | if (getDerived().AlwaysRebuild() || |
| 3866 | Typedef != T->getDecl()) { |
| 3867 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3868 | if (Result.isNull()) |
| 3869 | return QualType(); |
| 3870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3872 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3873 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3874 | |
| 3875 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3876 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3878 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3879 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3880 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3881 | // typeof expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3882 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3884 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3885 | if (E.isInvalid()) |
| 3886 | return QualType(); |
| 3887 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3888 | QualType Result = TL.getType(); |
| 3889 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3890 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 3891 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3892 | if (Result.isNull()) |
| 3893 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3894 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3895 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3897 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3898 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3899 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3900 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3901 | |
| 3902 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3903 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3904 | |
| 3905 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3906 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3907 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3908 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3909 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3910 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3911 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3912 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3913 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3914 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3915 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3916 | if (Result.isNull()) |
| 3917 | return QualType(); |
| 3918 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3920 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3921 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3922 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3923 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3924 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3925 | |
| 3926 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3927 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | |
| 3929 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3930 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3931 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3932 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3934 | // decltype expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3935 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3936 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3937 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3938 | if (E.isInvalid()) |
| 3939 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3940 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3941 | QualType Result = TL.getType(); |
| 3942 | if (getDerived().AlwaysRebuild() || |
| 3943 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 3944 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3945 | if (Result.isNull()) |
| 3946 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3947 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3948 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3950 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3951 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3952 | |
| 3953 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3957 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3958 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3959 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3960 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3961 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3962 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3963 | if (!Record) |
| 3964 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3966 | QualType Result = TL.getType(); |
| 3967 | if (getDerived().AlwaysRebuild() || |
| 3968 | Record != T->getDecl()) { |
| 3969 | Result = getDerived().RebuildRecordType(Record); |
| 3970 | if (Result.isNull()) |
| 3971 | return QualType(); |
| 3972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3973 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3974 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3975 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3976 | |
| 3977 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3978 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
| 3980 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3981 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3982 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3983 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3984 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3985 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3986 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3987 | if (!Enum) |
| 3988 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3989 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3990 | QualType Result = TL.getType(); |
| 3991 | if (getDerived().AlwaysRebuild() || |
| 3992 | Enum != T->getDecl()) { |
| 3993 | Result = getDerived().RebuildEnumType(Enum); |
| 3994 | if (Result.isNull()) |
| 3995 | return QualType(); |
| 3996 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3998 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3999 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4000 | |
| 4001 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4002 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4003 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4004 | template<typename Derived> |
| 4005 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4006 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4007 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4008 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4009 | TL.getTypePtr()->getDecl()); |
| 4010 | if (!D) return QualType(); |
| 4011 | |
| 4012 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4013 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4014 | return T; |
| 4015 | } |
| 4016 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4017 | template<typename Derived> |
| 4018 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4019 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4020 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4021 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4022 | } |
| 4023 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4024 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4025 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4026 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4027 | SubstTemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4028 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4032 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4033 | TypeLocBuilder &TLB, |
| 4034 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4035 | return TransformTypeSpecType(TLB, TL); |
| 4036 | } |
| 4037 | |
| 4038 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4039 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4040 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4041 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4042 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4043 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | TemplateName Template |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4045 | = getDerived().TransformTemplateName(T->getTemplateName()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4046 | if (Template.isNull()) |
| 4047 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4048 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4049 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4050 | } |
| 4051 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4052 | namespace { |
| 4053 | /// \brief Simple iterator that traverses the template arguments in a |
| 4054 | /// container that provides a \c getArgLoc() member function. |
| 4055 | /// |
| 4056 | /// This iterator is intended to be used with the iterator form of |
| 4057 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4058 | template<typename ArgLocContainer> |
| 4059 | class TemplateArgumentLocContainerIterator { |
| 4060 | ArgLocContainer *Container; |
| 4061 | unsigned Index; |
| 4062 | |
| 4063 | public: |
| 4064 | typedef TemplateArgumentLoc value_type; |
| 4065 | typedef TemplateArgumentLoc reference; |
| 4066 | typedef int difference_type; |
| 4067 | typedef std::input_iterator_tag iterator_category; |
| 4068 | |
| 4069 | class pointer { |
| 4070 | TemplateArgumentLoc Arg; |
| 4071 | |
| 4072 | public: |
| 4073 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4074 | |
| 4075 | const TemplateArgumentLoc *operator->() const { |
| 4076 | return &Arg; |
| 4077 | } |
| 4078 | }; |
| 4079 | |
| 4080 | |
| 4081 | TemplateArgumentLocContainerIterator() {} |
| 4082 | |
| 4083 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4084 | unsigned Index) |
| 4085 | : Container(&Container), Index(Index) { } |
| 4086 | |
| 4087 | TemplateArgumentLocContainerIterator &operator++() { |
| 4088 | ++Index; |
| 4089 | return *this; |
| 4090 | } |
| 4091 | |
| 4092 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4093 | TemplateArgumentLocContainerIterator Old(*this); |
| 4094 | ++(*this); |
| 4095 | return Old; |
| 4096 | } |
| 4097 | |
| 4098 | TemplateArgumentLoc operator*() const { |
| 4099 | return Container->getArgLoc(Index); |
| 4100 | } |
| 4101 | |
| 4102 | pointer operator->() const { |
| 4103 | return pointer(Container->getArgLoc(Index)); |
| 4104 | } |
| 4105 | |
| 4106 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4107 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4108 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4109 | } |
| 4110 | |
| 4111 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4112 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4113 | return !(X == Y); |
| 4114 | } |
| 4115 | }; |
| 4116 | } |
| 4117 | |
| 4118 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4119 | template <typename Derived> |
| 4120 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4121 | TypeLocBuilder &TLB, |
| 4122 | TemplateSpecializationTypeLoc TL, |
| 4123 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4124 | TemplateArgumentListInfo NewTemplateArgs; |
| 4125 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4126 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4127 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4128 | ArgIterator; |
| 4129 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4130 | ArgIterator(TL, TL.getNumArgs()), |
| 4131 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4132 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4134 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4135 | |
| 4136 | QualType Result = |
| 4137 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4138 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4139 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4140 | |
| 4141 | if (!Result.isNull()) { |
| 4142 | TemplateSpecializationTypeLoc NewTL |
| 4143 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4144 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4145 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4146 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4147 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4148 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4151 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
| 4154 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4155 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4156 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4157 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4158 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4159 | |
| 4160 | NestedNameSpecifier *NNS = 0; |
| 4161 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 4162 | if (T->getQualifier() != 0) { |
| 4163 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4164 | TL.getQualifierRange()); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4165 | if (!NNS) |
| 4166 | return QualType(); |
| 4167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4169 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4170 | if (NamedT.isNull()) |
| 4171 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4172 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4173 | QualType Result = TL.getType(); |
| 4174 | if (getDerived().AlwaysRebuild() || |
| 4175 | NNS != T->getQualifier() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4176 | NamedT != T->getNamedType()) { |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4177 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
| 4178 | T->getKeyword(), NNS, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4179 | if (Result.isNull()) |
| 4180 | return QualType(); |
| 4181 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4182 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4183 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4184 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4185 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4186 | |
| 4187 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | |
| 4190 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4191 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4192 | TypeLocBuilder &TLB, |
| 4193 | AttributedTypeLoc TL) { |
| 4194 | const AttributedType *oldType = TL.getTypePtr(); |
| 4195 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4196 | if (modifiedType.isNull()) |
| 4197 | return QualType(); |
| 4198 | |
| 4199 | QualType result = TL.getType(); |
| 4200 | |
| 4201 | // FIXME: dependent operand expressions? |
| 4202 | if (getDerived().AlwaysRebuild() || |
| 4203 | modifiedType != oldType->getModifiedType()) { |
| 4204 | // TODO: this is really lame; we should really be rebuilding the |
| 4205 | // equivalent type from first principles. |
| 4206 | QualType equivalentType |
| 4207 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4208 | if (equivalentType.isNull()) |
| 4209 | return QualType(); |
| 4210 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4211 | modifiedType, |
| 4212 | equivalentType); |
| 4213 | } |
| 4214 | |
| 4215 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4216 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4217 | if (TL.hasAttrOperand()) |
| 4218 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4219 | if (TL.hasAttrExprOperand()) |
| 4220 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4221 | else if (TL.hasAttrEnumOperand()) |
| 4222 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4223 | |
| 4224 | return result; |
| 4225 | } |
| 4226 | |
| 4227 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4228 | QualType |
| 4229 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4230 | ParenTypeLoc TL) { |
| 4231 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4232 | if (Inner.isNull()) |
| 4233 | return QualType(); |
| 4234 | |
| 4235 | QualType Result = TL.getType(); |
| 4236 | if (getDerived().AlwaysRebuild() || |
| 4237 | Inner != TL.getInnerLoc().getType()) { |
| 4238 | Result = getDerived().RebuildParenType(Inner); |
| 4239 | if (Result.isNull()) |
| 4240 | return QualType(); |
| 4241 | } |
| 4242 | |
| 4243 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4244 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4245 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4246 | return Result; |
| 4247 | } |
| 4248 | |
| 4249 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4250 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4251 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4252 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4253 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4254 | NestedNameSpecifier *NNS |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4255 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4256 | TL.getQualifierRange()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4257 | if (!NNS) |
| 4258 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4260 | QualType Result |
| 4261 | = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 4262 | T->getIdentifier(), |
| 4263 | TL.getKeywordLoc(), |
| 4264 | TL.getQualifierRange(), |
| 4265 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4266 | if (Result.isNull()) |
| 4267 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4268 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4269 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4270 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4271 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4272 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4273 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4274 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4275 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4276 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4277 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4278 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4279 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 4280 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4281 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4282 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4285 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4286 | QualType TreeTransform<Derived>:: |
| 4287 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4288 | DependentTemplateSpecializationTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4289 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4290 | |
| 4291 | NestedNameSpecifier *NNS |
| 4292 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4293 | TL.getQualifierRange()); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4294 | if (!NNS) |
| 4295 | return QualType(); |
| 4296 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4297 | return getDerived() |
| 4298 | .TransformDependentTemplateSpecializationType(TLB, TL, NNS); |
| 4299 | } |
| 4300 | |
| 4301 | template<typename Derived> |
| 4302 | QualType TreeTransform<Derived>:: |
| 4303 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4304 | DependentTemplateSpecializationTypeLoc TL, |
| 4305 | NestedNameSpecifier *NNS) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4306 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4307 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4308 | TemplateArgumentListInfo NewTemplateArgs; |
| 4309 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4310 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4311 | |
| 4312 | typedef TemplateArgumentLocContainerIterator< |
| 4313 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4314 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4315 | ArgIterator(TL, TL.getNumArgs()), |
| 4316 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4317 | return QualType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4319 | QualType Result |
| 4320 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4321 | NNS, |
| 4322 | TL.getQualifierRange(), |
| 4323 | T->getIdentifier(), |
| 4324 | TL.getNameLoc(), |
| 4325 | NewTemplateArgs); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4326 | if (Result.isNull()) |
| 4327 | return QualType(); |
| 4328 | |
| 4329 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4330 | QualType NamedT = ElabT->getNamedType(); |
| 4331 | |
| 4332 | // Copy information relevant to the template specialization. |
| 4333 | TemplateSpecializationTypeLoc NamedTL |
| 4334 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4335 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4336 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4337 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4338 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4339 | |
| 4340 | // Copy information relevant to the elaborated type. |
| 4341 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4342 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4343 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 4344 | } else { |
Douglas Gregor | e2872d0 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 4345 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4346 | TLB.pushFullCopy(NewTL); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4347 | } |
| 4348 | return Result; |
| 4349 | } |
| 4350 | |
| 4351 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4352 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4353 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4354 | QualType Pattern |
| 4355 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4356 | if (Pattern.isNull()) |
| 4357 | return QualType(); |
| 4358 | |
| 4359 | QualType Result = TL.getType(); |
| 4360 | if (getDerived().AlwaysRebuild() || |
| 4361 | Pattern != TL.getPatternLoc().getType()) { |
| 4362 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4363 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4364 | TL.getEllipsisLoc(), |
| 4365 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4366 | if (Result.isNull()) |
| 4367 | return QualType(); |
| 4368 | } |
| 4369 | |
| 4370 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4371 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4372 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4376 | QualType |
| 4377 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4378 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4379 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4380 | TLB.pushFullCopy(TL); |
| 4381 | return TL.getType(); |
| 4382 | } |
| 4383 | |
| 4384 | template<typename Derived> |
| 4385 | QualType |
| 4386 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4387 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4388 | // ObjCObjectType is never dependent. |
| 4389 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4390 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | |
| 4393 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4394 | QualType |
| 4395 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4396 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4397 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4398 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4399 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4400 | } |
| 4401 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4402 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4403 | // Statement transformation |
| 4404 | //===----------------------------------------------------------------------===// |
| 4405 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4406 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4408 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4412 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4413 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4414 | return getDerived().TransformCompoundStmt(S, false); |
| 4415 | } |
| 4416 | |
| 4417 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4418 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4419 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4420 | bool IsStmtExpr) { |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4421 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4422 | bool SubStmtChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4423 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4424 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4425 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4426 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4427 | if (Result.isInvalid()) { |
| 4428 | // Immediately fail if this was a DeclStmt, since it's very |
| 4429 | // likely that this will cause problems for future statements. |
| 4430 | if (isa<DeclStmt>(*B)) |
| 4431 | return StmtError(); |
| 4432 | |
| 4433 | // Otherwise, just keep processing substatements and fail later. |
| 4434 | SubStmtInvalid = true; |
| 4435 | continue; |
| 4436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4438 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4439 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4442 | if (SubStmtInvalid) |
| 4443 | return StmtError(); |
| 4444 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4445 | if (!getDerived().AlwaysRebuild() && |
| 4446 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4447 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4448 | |
| 4449 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4450 | move_arg(Statements), |
| 4451 | S->getRBracLoc(), |
| 4452 | IsStmtExpr); |
| 4453 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4454 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4455 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4456 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4457 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4458 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4459 | { |
| 4460 | // The case value expressions are not potentially evaluated. |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4461 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4462 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4463 | // Transform the left-hand case value. |
| 4464 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4465 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4466 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4468 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4469 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4470 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4471 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4472 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4474 | // Build the case statement. |
| 4475 | // Case statements are always rebuilt so that they will attached to their |
| 4476 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4477 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4478 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4479 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4480 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4481 | S->getColonLoc()); |
| 4482 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4483 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4485 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4486 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4487 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4488 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4489 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4490 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4491 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4495 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4497 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4498 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4499 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4500 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4502 | // Default statements are always rebuilt |
| 4503 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4504 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4505 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4507 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4508 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4509 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4510 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4511 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4512 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4514 | // FIXME: Pass the real colon location in. |
| 4515 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame^] | 4516 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
| 4517 | S->getDecl()->getIdentifier(), ColonLoc, |
| 4518 | SubStmt.get(), |
| 4519 | S->getDecl()->hasUnusedAttribute()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4521 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4522 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4523 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4524 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4525 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4526 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4527 | VarDecl *ConditionVar = 0; |
| 4528 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4529 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4530 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4531 | getDerived().TransformDefinition( |
| 4532 | S->getConditionVariable()->getLocation(), |
| 4533 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4534 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4535 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4536 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4537 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4538 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4539 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4540 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4541 | |
| 4542 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4543 | if (S->getCond()) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4544 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 4545 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4546 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4547 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4548 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4549 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4550 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4551 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4552 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4553 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4554 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4555 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4557 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4558 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4559 | if (Then.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4560 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4562 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4563 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4564 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4565 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4567 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4568 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4569 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4570 | Then.get() == S->getThen() && |
| 4571 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4572 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4574 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 4575 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4576 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4580 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4582 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4583 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4584 | VarDecl *ConditionVar = 0; |
| 4585 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4586 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4587 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4588 | getDerived().TransformDefinition( |
| 4589 | S->getConditionVariable()->getLocation(), |
| 4590 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4591 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4592 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4593 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4594 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4596 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4597 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4599 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4600 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4601 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4602 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 4603 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4604 | if (Switch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4605 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4607 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4608 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4609 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4610 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4611 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4612 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4613 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 4614 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4615 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4617 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4618 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4619 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4620 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4621 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4622 | VarDecl *ConditionVar = 0; |
| 4623 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4624 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4625 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4626 | getDerived().TransformDefinition( |
| 4627 | S->getConditionVariable()->getLocation(), |
| 4628 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4629 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4630 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4631 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4632 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4633 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4634 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4635 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4636 | |
| 4637 | if (S->getCond()) { |
| 4638 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4639 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 4640 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4641 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4642 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4643 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4644 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4646 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4647 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4648 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4649 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4650 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4651 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4652 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4653 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4654 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4655 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4656 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4657 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4658 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4659 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4660 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4661 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4662 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4663 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4664 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4666 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4667 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4668 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4669 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4670 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4671 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4672 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4674 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4675 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4676 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4677 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4678 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4679 | if (!getDerived().AlwaysRebuild() && |
| 4680 | Cond.get() == S->getCond() && |
| 4681 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4682 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4684 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 4685 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4686 | S->getRParenLoc()); |
| 4687 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4689 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4690 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4692 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4693 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4694 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4695 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4697 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4698 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4699 | VarDecl *ConditionVar = 0; |
| 4700 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4701 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4702 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4703 | getDerived().TransformDefinition( |
| 4704 | S->getConditionVariable()->getLocation(), |
| 4705 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4706 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4707 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4708 | } else { |
| 4709 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4711 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4712 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4713 | |
| 4714 | if (S->getCond()) { |
| 4715 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4716 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 4717 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4718 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4719 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4720 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4721 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4722 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4724 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4725 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4726 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4727 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4728 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4729 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4730 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4731 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4732 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4733 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4734 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 4735 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4736 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4737 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4738 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4739 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4740 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4741 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4742 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4743 | if (!getDerived().AlwaysRebuild() && |
| 4744 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4745 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4746 | Inc.get() == S->getInc() && |
| 4747 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4748 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4750 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4751 | Init.get(), FullCond, ConditionVar, |
| 4752 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4756 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4757 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4758 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4759 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4760 | S->getLabel()); |
| 4761 | } |
| 4762 | |
| 4763 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4764 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4766 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4767 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4768 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4769 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4770 | if (!getDerived().AlwaysRebuild() && |
| 4771 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4772 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4773 | |
| 4774 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4775 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4779 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4780 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4781 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4783 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4784 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4785 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4786 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4787 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4788 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4790 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4791 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4792 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4793 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4794 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4795 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4796 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4798 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4799 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4800 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4802 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4803 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4805 | bool DeclChanged = false; |
| 4806 | llvm::SmallVector<Decl *, 4> Decls; |
| 4807 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 4808 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4809 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 4810 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4811 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4812 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4814 | if (Transformed != *D) |
| 4815 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4817 | Decls.push_back(Transformed); |
| 4818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4819 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4820 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4821 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | |
| 4823 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4824 | S->getStartLoc(), S->getEndLoc()); |
| 4825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4826 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4827 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4828 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4829 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4830 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4831 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 4832 | ASTOwningVector<Expr*> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 4833 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 4834 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4835 | ExprResult AsmString; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4836 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4837 | |
| 4838 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4839 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4840 | // Go through the outputs. |
| 4841 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 4842 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4843 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4844 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4845 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4846 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4847 | // Transform the output expr. |
| 4848 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4849 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4850 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4851 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4852 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4853 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4854 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4855 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4856 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4857 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4858 | // Go through the inputs. |
| 4859 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 4860 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4861 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4862 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4863 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4864 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4865 | // Transform the input expr. |
| 4866 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4867 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4868 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4869 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4870 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4871 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4872 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4873 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4874 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4875 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4876 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4877 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4878 | |
| 4879 | // Go through the clobbers. |
| 4880 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4881 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4882 | |
| 4883 | // No need to transform the asm string literal. |
| 4884 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 4885 | |
| 4886 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 4887 | S->isSimple(), |
| 4888 | S->isVolatile(), |
| 4889 | S->getNumOutputs(), |
| 4890 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 4891 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4892 | move_arg(Constraints), |
| 4893 | move_arg(Exprs), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4894 | AsmString.get(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4895 | move_arg(Clobbers), |
| 4896 | S->getRParenLoc(), |
| 4897 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | |
| 4901 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4902 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4903 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4904 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4905 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4906 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4907 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4908 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4909 | // Transform the @catch statements (if present). |
| 4910 | bool AnyCatchChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4911 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4912 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4913 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4914 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4915 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4916 | if (Catch.get() != S->getCatchStmt(I)) |
| 4917 | AnyCatchChanged = true; |
| 4918 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4919 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4921 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4922 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4923 | if (S->getFinallyStmt()) { |
| 4924 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 4925 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4926 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | // If nothing changed, just retain this statement. |
| 4930 | if (!getDerived().AlwaysRebuild() && |
| 4931 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4932 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4933 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4934 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4935 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4936 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4937 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 4938 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4939 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4941 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4942 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4943 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4944 | // Transform the @catch parameter, if there is one. |
| 4945 | VarDecl *Var = 0; |
| 4946 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 4947 | TypeSourceInfo *TSInfo = 0; |
| 4948 | if (FromVar->getTypeSourceInfo()) { |
| 4949 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 4950 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4951 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4952 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4953 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4954 | QualType T; |
| 4955 | if (TSInfo) |
| 4956 | T = TSInfo->getType(); |
| 4957 | else { |
| 4958 | T = getDerived().TransformType(FromVar->getType()); |
| 4959 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4960 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4961 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4963 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 4964 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4965 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4966 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4967 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4968 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4969 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4970 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4971 | |
| 4972 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4973 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4974 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4976 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4977 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4978 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4980 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4981 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4982 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4983 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4984 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4985 | // If nothing changed, just retain this statement. |
| 4986 | if (!getDerived().AlwaysRebuild() && |
| 4987 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4988 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4989 | |
| 4990 | // Build a new statement. |
| 4991 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4992 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4994 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4995 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4996 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4997 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4998 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4999 | if (S->getThrowExpr()) { |
| 5000 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5001 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5002 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5003 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5004 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5005 | if (!getDerived().AlwaysRebuild() && |
| 5006 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5007 | return getSema().Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5008 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5009 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5011 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5012 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5013 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5014 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5015 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5016 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5017 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5018 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5019 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5020 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5021 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5022 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5023 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5024 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5025 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5026 | // If nothing change, just retain the current statement. |
| 5027 | if (!getDerived().AlwaysRebuild() && |
| 5028 | Object.get() == S->getSynchExpr() && |
| 5029 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5030 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5031 | |
| 5032 | // Build a new statement. |
| 5033 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5034 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5038 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5039 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5040 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5041 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5042 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5043 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5044 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5045 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5046 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5047 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5048 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5049 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5050 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5051 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5052 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5053 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5054 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5055 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5056 | // If nothing changed, just retain this statement. |
| 5057 | if (!getDerived().AlwaysRebuild() && |
| 5058 | Element.get() == S->getElement() && |
| 5059 | Collection.get() == S->getCollection() && |
| 5060 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5061 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5062 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5063 | // Build a new statement. |
| 5064 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5065 | /*FIXME:*/S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5066 | Element.get(), |
| 5067 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5068 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5069 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | |
| 5073 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5074 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5075 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5076 | // Transform the exception declaration, if any. |
| 5077 | VarDecl *Var = 0; |
| 5078 | if (S->getExceptionDecl()) { |
| 5079 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5080 | TypeSourceInfo *T = getDerived().TransformType( |
| 5081 | ExceptionDecl->getTypeSourceInfo()); |
| 5082 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5083 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5085 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5086 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5087 | ExceptionDecl->getLocation()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5088 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5089 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5092 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5093 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5094 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5095 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5096 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5097 | if (!getDerived().AlwaysRebuild() && |
| 5098 | !Var && |
| 5099 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5100 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5101 | |
| 5102 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5103 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5104 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5106 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5107 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5108 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5109 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5110 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5111 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5112 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5113 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5114 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5115 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5116 | // Transform the handlers. |
| 5117 | bool HandlerChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5118 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5119 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5120 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5121 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5122 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5123 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5125 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5126 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5128 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5129 | if (!getDerived().AlwaysRebuild() && |
| 5130 | TryBlock.get() == S->getTryBlock() && |
| 5131 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5132 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5133 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5134 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5135 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5138 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5139 | // Expression transformation |
| 5140 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5142 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5143 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5144 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5146 | |
| 5147 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5148 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5149 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5150 | NestedNameSpecifier *Qualifier = 0; |
| 5151 | if (E->getQualifier()) { |
| 5152 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5153 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5154 | if (!Qualifier) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5155 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5156 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5157 | |
| 5158 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5159 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5160 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5162 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5164 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5165 | if (NameInfo.getName()) { |
| 5166 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5167 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5168 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5169 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5170 | |
| 5171 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5172 | Qualifier == E->getQualifier() && |
| 5173 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5174 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5175 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5176 | |
| 5177 | // Mark it referenced in the new context regardless. |
| 5178 | // FIXME: this is a bit instantiation-specific. |
| 5179 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5180 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5181 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5182 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5183 | |
| 5184 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5185 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5186 | TemplateArgs = &TransArgs; |
| 5187 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5188 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5189 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5190 | E->getNumTemplateArgs(), |
| 5191 | TransArgs)) |
| 5192 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5195 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5196 | ND, NameInfo, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5197 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5200 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5201 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5202 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5204 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5205 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5206 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5207 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5208 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5209 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5211 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5212 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5213 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5214 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5215 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5216 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5217 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5218 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5219 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5220 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5221 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5222 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5224 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5225 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5226 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5230 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5231 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5232 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5234 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5235 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5236 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5237 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5239 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5240 | E->getRParen()); |
| 5241 | } |
| 5242 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5244 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5245 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5246 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5247 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5248 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5251 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5253 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5254 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5255 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5259 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5260 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5261 | // Transform the type. |
| 5262 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5263 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5264 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5265 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5266 | // Transform all of the components into components similar to what the |
| 5267 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5268 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5269 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5270 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5271 | // template code that we don't care. |
| 5272 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5273 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5274 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 5275 | llvm::SmallVector<Component, 4> Components; |
| 5276 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5277 | const Node &ON = E->getComponent(I); |
| 5278 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5279 | Comp.isBrackets = true; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5280 | Comp.LocStart = ON.getRange().getBegin(); |
| 5281 | Comp.LocEnd = ON.getRange().getEnd(); |
| 5282 | switch (ON.getKind()) { |
| 5283 | case Node::Array: { |
| 5284 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5285 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5286 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5287 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5288 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5289 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5290 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5291 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5292 | break; |
| 5293 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5294 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5295 | case Node::Field: |
| 5296 | case Node::Identifier: |
| 5297 | Comp.isBrackets = false; |
| 5298 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5299 | if (!Comp.U.IdentInfo) |
| 5300 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5301 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5302 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5303 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5304 | case Node::Base: |
| 5305 | // Will be recomputed during the rebuild. |
| 5306 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5307 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5308 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5309 | Components.push_back(Comp); |
| 5310 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5311 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5312 | // If nothing changed, retain the existing expression. |
| 5313 | if (!getDerived().AlwaysRebuild() && |
| 5314 | Type == E->getTypeSourceInfo() && |
| 5315 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5316 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5317 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5318 | // Build a new offsetof expression. |
| 5319 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5320 | Components.data(), Components.size(), |
| 5321 | E->getRParenLoc()); |
| 5322 | } |
| 5323 | |
| 5324 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5325 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5326 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5327 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5328 | "opaque value expression requires transformation"); |
| 5329 | return SemaRef.Owned(E); |
| 5330 | } |
| 5331 | |
| 5332 | template<typename Derived> |
| 5333 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5334 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5335 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5336 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5337 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5338 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5339 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5340 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5342 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5343 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5345 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5346 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5347 | E->getSourceRange()); |
| 5348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5349 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5350 | ExprResult SubExpr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5351 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5352 | // C++0x [expr.sizeof]p1: |
| 5353 | // The operand is either an expression, which is an unevaluated operand |
| 5354 | // [...] |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5355 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5356 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5357 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5358 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5359 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5361 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5362 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5363 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5365 | return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5366 | E->isSizeOf(), |
| 5367 | E->getSourceRange()); |
| 5368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5370 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5371 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5372 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5373 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5374 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5375 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5377 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5378 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5379 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5380 | |
| 5381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5382 | if (!getDerived().AlwaysRebuild() && |
| 5383 | LHS.get() == E->getLHS() && |
| 5384 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5385 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5386 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5387 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5388 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5389 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5390 | E->getRBracketLoc()); |
| 5391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5392 | |
| 5393 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5394 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5395 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5396 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5397 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5398 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5399 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | |
| 5401 | // Transform arguments. |
| 5402 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5403 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5404 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5405 | &ArgChanged)) |
| 5406 | return ExprError(); |
| 5407 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5408 | if (!getDerived().AlwaysRebuild() && |
| 5409 | Callee.get() == E->getCallee() && |
| 5410 | !ArgChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5411 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5413 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5415 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5416 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5417 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5418 | E->getRParenLoc()); |
| 5419 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5420 | |
| 5421 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5422 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5423 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5424 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5425 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5426 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5427 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5428 | NestedNameSpecifier *Qualifier = 0; |
| 5429 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5431 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5432 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 5433 | if (Qualifier == 0) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5434 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 5437 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5438 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 5439 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5440 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5441 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5442 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5443 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 5444 | if (FoundDecl == E->getMemberDecl()) { |
| 5445 | FoundDecl = Member; |
| 5446 | } else { |
| 5447 | FoundDecl = cast_or_null<NamedDecl>( |
| 5448 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 5449 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5450 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5453 | if (!getDerived().AlwaysRebuild() && |
| 5454 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5455 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5456 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5457 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5458 | !E->hasExplicitTemplateArgs()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5459 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5460 | // Mark it referenced in the new context regardless. |
| 5461 | // FIXME: this is a bit instantiation-specific. |
| 5462 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5463 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5464 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5465 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5466 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5467 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5468 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5469 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5470 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5471 | E->getNumTemplateArgs(), |
| 5472 | TransArgs)) |
| 5473 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5474 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5475 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5476 | // FIXME: Bogus source location for the operator |
| 5477 | SourceLocation FakeOperatorLoc |
| 5478 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 5479 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5480 | // FIXME: to do this check properly, we will need to preserve the |
| 5481 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5482 | // base (and therefore couldn't do the check) and a |
| 5483 | // nested-name-qualifier (and therefore could do the lookup). |
| 5484 | NamedDecl *FirstQualifierInScope = 0; |
| 5485 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5486 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5487 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5488 | Qualifier, |
| 5489 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5490 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5491 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5492 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5493 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5494 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5495 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5496 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5497 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5498 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5499 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5500 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5501 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5503 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5505 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5506 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5507 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5509 | if (!getDerived().AlwaysRebuild() && |
| 5510 | LHS.get() == E->getLHS() && |
| 5511 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5512 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5514 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5515 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5519 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5520 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5521 | CompoundAssignOperator *E) { |
| 5522 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5524 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5525 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5526 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5527 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5528 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5529 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5530 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5531 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5532 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5533 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5534 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5535 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5536 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5537 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5538 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5539 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5540 | if (!getDerived().AlwaysRebuild() && |
| 5541 | Cond.get() == E->getCond() && |
| 5542 | LHS.get() == E->getLHS() && |
| 5543 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5544 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5546 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5547 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5548 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5549 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5550 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5551 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5552 | |
| 5553 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5554 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5555 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5556 | // Implicit casts are eliminated during transformation, since they |
| 5557 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5558 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5561 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5562 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5563 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5564 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5565 | if (!Type) |
| 5566 | return ExprError(); |
| 5567 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5568 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5569 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5570 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5571 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5572 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5573 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5574 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5575 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5576 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5577 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5578 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5579 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5580 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5581 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5582 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5584 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5585 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5586 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5587 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 5588 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 5589 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5590 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5591 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5592 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5593 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5594 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5596 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5597 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5598 | Init.get() == E->getInitializer()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5599 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5600 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 5601 | // Note: the expression type doesn't necessarily match the |
| 5602 | // type-as-written, but that's okay, because it should always be |
| 5603 | // derivable from the initializer. |
| 5604 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5605 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5607 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5608 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5610 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5611 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5612 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5613 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5614 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5615 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5617 | if (!getDerived().AlwaysRebuild() && |
| 5618 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5619 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5621 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5622 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5624 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5625 | E->getAccessorLoc(), |
| 5626 | E->getAccessor()); |
| 5627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5628 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5629 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5630 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5631 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5632 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5633 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5634 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5635 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 5636 | Inits, &InitChanged)) |
| 5637 | return ExprError(); |
| 5638 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5639 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5640 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5642 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 5643 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5646 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5647 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5648 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5649 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5650 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5651 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5652 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5653 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5654 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5655 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5656 | // transform the designators. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5657 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5658 | bool ExprChanged = false; |
| 5659 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 5660 | DEnd = E->designators_end(); |
| 5661 | D != DEnd; ++D) { |
| 5662 | if (D->isFieldDesignator()) { |
| 5663 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 5664 | D->getDotLoc(), |
| 5665 | D->getFieldLoc())); |
| 5666 | continue; |
| 5667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5669 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5670 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5671 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5672 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5673 | |
| 5674 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5675 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5677 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 5678 | ArrayExprs.push_back(Index.release()); |
| 5679 | continue; |
| 5680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5681 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5682 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5683 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 5685 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5686 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5687 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5688 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5689 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5690 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | |
| 5692 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5693 | End.get(), |
| 5694 | D->getLBracketLoc(), |
| 5695 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5696 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5697 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 5698 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5699 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5700 | ArrayExprs.push_back(Start.release()); |
| 5701 | ArrayExprs.push_back(End.release()); |
| 5702 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5703 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5704 | if (!getDerived().AlwaysRebuild() && |
| 5705 | Init.get() == E->getInit() && |
| 5706 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5707 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5708 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5709 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 5710 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5711 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5712 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5714 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5715 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5716 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5717 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5718 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5719 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5720 | // FIXME: Will we ever have proper type location here? Will we actually |
| 5721 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5722 | QualType T = getDerived().TransformType(E->getType()); |
| 5723 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5724 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5726 | if (!getDerived().AlwaysRebuild() && |
| 5727 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5728 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 5731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5733 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5734 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5735 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 5736 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 5737 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5738 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5739 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5740 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5741 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5742 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5743 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5744 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 5745 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5746 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5747 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5748 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5749 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 5750 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5751 | } |
| 5752 | |
| 5753 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5754 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5755 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5756 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5757 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5758 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 5759 | &ArgumentChanged)) |
| 5760 | return ExprError(); |
| 5761 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5762 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 5763 | move_arg(Inits), |
| 5764 | E->getRParenLoc()); |
| 5765 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5766 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5767 | /// \brief Transform an address-of-label expression. |
| 5768 | /// |
| 5769 | /// By default, the transformation of an address-of-label expression always |
| 5770 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 5771 | /// the corresponding label statement by semantic analysis. |
| 5772 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5773 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5774 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5775 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 5776 | E->getLabel()); |
| 5777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5778 | |
| 5779 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5780 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5781 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5782 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5783 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 5784 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5785 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5787 | if (!getDerived().AlwaysRebuild() && |
| 5788 | SubStmt.get() == E->getSubStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5789 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5790 | |
| 5791 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5792 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5793 | E->getRParenLoc()); |
| 5794 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5795 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5796 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5797 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5798 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5799 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5800 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5801 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5802 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5803 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5804 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5805 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5806 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5807 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5808 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5809 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5810 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5811 | if (!getDerived().AlwaysRebuild() && |
| 5812 | Cond.get() == E->getCond() && |
| 5813 | LHS.get() == E->getLHS() && |
| 5814 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5815 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5817 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5818 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5819 | E->getRParenLoc()); |
| 5820 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5821 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5822 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5823 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5824 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5825 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5829 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5830 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5831 | switch (E->getOperator()) { |
| 5832 | case OO_New: |
| 5833 | case OO_Delete: |
| 5834 | case OO_Array_New: |
| 5835 | case OO_Array_Delete: |
| 5836 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5837 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5838 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5839 | case OO_Call: { |
| 5840 | // This is a call to an object's operator(). |
| 5841 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 5842 | |
| 5843 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5844 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5845 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5846 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5847 | |
| 5848 | // FIXME: Poor location information |
| 5849 | SourceLocation FakeLParenLoc |
| 5850 | = SemaRef.PP.getLocForEndOfToken( |
| 5851 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 5852 | |
| 5853 | // Transform the call arguments. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5854 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5855 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 5856 | Args)) |
| 5857 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5858 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5859 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5860 | move_arg(Args), |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5861 | E->getLocEnd()); |
| 5862 | } |
| 5863 | |
| 5864 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 5865 | case OO_##Name: |
| 5866 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 5867 | #include "clang/Basic/OperatorKinds.def" |
| 5868 | case OO_Subscript: |
| 5869 | // Handled below. |
| 5870 | break; |
| 5871 | |
| 5872 | case OO_Conditional: |
| 5873 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5874 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5875 | |
| 5876 | case OO_None: |
| 5877 | case NUM_OVERLOADED_OPERATORS: |
| 5878 | llvm_unreachable("not an overloaded operator?"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5879 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5882 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5883 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5884 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5885 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5886 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5887 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5888 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5889 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5890 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5891 | if (E->getNumArgs() == 2) { |
| 5892 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 5893 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5894 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5896 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5897 | if (!getDerived().AlwaysRebuild() && |
| 5898 | Callee.get() == E->getCallee() && |
| 5899 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5901 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5902 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5903 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 5904 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5905 | Callee.get(), |
| 5906 | First.get(), |
| 5907 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5908 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5909 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5910 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5911 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5912 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5913 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5914 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5915 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5916 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5917 | ExprResult |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 5918 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 5919 | // Transform the callee. |
| 5920 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 5921 | if (Callee.isInvalid()) |
| 5922 | return ExprError(); |
| 5923 | |
| 5924 | // Transform exec config. |
| 5925 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 5926 | if (EC.isInvalid()) |
| 5927 | return ExprError(); |
| 5928 | |
| 5929 | // Transform arguments. |
| 5930 | bool ArgChanged = false; |
| 5931 | ASTOwningVector<Expr*> Args(SemaRef); |
| 5932 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5933 | &ArgChanged)) |
| 5934 | return ExprError(); |
| 5935 | |
| 5936 | if (!getDerived().AlwaysRebuild() && |
| 5937 | Callee.get() == E->getCallee() && |
| 5938 | !ArgChanged) |
| 5939 | return SemaRef.Owned(E); |
| 5940 | |
| 5941 | // FIXME: Wrong source location information for the '('. |
| 5942 | SourceLocation FakeLParenLoc |
| 5943 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 5944 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 5945 | move_arg(Args), |
| 5946 | E->getRParenLoc(), EC.get()); |
| 5947 | } |
| 5948 | |
| 5949 | template<typename Derived> |
| 5950 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5951 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5952 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5953 | if (!Type) |
| 5954 | return ExprError(); |
| 5955 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5956 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5957 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5958 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5959 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5961 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5962 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5963 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5964 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5966 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5967 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5968 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5969 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 5970 | SourceLocation FakeRParenLoc |
| 5971 | = SemaRef.PP.getLocForEndOfToken( |
| 5972 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5973 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5974 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5975 | FakeLAngleLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5976 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5977 | FakeRAngleLoc, |
| 5978 | FakeRAngleLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5979 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5980 | FakeRParenLoc); |
| 5981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5982 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5983 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5984 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5985 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5986 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5987 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5988 | |
| 5989 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5990 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5991 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5992 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5993 | } |
| 5994 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5995 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5996 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5997 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5998 | CXXReinterpretCastExpr *E) { |
| 5999 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6000 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6001 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6002 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6003 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6004 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6005 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6006 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6007 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6008 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6009 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6010 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6011 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6012 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6013 | if (!Type) |
| 6014 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6015 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6016 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6017 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6018 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6019 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6020 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6021 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6022 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6023 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6024 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6025 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6026 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6027 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6028 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6029 | E->getRParenLoc()); |
| 6030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6032 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6033 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6034 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6035 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6036 | TypeSourceInfo *TInfo |
| 6037 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6038 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6039 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6040 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6041 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6042 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6043 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6044 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6045 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6046 | E->getLocStart(), |
| 6047 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6048 | E->getLocEnd()); |
| 6049 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6050 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6051 | // We don't know whether the expression is potentially evaluated until |
| 6052 | // after we perform semantic analysis, so the expression is potentially |
| 6053 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6054 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6055 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6056 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6057 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6058 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6059 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6060 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6061 | if (!getDerived().AlwaysRebuild() && |
| 6062 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6063 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6064 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6065 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6066 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6067 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6068 | E->getLocEnd()); |
| 6069 | } |
| 6070 | |
| 6071 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6072 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6073 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6074 | if (E->isTypeOperand()) { |
| 6075 | TypeSourceInfo *TInfo |
| 6076 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6077 | if (!TInfo) |
| 6078 | return ExprError(); |
| 6079 | |
| 6080 | if (!getDerived().AlwaysRebuild() && |
| 6081 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6082 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6083 | |
| 6084 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6085 | E->getLocStart(), |
| 6086 | TInfo, |
| 6087 | E->getLocEnd()); |
| 6088 | } |
| 6089 | |
| 6090 | // We don't know whether the expression is potentially evaluated until |
| 6091 | // after we perform semantic analysis, so the expression is potentially |
| 6092 | // potentially evaluated. |
| 6093 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6094 | |
| 6095 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6096 | if (SubExpr.isInvalid()) |
| 6097 | return ExprError(); |
| 6098 | |
| 6099 | if (!getDerived().AlwaysRebuild() && |
| 6100 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6101 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6102 | |
| 6103 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6104 | E->getLocStart(), |
| 6105 | SubExpr.get(), |
| 6106 | E->getLocEnd()); |
| 6107 | } |
| 6108 | |
| 6109 | template<typename Derived> |
| 6110 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6111 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6112 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6114 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6115 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6116 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6117 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6118 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6119 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6122 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6123 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6124 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6125 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
| 6126 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); |
| 6127 | QualType T = MD->getThisType(getSema().Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6128 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6129 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6130 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6131 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6132 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6133 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6134 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6135 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6136 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6137 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6138 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6139 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6140 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6141 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6142 | if (!getDerived().AlwaysRebuild() && |
| 6143 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6144 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6145 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6146 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6149 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6150 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6151 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6152 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6153 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6154 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6155 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6156 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6157 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6158 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6159 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6160 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6161 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6162 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6163 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6164 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6165 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6166 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6167 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6168 | CXXScalarValueInitExpr *E) { |
| 6169 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6170 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6171 | return ExprError(); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6172 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6173 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6174 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6175 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6176 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6177 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6178 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6179 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6181 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6182 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6183 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6184 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6185 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6186 | TypeSourceInfo *AllocTypeInfo |
| 6187 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6188 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6189 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6190 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6191 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6192 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6193 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6194 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6196 | // Transform the placement arguments (if any). |
| 6197 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6198 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6199 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6200 | E->getNumPlacementArgs(), true, |
| 6201 | PlacementArgs, &ArgumentChanged)) |
| 6202 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6203 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6204 | // transform the constructor arguments (if any). |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6205 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6206 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6207 | ConstructorArgs, &ArgumentChanged)) |
| 6208 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6209 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6210 | // Transform constructor, new operator, and delete operator. |
| 6211 | CXXConstructorDecl *Constructor = 0; |
| 6212 | if (E->getConstructor()) { |
| 6213 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6214 | getDerived().TransformDecl(E->getLocStart(), |
| 6215 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6216 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6217 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | FunctionDecl *OperatorNew = 0; |
| 6221 | if (E->getOperatorNew()) { |
| 6222 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6223 | getDerived().TransformDecl(E->getLocStart(), |
| 6224 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6225 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6226 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | FunctionDecl *OperatorDelete = 0; |
| 6230 | if (E->getOperatorDelete()) { |
| 6231 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6232 | getDerived().TransformDecl(E->getLocStart(), |
| 6233 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6234 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6235 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6236 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6237 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6238 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6239 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6240 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6241 | Constructor == E->getConstructor() && |
| 6242 | OperatorNew == E->getOperatorNew() && |
| 6243 | OperatorDelete == E->getOperatorDelete() && |
| 6244 | !ArgumentChanged) { |
| 6245 | // Mark any declarations we need as referenced. |
| 6246 | // FIXME: instantiation-specific. |
| 6247 | if (Constructor) |
| 6248 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6249 | if (OperatorNew) |
| 6250 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6251 | if (OperatorDelete) |
| 6252 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6253 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6255 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6256 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6257 | if (!ArraySize.get()) { |
| 6258 | // If no array size was specified, but the new expression was |
| 6259 | // instantiated with an array type (e.g., "new T" where T is |
| 6260 | // instantiated with "int[4]"), extract the outer bound from the |
| 6261 | // array type as our array size. We do this with constant and |
| 6262 | // dependently-sized array types. |
| 6263 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6264 | if (!ArrayT) { |
| 6265 | // Do nothing |
| 6266 | } else if (const ConstantArrayType *ConsArrayT |
| 6267 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6268 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6269 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6270 | ConsArrayT->getSize(), |
| 6271 | SemaRef.Context.getSizeType(), |
| 6272 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6273 | AllocType = ConsArrayT->getElementType(); |
| 6274 | } else if (const DependentSizedArrayType *DepArrayT |
| 6275 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6276 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6277 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6278 | AllocType = DepArrayT->getElementType(); |
| 6279 | } |
| 6280 | } |
| 6281 | } |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6282 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6283 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6284 | E->isGlobalNew(), |
| 6285 | /*FIXME:*/E->getLocStart(), |
| 6286 | move_arg(PlacementArgs), |
| 6287 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6288 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6289 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6290 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6291 | ArraySize.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6292 | /*FIXME:*/E->getLocStart(), |
| 6293 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6295 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6296 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6297 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6298 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6299 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6300 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6301 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6302 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6303 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6304 | // Transform the delete operator, if known. |
| 6305 | FunctionDecl *OperatorDelete = 0; |
| 6306 | if (E->getOperatorDelete()) { |
| 6307 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6308 | getDerived().TransformDecl(E->getLocStart(), |
| 6309 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6310 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6311 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6312 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6313 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6314 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6315 | Operand.get() == E->getArgument() && |
| 6316 | OperatorDelete == E->getOperatorDelete()) { |
| 6317 | // Mark any declarations we need as referenced. |
| 6318 | // FIXME: instantiation-specific. |
| 6319 | if (OperatorDelete) |
| 6320 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 6321 | |
| 6322 | if (!E->getArgument()->isTypeDependent()) { |
| 6323 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 6324 | E->getDestroyedType()); |
| 6325 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 6326 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 6327 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 6328 | SemaRef.LookupDestructor(Record)); |
| 6329 | } |
| 6330 | } |
| 6331 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6332 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6334 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6335 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 6336 | E->isGlobalDelete(), |
| 6337 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6338 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6341 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6342 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6343 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6344 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6345 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6346 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6347 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6348 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6349 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6350 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6351 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6352 | E->getOperatorLoc(), |
| 6353 | E->isArrow()? tok::arrow : tok::period, |
| 6354 | ObjectTypePtr, |
| 6355 | MayBePseudoDestructor); |
| 6356 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6357 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6358 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6359 | QualType ObjectType = ObjectTypePtr.get(); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6360 | NestedNameSpecifier *Qualifier = E->getQualifier(); |
| 6361 | if (Qualifier) { |
| 6362 | Qualifier |
| 6363 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 6364 | E->getQualifierRange(), |
| 6365 | ObjectType); |
| 6366 | if (!Qualifier) |
| 6367 | return ExprError(); |
| 6368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6369 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6370 | PseudoDestructorTypeStorage Destroyed; |
| 6371 | if (E->getDestroyedTypeInfo()) { |
| 6372 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6373 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
| 6374 | ObjectType, 0, Qualifier); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6375 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6376 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6377 | Destroyed = DestroyedTypeInfo; |
| 6378 | } else if (ObjectType->isDependentType()) { |
| 6379 | // We aren't likely to be able to resolve the identifier down to a type |
| 6380 | // now anyway, so just retain the identifier. |
| 6381 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 6382 | E->getDestroyedTypeLoc()); |
| 6383 | } else { |
| 6384 | // Look for a destructor known with the given name. |
| 6385 | CXXScopeSpec SS; |
| 6386 | if (Qualifier) { |
| 6387 | SS.setScopeRep(Qualifier); |
| 6388 | SS.setRange(E->getQualifierRange()); |
| 6389 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6390 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6391 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6392 | *E->getDestroyedTypeIdentifier(), |
| 6393 | E->getDestroyedTypeLoc(), |
| 6394 | /*Scope=*/0, |
| 6395 | SS, ObjectTypePtr, |
| 6396 | false); |
| 6397 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6398 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6399 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6400 | Destroyed |
| 6401 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 6402 | E->getDestroyedTypeLoc()); |
| 6403 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6404 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6405 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 6406 | if (E->getScopeTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6407 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6408 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6409 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6410 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6411 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6412 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6413 | E->getOperatorLoc(), |
| 6414 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6415 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6416 | E->getQualifierRange(), |
| 6417 | ScopeTypeInfo, |
| 6418 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6419 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6420 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6421 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6422 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6423 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6424 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6425 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6426 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6427 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 6428 | |
| 6429 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 6430 | Sema::LookupOrdinaryName); |
| 6431 | |
| 6432 | // Transform all the decls. |
| 6433 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 6434 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6435 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6436 | getDerived().TransformDecl(Old->getNameLoc(), |
| 6437 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6438 | if (!InstD) { |
| 6439 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6440 | // This can happen because of dependent hiding. |
| 6441 | if (isa<UsingShadowDecl>(*I)) |
| 6442 | continue; |
| 6443 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6444 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6445 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6446 | |
| 6447 | // Expand using declarations. |
| 6448 | if (isa<UsingDecl>(InstD)) { |
| 6449 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6450 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6451 | E = UD->shadow_end(); I != E; ++I) |
| 6452 | R.addDecl(*I); |
| 6453 | continue; |
| 6454 | } |
| 6455 | |
| 6456 | R.addDecl(InstD); |
| 6457 | } |
| 6458 | |
| 6459 | // Resolve a kind, but don't do any further analysis. If it's |
| 6460 | // ambiguous, the callee needs to deal with it. |
| 6461 | R.resolveKind(); |
| 6462 | |
| 6463 | // Rebuild the nested-name qualifier, if present. |
| 6464 | CXXScopeSpec SS; |
| 6465 | NestedNameSpecifier *Qualifier = 0; |
| 6466 | if (Old->getQualifier()) { |
| 6467 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6468 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6469 | if (!Qualifier) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6470 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6471 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6472 | SS.setScopeRep(Qualifier); |
| 6473 | SS.setRange(Old->getQualifierRange()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6474 | } |
| 6475 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6476 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6477 | CXXRecordDecl *NamingClass |
| 6478 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 6479 | Old->getNameLoc(), |
| 6480 | Old->getNamingClass())); |
| 6481 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6482 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6483 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6484 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6485 | } |
| 6486 | |
| 6487 | // If we have no template arguments, it's a normal declaration name. |
| 6488 | if (!Old->hasExplicitTemplateArgs()) |
| 6489 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 6490 | |
| 6491 | // If we have template arguments, rebuild them, then rebuild the |
| 6492 | // templateid expression. |
| 6493 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6494 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6495 | Old->getNumTemplateArgs(), |
| 6496 | TransArgs)) |
| 6497 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6498 | |
| 6499 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 6500 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6501 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6503 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6504 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6505 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6506 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 6507 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6508 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6509 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6510 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6511 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6512 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6513 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6515 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6516 | T, |
| 6517 | E->getLocEnd()); |
| 6518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6520 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6521 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 6522 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 6523 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 6524 | if (!LhsT) |
| 6525 | return ExprError(); |
| 6526 | |
| 6527 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 6528 | if (!RhsT) |
| 6529 | return ExprError(); |
| 6530 | |
| 6531 | if (!getDerived().AlwaysRebuild() && |
| 6532 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 6533 | return SemaRef.Owned(E); |
| 6534 | |
| 6535 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 6536 | E->getLocStart(), |
| 6537 | LhsT, RhsT, |
| 6538 | E->getLocEnd()); |
| 6539 | } |
| 6540 | |
| 6541 | template<typename Derived> |
| 6542 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6543 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6544 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6545 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6546 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6547 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6548 | if (!NNS) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6549 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6550 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6551 | // TODO: If this is a conversion-function-id, verify that the |
| 6552 | // destination type name (if present) resolves the same way after |
| 6553 | // instantiation as it did in the local scope. |
| 6554 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6555 | DeclarationNameInfo NameInfo |
| 6556 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 6557 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6558 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6559 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6560 | if (!E->hasExplicitTemplateArgs()) { |
| 6561 | if (!getDerived().AlwaysRebuild() && |
| 6562 | NNS == E->getQualifier() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6563 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 6564 | // if name has not changed, DNLoc has not changed either. |
| 6565 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6566 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6567 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6568 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 6569 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6570 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6571 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6572 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6573 | |
| 6574 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6575 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6576 | E->getNumTemplateArgs(), |
| 6577 | TransArgs)) |
| 6578 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6579 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6580 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 6581 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6582 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6583 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6587 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6588 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 6589 | // CXXConstructExprs are always implicit, so when we have a |
| 6590 | // 1-argument construction we just transform that argument. |
| 6591 | if (E->getNumArgs() == 1 || |
| 6592 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 6593 | return getDerived().TransformExpr(E->getArg(0)); |
| 6594 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6595 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 6596 | |
| 6597 | QualType T = getDerived().TransformType(E->getType()); |
| 6598 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6599 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6600 | |
| 6601 | CXXConstructorDecl *Constructor |
| 6602 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6603 | getDerived().TransformDecl(E->getLocStart(), |
| 6604 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6605 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6606 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6608 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6609 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6610 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6611 | &ArgumentChanged)) |
| 6612 | return ExprError(); |
| 6613 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6614 | if (!getDerived().AlwaysRebuild() && |
| 6615 | T == E->getType() && |
| 6616 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6617 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6618 | // Mark the constructor as referenced. |
| 6619 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6620 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6621 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6623 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 6624 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 6625 | Constructor, E->isElidable(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 6626 | move_arg(Args), |
| 6627 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 6628 | E->getConstructionKind(), |
| 6629 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6631 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6632 | /// \brief Transform a C++ temporary-binding expression. |
| 6633 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6634 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 6635 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6636 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6637 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6638 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6639 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6641 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6642 | /// \brief Transform a C++ expression that contains cleanups that should |
| 6643 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6644 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6645 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6646 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6647 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6648 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6649 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6650 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6652 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6653 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6654 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6655 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6656 | CXXTemporaryObjectExpr *E) { |
| 6657 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6658 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6659 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6661 | CXXConstructorDecl *Constructor |
| 6662 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6663 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6664 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6666 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6667 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6668 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6669 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6670 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6671 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6672 | &ArgumentChanged)) |
| 6673 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6674 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6675 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6676 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6677 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6678 | !ArgumentChanged) { |
| 6679 | // FIXME: Instantiation-specific |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6680 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6681 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6682 | } |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6683 | |
| 6684 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 6685 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6686 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6687 | E->getLocEnd()); |
| 6688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6690 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6691 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6692 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6693 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6694 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6695 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6696 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6697 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6698 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6699 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6700 | Args.reserve(E->arg_size()); |
| 6701 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 6702 | &ArgumentChanged)) |
| 6703 | return ExprError(); |
| 6704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6705 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6706 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6707 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6708 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6709 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6710 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6711 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6712 | E->getLParenLoc(), |
| 6713 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6714 | E->getRParenLoc()); |
| 6715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6716 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6717 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6718 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6719 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6720 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6721 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6722 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6723 | Expr *OldBase; |
| 6724 | QualType BaseType; |
| 6725 | QualType ObjectType; |
| 6726 | if (!E->isImplicitAccess()) { |
| 6727 | OldBase = E->getBase(); |
| 6728 | Base = getDerived().TransformExpr(OldBase); |
| 6729 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6730 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6731 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6732 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6733 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 6734 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6735 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6736 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6737 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 6738 | ObjectTy, |
| 6739 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6740 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6741 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6742 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6743 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6744 | BaseType = ((Expr*) Base.get())->getType(); |
| 6745 | } else { |
| 6746 | OldBase = 0; |
| 6747 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 6748 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 6749 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6750 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 6751 | // Transform the first part of the nested-name-specifier that qualifies |
| 6752 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6753 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 6754 | = getDerived().TransformFirstQualifierInScope( |
| 6755 | E->getFirstQualifierFoundInScope(), |
| 6756 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6757 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6758 | NestedNameSpecifier *Qualifier = 0; |
| 6759 | if (E->getQualifier()) { |
| 6760 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 6761 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6762 | ObjectType, |
| 6763 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6764 | if (!Qualifier) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6765 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6767 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6768 | // TODO: If this is a conversion-function-id, verify that the |
| 6769 | // destination type name (if present) resolves the same way after |
| 6770 | // instantiation as it did in the local scope. |
| 6771 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6772 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6773 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6774 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6775 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6776 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6777 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6778 | // This is a reference to a member without an explicitly-specified |
| 6779 | // template argument list. Optimize for this common case. |
| 6780 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6781 | Base.get() == OldBase && |
| 6782 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6783 | Qualifier == E->getQualifier() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6784 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6785 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6786 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6787 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6788 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6789 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6790 | E->isArrow(), |
| 6791 | E->getOperatorLoc(), |
| 6792 | Qualifier, |
| 6793 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6794 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6795 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6796 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6797 | } |
| 6798 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6799 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6800 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6801 | E->getNumTemplateArgs(), |
| 6802 | TransArgs)) |
| 6803 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6804 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6805 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6806 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6807 | E->isArrow(), |
| 6808 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6809 | Qualifier, |
| 6810 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6811 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6812 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6813 | &TransArgs); |
| 6814 | } |
| 6815 | |
| 6816 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6817 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6818 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6819 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6820 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6821 | QualType BaseType; |
| 6822 | if (!Old->isImplicitAccess()) { |
| 6823 | Base = getDerived().TransformExpr(Old->getBase()); |
| 6824 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6825 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6826 | BaseType = ((Expr*) Base.get())->getType(); |
| 6827 | } else { |
| 6828 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 6829 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6830 | |
| 6831 | NestedNameSpecifier *Qualifier = 0; |
| 6832 | if (Old->getQualifier()) { |
| 6833 | Qualifier |
| 6834 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6835 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6836 | if (Qualifier == 0) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6837 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6838 | } |
| 6839 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6840 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6841 | Sema::LookupOrdinaryName); |
| 6842 | |
| 6843 | // Transform all the decls. |
| 6844 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 6845 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6846 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6847 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 6848 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6849 | if (!InstD) { |
| 6850 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6851 | // This can happen because of dependent hiding. |
| 6852 | if (isa<UsingShadowDecl>(*I)) |
| 6853 | continue; |
| 6854 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6855 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6856 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6857 | |
| 6858 | // Expand using declarations. |
| 6859 | if (isa<UsingDecl>(InstD)) { |
| 6860 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6861 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6862 | E = UD->shadow_end(); I != E; ++I) |
| 6863 | R.addDecl(*I); |
| 6864 | continue; |
| 6865 | } |
| 6866 | |
| 6867 | R.addDecl(InstD); |
| 6868 | } |
| 6869 | |
| 6870 | R.resolveKind(); |
| 6871 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6872 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 6873 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6874 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6875 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6876 | Old->getMemberLoc(), |
| 6877 | Old->getNamingClass())); |
| 6878 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6879 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6880 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6881 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6882 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6883 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6884 | TemplateArgumentListInfo TransArgs; |
| 6885 | if (Old->hasExplicitTemplateArgs()) { |
| 6886 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 6887 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6888 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6889 | Old->getNumTemplateArgs(), |
| 6890 | TransArgs)) |
| 6891 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6892 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6893 | |
| 6894 | // FIXME: to do this check properly, we will need to preserve the |
| 6895 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6896 | // base (and therefore couldn't do the check) and a |
| 6897 | // nested-name-qualifier (and therefore could do the lookup). |
| 6898 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6899 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6900 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6901 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6902 | Old->getOperatorLoc(), |
| 6903 | Old->isArrow(), |
| 6904 | Qualifier, |
| 6905 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6906 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6907 | R, |
| 6908 | (Old->hasExplicitTemplateArgs() |
| 6909 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6913 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 6914 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6915 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 6916 | if (SubExpr.isInvalid()) |
| 6917 | return ExprError(); |
| 6918 | |
| 6919 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6920 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 6921 | |
| 6922 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 6923 | } |
| 6924 | |
| 6925 | template<typename Derived> |
| 6926 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6927 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 6928 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 6929 | if (Pattern.isInvalid()) |
| 6930 | return ExprError(); |
| 6931 | |
| 6932 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 6933 | return SemaRef.Owned(E); |
| 6934 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 6935 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 6936 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6937 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6938 | |
| 6939 | template<typename Derived> |
| 6940 | ExprResult |
| 6941 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6942 | // If E is not value-dependent, then nothing will change when we transform it. |
| 6943 | // Note: This is an instantiation-centric view. |
| 6944 | if (!E->isValueDependent()) |
| 6945 | return SemaRef.Owned(E); |
| 6946 | |
| 6947 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 6948 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 6949 | // so |
| 6950 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 6951 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 6952 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6953 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6954 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 6955 | &Unexpanded, 1, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 6956 | ShouldExpand, RetainExpansion, |
| 6957 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6958 | return ExprError(); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6959 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 6960 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6961 | return SemaRef.Owned(E); |
| 6962 | |
| 6963 | // We now know the length of the parameter pack, so build a new expression |
| 6964 | // that stores that length. |
| 6965 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 6966 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6967 | *NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6970 | template<typename Derived> |
| 6971 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 6973 | SubstNonTypeTemplateParmPackExpr *E) { |
| 6974 | // Default behavior is to do nothing with this transformation. |
| 6975 | return SemaRef.Owned(E); |
| 6976 | } |
| 6977 | |
| 6978 | template<typename Derived> |
| 6979 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6980 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6981 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6982 | } |
| 6983 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6984 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6985 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6986 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6987 | TypeSourceInfo *EncodedTypeInfo |
| 6988 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 6989 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6990 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6991 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6992 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6993 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6994 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6995 | |
| 6996 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6997 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6998 | E->getRParenLoc()); |
| 6999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7001 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7002 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7003 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7004 | // Transform arguments. |
| 7005 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7006 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7007 | Args.reserve(E->getNumArgs()); |
| 7008 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 7009 | &ArgChanged)) |
| 7010 | return ExprError(); |
| 7011 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7012 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 7013 | // Class message: transform the receiver type. |
| 7014 | TypeSourceInfo *ReceiverTypeInfo |
| 7015 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 7016 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7017 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7018 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7019 | // If nothing changed, just retain the existing message send. |
| 7020 | if (!getDerived().AlwaysRebuild() && |
| 7021 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7022 | return SemaRef.Owned(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7023 | |
| 7024 | // Build a new class message send. |
| 7025 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7026 | E->getSelector(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7027 | E->getSelectorLoc(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7028 | E->getMethodDecl(), |
| 7029 | E->getLeftLoc(), |
| 7030 | move_arg(Args), |
| 7031 | E->getRightLoc()); |
| 7032 | } |
| 7033 | |
| 7034 | // Instance message: transform the receiver |
| 7035 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7036 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7037 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7038 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7039 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7040 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7041 | |
| 7042 | // If nothing changed, just retain the existing message send. |
| 7043 | if (!getDerived().AlwaysRebuild() && |
| 7044 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7045 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7046 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7047 | // Build a new instance message send. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7048 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7049 | E->getSelector(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7050 | E->getSelectorLoc(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7051 | E->getMethodDecl(), |
| 7052 | E->getLeftLoc(), |
| 7053 | move_arg(Args), |
| 7054 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7055 | } |
| 7056 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7057 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7058 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7059 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7060 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7061 | } |
| 7062 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7063 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7064 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7065 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7066 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7067 | } |
| 7068 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7069 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7070 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7071 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7072 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7073 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7074 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7075 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7076 | |
| 7077 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7078 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7079 | // If nothing changed, just retain the existing expression. |
| 7080 | if (!getDerived().AlwaysRebuild() && |
| 7081 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7082 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7083 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7084 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7085 | E->getLocation(), |
| 7086 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7087 | } |
| 7088 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7089 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7090 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7091 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7092 | // 'super' and types never change. Property never changes. Just |
| 7093 | // retain the existing expression. |
| 7094 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7095 | return SemaRef.Owned(E); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7096 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7097 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7098 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7099 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7100 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7101 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7102 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7103 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7104 | // If nothing changed, just retain the existing expression. |
| 7105 | if (!getDerived().AlwaysRebuild() && |
| 7106 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7107 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7108 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7109 | if (E->isExplicitProperty()) |
| 7110 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7111 | E->getExplicitProperty(), |
| 7112 | E->getLocation()); |
| 7113 | |
| 7114 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7115 | E->getType(), |
| 7116 | E->getImplicitPropertyGetter(), |
| 7117 | E->getImplicitPropertySetter(), |
| 7118 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7119 | } |
| 7120 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7121 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7122 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7123 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7124 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7125 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7126 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7127 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7128 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7129 | // If nothing changed, just retain the existing expression. |
| 7130 | if (!getDerived().AlwaysRebuild() && |
| 7131 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7132 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7133 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7134 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7135 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7136 | } |
| 7137 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7138 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7139 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7140 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7141 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7142 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7143 | SubExprs.reserve(E->getNumSubExprs()); |
| 7144 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7145 | SubExprs, &ArgumentChanged)) |
| 7146 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7147 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7148 | if (!getDerived().AlwaysRebuild() && |
| 7149 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7150 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7151 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7152 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7153 | move_arg(SubExprs), |
| 7154 | E->getRParenLoc()); |
| 7155 | } |
| 7156 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7157 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7158 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7159 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7160 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7161 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7162 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7163 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7164 | |
| 7165 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 7166 | llvm::SmallVector<ParmVarDecl*, 4> params; |
| 7167 | llvm::SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7168 | |
| 7169 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7170 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7171 | oldBlock->param_begin(), |
| 7172 | oldBlock->param_size(), |
| 7173 | 0, paramTypes, ¶ms)) |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7174 | return true; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7175 | |
| 7176 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7177 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7178 | if (!exprResultType.isNull()) { |
| 7179 | if (!exprResultType->isDependentType()) |
| 7180 | blockScope->ReturnType = exprResultType; |
| 7181 | else if (exprResultType != getSema().Context.DependentTy) |
| 7182 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7183 | } |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7184 | |
| 7185 | // If the return type has not been determined yet, leave it as a dependent |
| 7186 | // type; it'll get set when we process the body. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7187 | if (blockScope->ReturnType.isNull()) |
| 7188 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7189 | |
| 7190 | // Don't allow returning a objc interface by value. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7191 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7192 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7193 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7194 | << 0 << blockScope->ReturnType; |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7195 | return ExprError(); |
| 7196 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7197 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7198 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7199 | blockScope->ReturnType, |
| 7200 | paramTypes.data(), |
| 7201 | paramTypes.size(), |
| 7202 | oldBlock->isVariadic(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7203 | 0, RQ_None, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7204 | exprFunctionType->getExtInfo()); |
| 7205 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7206 | |
| 7207 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7208 | if (!params.empty()) |
| 7209 | blockScope->TheDecl->setParams(params.data(), params.size()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7210 | |
| 7211 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7212 | // dependent type (DependentTy); clear out the return type setting so |
| 7213 | // we will deduce the return type when type-checking the block's body. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7214 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7215 | blockScope->ReturnType = QualType(); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7216 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7217 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7218 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7219 | if (body.isInvalid()) |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7220 | return ExprError(); |
| 7221 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7222 | #ifndef NDEBUG |
| 7223 | // In builds with assertions, make sure that we captured everything we |
| 7224 | // captured before. |
| 7225 | |
| 7226 | if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); |
| 7227 | |
| 7228 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 7229 | e = oldBlock->capture_end(); i != e; ++i) { |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7230 | VarDecl *oldCapture = i->getVariable(); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7231 | |
| 7232 | // Ignore parameter packs. |
| 7233 | if (isa<ParmVarDecl>(oldCapture) && |
| 7234 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 7235 | continue; |
| 7236 | |
| 7237 | VarDecl *newCapture = |
| 7238 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 7239 | oldCapture)); |
John McCall | 6b5a61b | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7240 | assert(blockScope->CaptureMap.count(newCapture)); |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7241 | } |
| 7242 | #endif |
| 7243 | |
| 7244 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 7245 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7246 | } |
| 7247 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7248 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7249 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7250 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7251 | NestedNameSpecifier *Qualifier = 0; |
| 7252 | |
| 7253 | ValueDecl *ND |
| 7254 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7255 | E->getDecl())); |
| 7256 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7257 | return ExprError(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7258 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7259 | if (!getDerived().AlwaysRebuild() && |
| 7260 | ND == E->getDecl()) { |
| 7261 | // Mark it referenced in the new context regardless. |
| 7262 | // FIXME: this is a bit instantiation-specific. |
| 7263 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 7264 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7265 | return SemaRef.Owned(E); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7266 | } |
| 7267 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7268 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7269 | return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7270 | ND, NameInfo, 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7272 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7273 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7274 | // Type reconstruction |
| 7275 | //===----------------------------------------------------------------------===// |
| 7276 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7277 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7278 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 7279 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7280 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7281 | getDerived().getBaseEntity()); |
| 7282 | } |
| 7283 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7284 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7285 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 7286 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7287 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7288 | getDerived().getBaseEntity()); |
| 7289 | } |
| 7290 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7291 | template<typename Derived> |
| 7292 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7293 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 7294 | bool WrittenAsLValue, |
| 7295 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7296 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7297 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7298 | } |
| 7299 | |
| 7300 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7301 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7302 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 7303 | QualType ClassType, |
| 7304 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7305 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7306 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7307 | } |
| 7308 | |
| 7309 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7310 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7311 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 7312 | ArrayType::ArraySizeModifier SizeMod, |
| 7313 | const llvm::APInt *Size, |
| 7314 | Expr *SizeExpr, |
| 7315 | unsigned IndexTypeQuals, |
| 7316 | SourceRange BracketsRange) { |
| 7317 | if (SizeExpr || !Size) |
| 7318 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 7319 | IndexTypeQuals, BracketsRange, |
| 7320 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7321 | |
| 7322 | QualType Types[] = { |
| 7323 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 7324 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 7325 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7326 | }; |
| 7327 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 7328 | QualType SizeType; |
| 7329 | for (unsigned I = 0; I != NumTypes; ++I) |
| 7330 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 7331 | SizeType = Types[I]; |
| 7332 | break; |
| 7333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7334 | |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7335 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 7336 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7337 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7338 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7339 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7341 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7342 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7343 | QualType |
| 7344 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7345 | ArrayType::ArraySizeModifier SizeMod, |
| 7346 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7347 | unsigned IndexTypeQuals, |
| 7348 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7349 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7350 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7351 | } |
| 7352 | |
| 7353 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7354 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7355 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7356 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7357 | unsigned IndexTypeQuals, |
| 7358 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7359 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7360 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7362 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7363 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7364 | QualType |
| 7365 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7366 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7367 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7368 | unsigned IndexTypeQuals, |
| 7369 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7370 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7371 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7372 | IndexTypeQuals, BracketsRange); |
| 7373 | } |
| 7374 | |
| 7375 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7376 | QualType |
| 7377 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7378 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7379 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7380 | unsigned IndexTypeQuals, |
| 7381 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7382 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7383 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7384 | IndexTypeQuals, BracketsRange); |
| 7385 | } |
| 7386 | |
| 7387 | template<typename Derived> |
| 7388 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7389 | unsigned NumElements, |
| 7390 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7391 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7392 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7393 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7394 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7395 | template<typename Derived> |
| 7396 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 7397 | unsigned NumElements, |
| 7398 | SourceLocation AttributeLoc) { |
| 7399 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 7400 | NumElements, true); |
| 7401 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7402 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 7403 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7404 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7406 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7407 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7408 | QualType |
| 7409 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7410 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7411 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7412 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7413 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7414 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7415 | template<typename Derived> |
| 7416 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7417 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7418 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7419 | bool Variadic, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7420 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7421 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7422 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7423 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7424 | Quals, RefQualifier, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7425 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7426 | getDerived().getBaseEntity(), |
| 7427 | Info); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7428 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7429 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7430 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 7431 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 7432 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 7433 | } |
| 7434 | |
| 7435 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7436 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 7437 | assert(D && "no decl found"); |
| 7438 | if (D->isInvalidDecl()) return QualType(); |
| 7439 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7440 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7441 | TypeDecl *Ty; |
| 7442 | if (isa<UsingDecl>(D)) { |
| 7443 | UsingDecl *Using = cast<UsingDecl>(D); |
| 7444 | assert(Using->isTypeName() && |
| 7445 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 7446 | |
| 7447 | // A valid resolved using typename decl points to exactly one type decl. |
| 7448 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 7449 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7450 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7451 | } else { |
| 7452 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 7453 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 7454 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 7455 | } |
| 7456 | |
| 7457 | return SemaRef.Context.getTypeDeclType(Ty); |
| 7458 | } |
| 7459 | |
| 7460 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7461 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 7462 | SourceLocation Loc) { |
| 7463 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7464 | } |
| 7465 | |
| 7466 | template<typename Derived> |
| 7467 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 7468 | return SemaRef.Context.getTypeOfType(Underlying); |
| 7469 | } |
| 7470 | |
| 7471 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7472 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 7473 | SourceLocation Loc) { |
| 7474 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | template<typename Derived> |
| 7478 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 7479 | TemplateName Template, |
| 7480 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7481 | const TemplateArgumentListInfo &TemplateArgs) { |
| 7482 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7484 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7485 | template<typename Derived> |
| 7486 | NestedNameSpecifier * |
| 7487 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7488 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7489 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7490 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7491 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7492 | CXXScopeSpec SS; |
| 7493 | // FIXME: The source location information is all wrong. |
| 7494 | SS.setRange(Range); |
| 7495 | SS.setScopeRep(Prefix); |
| 7496 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7497 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 7498 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7499 | ObjectType, |
| 7500 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 7501 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7502 | } |
| 7503 | |
| 7504 | template<typename Derived> |
| 7505 | NestedNameSpecifier * |
| 7506 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7507 | SourceRange Range, |
| 7508 | NamespaceDecl *NS) { |
| 7509 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 7510 | } |
| 7511 | |
| 7512 | template<typename Derived> |
| 7513 | NestedNameSpecifier * |
| 7514 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7515 | SourceRange Range, |
| 7516 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 7517 | QualType T) { |
| 7518 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7519 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 7520 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7521 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 7522 | T.getTypePtr()); |
| 7523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7524 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7525 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 7526 | return 0; |
| 7527 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7528 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7529 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7530 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7531 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7532 | bool TemplateKW, |
| 7533 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7534 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7535 | Template); |
| 7536 | } |
| 7537 | |
| 7538 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7539 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7540 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 7541 | SourceRange QualifierRange, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7542 | const IdentifierInfo &II, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7543 | QualType ObjectType, |
| 7544 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7545 | CXXScopeSpec SS; |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 7546 | SS.setRange(QualifierRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7547 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 7548 | UnqualifiedId Name; |
| 7549 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7550 | Sema::TemplateTy Template; |
| 7551 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 7552 | /*FIXME:*/getDerived().getBaseLocation(), |
| 7553 | SS, |
| 7554 | Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7555 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7556 | /*EnteringContext=*/false, |
| 7557 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7558 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7561 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7562 | TemplateName |
| 7563 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7564 | OverloadedOperatorKind Operator, |
| 7565 | QualType ObjectType) { |
| 7566 | CXXScopeSpec SS; |
| 7567 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 7568 | SS.setScopeRep(Qualifier); |
| 7569 | UnqualifiedId Name; |
| 7570 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 7571 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 7572 | Operator, SymbolLocations); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7573 | Sema::TemplateTy Template; |
| 7574 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7575 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7576 | SS, |
| 7577 | Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7578 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7579 | /*EnteringContext=*/false, |
| 7580 | Template); |
| 7581 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7582 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7583 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7584 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7585 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7586 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 7587 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7588 | Expr *OrigCallee, |
| 7589 | Expr *First, |
| 7590 | Expr *Second) { |
| 7591 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 7592 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7594 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7595 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7596 | if (!First->getType()->isOverloadableType() && |
| 7597 | !Second->getType()->isOverloadableType()) |
| 7598 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 7599 | Callee->getLocStart(), |
| 7600 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 7601 | } else if (Op == OO_Arrow) { |
| 7602 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7603 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 7604 | } else if (Second == 0 || isPostIncDec) { |
| 7605 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7606 | // The argument is not of overloadable type, so try to create a |
| 7607 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7608 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7609 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7610 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7611 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7612 | } |
| 7613 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7614 | if (!First->getType()->isOverloadableType() && |
| 7615 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7616 | // Neither of the arguments is an overloadable type, so try to |
| 7617 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7618 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7619 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7620 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7621 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7622 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7624 | return move(Result); |
| 7625 | } |
| 7626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7627 | |
| 7628 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7629 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7630 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7631 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7632 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7633 | assert(ULE->requiresADL()); |
| 7634 | |
| 7635 | // FIXME: Do we have to check |
| 7636 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7637 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7638 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7639 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7642 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7643 | Expr *Args[2] = { First, Second }; |
| 7644 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7646 | // Create the overloaded operator invocation for unary operators. |
| 7647 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7648 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7649 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7650 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7652 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7653 | if (Op == OO_Subscript) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7654 | return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7655 | OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7656 | First, |
| 7657 | Second); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7659 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7660 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7661 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7662 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 7663 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7664 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7665 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7666 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7668 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7669 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7670 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7671 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7672 | SourceLocation OperatorLoc, |
| 7673 | bool isArrow, |
| 7674 | NestedNameSpecifier *Qualifier, |
| 7675 | SourceRange QualifierRange, |
| 7676 | TypeSourceInfo *ScopeType, |
| 7677 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7678 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7679 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7680 | CXXScopeSpec SS; |
| 7681 | if (Qualifier) { |
| 7682 | SS.setRange(QualifierRange); |
| 7683 | SS.setScopeRep(Qualifier); |
| 7684 | } |
| 7685 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7686 | QualType BaseType = Base->getType(); |
| 7687 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7688 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7689 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 7690 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 7691 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7692 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7693 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7694 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7695 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7696 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7697 | /*FIXME?*/true); |
| 7698 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7699 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7700 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7701 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 7702 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 7703 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 7704 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 7705 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7706 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7707 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7708 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7709 | OperatorLoc, isArrow, |
| 7710 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7711 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7712 | /*TemplateArgs*/ 0); |
| 7713 | } |
| 7714 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7715 | } // end namespace clang |
| 7716 | |
| 7717 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |