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. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 978 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 979 | IdentifierInfo *Id, |
| 980 | SourceLocation ColonLoc, |
Argyrios Kyrtzidis | 1a18600 | 2010-09-28 14:54:07 +0000 | [diff] [blame] | 981 | Stmt *SubStmt, bool HasUnusedAttr) { |
| 982 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt, |
| 983 | HasUnusedAttr); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 984 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 986 | /// \brief Build a new "if" statement. |
| 987 | /// |
| 988 | /// By default, performs semantic analysis to build the new statement. |
| 989 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 990 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 991 | VarDecl *CondVar, Stmt *Then, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 992 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 993 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 995 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 996 | /// \brief Start building a new switch statement. |
| 997 | /// |
| 998 | /// By default, performs semantic analysis to build the new statement. |
| 999 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1000 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1001 | Expr *Cond, VarDecl *CondVar) { |
| 1002 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1003 | CondVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1006 | /// \brief Attach the body to the switch statement. |
| 1007 | /// |
| 1008 | /// By default, performs semantic analysis to build the new statement. |
| 1009 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1010 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1011 | Stmt *Switch, Stmt *Body) { |
| 1012 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /// \brief Build a new while statement. |
| 1016 | /// |
| 1017 | /// By default, performs semantic analysis to build the new statement. |
| 1018 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1019 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 1020 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1021 | VarDecl *CondVar, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1022 | Stmt *Body) { |
| 1023 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1024 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1026 | /// \brief Build a new do-while statement. |
| 1027 | /// |
| 1028 | /// By default, performs semantic analysis to build the new statement. |
| 1029 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1030 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1031 | SourceLocation WhileLoc, |
| 1032 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1033 | Expr *Cond, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1034 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1035 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1036 | Cond, RParenLoc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | /// \brief Build a new for statement. |
| 1040 | /// |
| 1041 | /// By default, performs semantic analysis to build the new statement. |
| 1042 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1043 | StmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1044 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1045 | Stmt *Init, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1046 | VarDecl *CondVar, Sema::FullExprArg Inc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1047 | SourceLocation RParenLoc, Stmt *Body) { |
| 1048 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1049 | CondVar, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1050 | Inc, RParenLoc, Body); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1051 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1053 | /// \brief Build a new goto statement. |
| 1054 | /// |
| 1055 | /// By default, performs semantic analysis to build the new statement. |
| 1056 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1057 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1058 | SourceLocation LabelLoc, |
| 1059 | LabelStmt *Label) { |
| 1060 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 1061 | } |
| 1062 | |
| 1063 | /// \brief Build a new indirect goto statement. |
| 1064 | /// |
| 1065 | /// By default, performs semantic analysis to build the new statement. |
| 1066 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1067 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | SourceLocation StarLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1069 | Expr *Target) { |
| 1070 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1073 | /// \brief Build a new return statement. |
| 1074 | /// |
| 1075 | /// By default, performs semantic analysis to build the new statement. |
| 1076 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1077 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1078 | Expr *Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1080 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1081 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1083 | /// \brief Build a new declaration statement. |
| 1084 | /// |
| 1085 | /// By default, performs semantic analysis to build the new statement. |
| 1086 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1087 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | SourceLocation EndLoc) { |
| 1090 | return getSema().Owned( |
| 1091 | new (getSema().Context) DeclStmt( |
| 1092 | DeclGroupRef::Create(getSema().Context, |
| 1093 | Decls, NumDecls), |
| 1094 | StartLoc, EndLoc)); |
| 1095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1097 | /// \brief Build a new inline asm statement. |
| 1098 | /// |
| 1099 | /// By default, performs semantic analysis to build the new statement. |
| 1100 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1101 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1102 | bool IsSimple, |
| 1103 | bool IsVolatile, |
| 1104 | unsigned NumOutputs, |
| 1105 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1106 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1107 | MultiExprArg Constraints, |
| 1108 | MultiExprArg Exprs, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1109 | Expr *AsmString, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1110 | MultiExprArg Clobbers, |
| 1111 | SourceLocation RParenLoc, |
| 1112 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1113 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1114 | NumInputs, Names, move(Constraints), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1115 | Exprs, AsmString, Clobbers, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1116 | RParenLoc, MSAsm); |
| 1117 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1118 | |
| 1119 | /// \brief Build a new Objective-C @try statement. |
| 1120 | /// |
| 1121 | /// By default, performs semantic analysis to build the new statement. |
| 1122 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1123 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1124 | Stmt *TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1125 | MultiStmtArg CatchStmts, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1126 | Stmt *Finally) { |
| 1127 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1128 | Finally); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1131 | /// \brief Rebuild an Objective-C exception declaration. |
| 1132 | /// |
| 1133 | /// By default, performs semantic analysis to build the new declaration. |
| 1134 | /// Subclasses may override this routine to provide different behavior. |
| 1135 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1136 | TypeSourceInfo *TInfo, QualType T) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1137 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1138 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1139 | ExceptionDecl->getLocation()); |
| 1140 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1142 | /// \brief Build a new Objective-C @catch statement. |
| 1143 | /// |
| 1144 | /// By default, performs semantic analysis to build the new statement. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1146 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1147 | SourceLocation RParenLoc, |
| 1148 | VarDecl *Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1149 | Stmt *Body) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1150 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1151 | Var, Body); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1152 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1154 | /// \brief Build a new Objective-C @finally statement. |
| 1155 | /// |
| 1156 | /// By default, performs semantic analysis to build the new statement. |
| 1157 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1158 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1159 | Stmt *Body) { |
| 1160 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1161 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1163 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1164 | /// |
| 1165 | /// By default, performs semantic analysis to build the new statement. |
| 1166 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1167 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1168 | Expr *Operand) { |
| 1169 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1170 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1172 | /// \brief Build a new Objective-C @synchronized statement. |
| 1173 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1174 | /// By default, performs semantic analysis to build the new statement. |
| 1175 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1176 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1177 | Expr *Object, |
| 1178 | Stmt *Body) { |
| 1179 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, |
| 1180 | Body); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1181 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1182 | |
| 1183 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1184 | /// |
| 1185 | /// By default, performs semantic analysis to build the new statement. |
| 1186 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1187 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1188 | SourceLocation LParenLoc, |
| 1189 | Stmt *Element, |
| 1190 | Expr *Collection, |
| 1191 | SourceLocation RParenLoc, |
| 1192 | Stmt *Body) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1193 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1194 | Element, |
| 1195 | Collection, |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1196 | RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1197 | Body); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1198 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1199 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1200 | /// \brief Build a new C++ exception declaration. |
| 1201 | /// |
| 1202 | /// By default, performs semantic analysis to build the new decaration. |
| 1203 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1204 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1205 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1206 | IdentifierInfo *Name, |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1207 | SourceLocation Loc) { |
| 1208 | return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /// \brief Build a new C++ catch statement. |
| 1212 | /// |
| 1213 | /// By default, performs semantic analysis to build the new statement. |
| 1214 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1215 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1216 | VarDecl *ExceptionDecl, |
| 1217 | Stmt *Handler) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1218 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1219 | Handler)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1220 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1222 | /// \brief Build a new C++ try statement. |
| 1223 | /// |
| 1224 | /// By default, performs semantic analysis to build the new statement. |
| 1225 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1226 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1227 | Stmt *TryBlock, |
| 1228 | MultiStmtArg Handlers) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1229 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1230 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | /// \brief Build a new expression that references a declaration. |
| 1233 | /// |
| 1234 | /// By default, performs semantic analysis to build the new expression. |
| 1235 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1236 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1237 | LookupResult &R, |
| 1238 | bool RequiresADL) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1239 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | /// \brief Build a new expression that references a declaration. |
| 1244 | /// |
| 1245 | /// By default, performs semantic analysis to build the new expression. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1247 | ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1248 | SourceRange QualifierRange, |
| 1249 | ValueDecl *VD, |
| 1250 | const DeclarationNameInfo &NameInfo, |
| 1251 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1252 | CXXScopeSpec SS; |
| 1253 | SS.setScopeRep(Qualifier); |
| 1254 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1255 | |
| 1256 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1257 | |
| 1258 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1259 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | /// By default, performs semantic analysis to build the new expression. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1265 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1266 | SourceLocation RParen) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1267 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1270 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1271 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1272 | /// By default, performs semantic analysis to build the new expression. |
| 1273 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1274 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1275 | SourceLocation OperatorLoc, |
| 1276 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1277 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1278 | SourceRange QualifierRange, |
| 1279 | TypeSourceInfo *ScopeType, |
| 1280 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1281 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1282 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1283 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1284 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1286 | /// By default, performs semantic analysis to build the new expression. |
| 1287 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1288 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1289 | UnaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1290 | Expr *SubExpr) { |
| 1291 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1292 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1293 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1294 | /// \brief Build a new builtin offsetof expression. |
| 1295 | /// |
| 1296 | /// By default, performs semantic analysis to build the new expression. |
| 1297 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1298 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1299 | TypeSourceInfo *Type, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1300 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1301 | unsigned NumComponents, |
| 1302 | SourceLocation RParenLoc) { |
| 1303 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1304 | NumComponents, RParenLoc); |
| 1305 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1306 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | /// By default, performs semantic analysis to build the new expression. |
| 1310 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1311 | ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1312 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1314 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1318 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1319 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1320 | /// By default, performs semantic analysis to build the new expression. |
| 1321 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1322 | ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | bool isSizeOf, SourceRange R) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1324 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1325 | = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1327 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | return move(Result); |
| 1330 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// By default, performs semantic analysis to build the new expression. |
| 1335 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1336 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | SourceLocation LBracketLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1338 | Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | SourceLocation RBracketLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1340 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1341 | LBracketLoc, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | RBracketLoc); |
| 1343 | } |
| 1344 | |
| 1345 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | /// By default, performs semantic analysis to build the new expression. |
| 1348 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1349 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | MultiExprArg Args, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1351 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1352 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Douglas Gregor | a1a0478 | 2010-09-09 16:33:13 +0000 | [diff] [blame] | 1353 | move(Args), RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | /// By default, performs semantic analysis to build the new expression. |
| 1359 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1360 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1361 | bool isArrow, |
| 1362 | NestedNameSpecifier *Qualifier, |
| 1363 | SourceRange QualifierRange, |
| 1364 | const DeclarationNameInfo &MemberNameInfo, |
| 1365 | ValueDecl *Member, |
| 1366 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1367 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1368 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1369 | if (!Member->getDeclName()) { |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1370 | // We have a reference to an unnamed field. This is always the |
| 1371 | // base of an anonymous struct/union member access, i.e. the |
| 1372 | // field is always of record type. |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1373 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1374 | assert(Member->getType()->isRecordType() && |
| 1375 | "unnamed member not of record type?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1377 | if (getSema().PerformObjectMemberConversion(Base, Qualifier, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1378 | FoundDecl, Member)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1379 | return ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1380 | |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1381 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | MemberExpr *ME = |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1383 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1384 | Member, MemberNameInfo, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1385 | cast<FieldDecl>(Member)->getType(), |
| 1386 | VK, OK_Ordinary); |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1387 | return getSema().Owned(ME); |
| 1388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1390 | CXXScopeSpec SS; |
| 1391 | if (Qualifier) { |
| 1392 | SS.setRange(QualifierRange); |
| 1393 | SS.setScopeRep(Qualifier); |
| 1394 | } |
| 1395 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1396 | getSema().DefaultFunctionArrayConversion(Base); |
| 1397 | QualType BaseType = Base->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1398 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1399 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1400 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1401 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1402 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1403 | R.resolveKind(); |
| 1404 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1405 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1406 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1407 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | /// By default, performs semantic analysis to build the new expression. |
| 1413 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1414 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1415 | BinaryOperatorKind Opc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1416 | Expr *LHS, Expr *RHS) { |
| 1417 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1422 | /// By default, performs semantic analysis to build the new expression. |
| 1423 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1424 | ExprResult RebuildConditionalOperator(Expr *Cond, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | SourceLocation QuestionLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1426 | Expr *LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1427 | SourceLocation ColonLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1428 | Expr *RHS) { |
| 1429 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1430 | LHS, RHS); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1433 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1435 | /// By default, performs semantic analysis to build the new expression. |
| 1436 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1437 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1438 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1439 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1440 | Expr *SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1441 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1442 | SubExpr); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1445 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | /// By default, performs semantic analysis to build the new expression. |
| 1448 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1449 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1450 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | SourceLocation RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1452 | Expr *Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1453 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1454 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1458 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1459 | /// By default, performs semantic analysis to build the new expression. |
| 1460 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1461 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | SourceLocation OpLoc, |
| 1463 | SourceLocation AccessorLoc, |
| 1464 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1465 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1466 | CXXScopeSpec SS; |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1467 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1468 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1469 | OpLoc, /*IsArrow*/ false, |
| 1470 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1471 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1472 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1473 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1476 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1479 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1481 | SourceLocation RBraceLoc, |
| 1482 | QualType ResultTy) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1483 | ExprResult Result |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1484 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1485 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1486 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1487 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1488 | // Patch in the result type we were given, which may have been computed |
| 1489 | // when the initial InitListExpr was built. |
| 1490 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1491 | ILE->setType(ResultTy); |
| 1492 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1496 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1497 | /// By default, performs semantic analysis to build the new expression. |
| 1498 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1499 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | MultiExprArg ArrayExprs, |
| 1501 | SourceLocation EqualOrColonLoc, |
| 1502 | bool GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1503 | Expr *Init) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1504 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1505 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1506 | Init); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1508 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1509 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1510 | ArrayExprs.release(); |
| 1511 | return move(Result); |
| 1512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | /// \brief Build a new value-initialized expression. |
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 | /// By default, builds the implicit value initialization without performing |
| 1517 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1518 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1519 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1520 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1521 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1522 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1523 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | /// By default, performs semantic analysis to build the new expression. |
| 1526 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1527 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1528 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1529 | SourceLocation RParenLoc) { |
| 1530 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1531 | SubExpr, TInfo, |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1532 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | /// By default, performs semantic analysis to build the new expression. |
| 1538 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1539 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1540 | MultiExprArg SubExprs, |
| 1541 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1542 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1543 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1547 | /// |
| 1548 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | /// rather than attempting to map the label statement itself. |
| 1550 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1551 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | SourceLocation LabelLoc, |
| 1553 | LabelStmt *Label) { |
| 1554 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1555 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | /// \brief Build a new GNU statement expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1560 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1561 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1562 | Stmt *SubStmt, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1563 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1564 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1566 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1567 | /// \brief Build a new __builtin_choose_expr expression. |
| 1568 | /// |
| 1569 | /// By default, performs semantic analysis to build the new expression. |
| 1570 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1571 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1572 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1573 | SourceLocation RParenLoc) { |
| 1574 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1575 | Cond, LHS, RHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1576 | RParenLoc); |
| 1577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | /// \brief Build a new overloaded operator call expression. |
| 1580 | /// |
| 1581 | /// By default, performs semantic analysis to build the new expression. |
| 1582 | /// The semantic analysis provides the behavior of template instantiation, |
| 1583 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1584 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1586 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1587 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1588 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1589 | Expr *Callee, |
| 1590 | Expr *First, |
| 1591 | Expr *Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | |
| 1593 | /// \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] | 1594 | /// reinterpret_cast. |
| 1595 | /// |
| 1596 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1597 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1598 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1599 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | Stmt::StmtClass Class, |
| 1601 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1602 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | SourceLocation RAngleLoc, |
| 1604 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1605 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | SourceLocation RParenLoc) { |
| 1607 | switch (Class) { |
| 1608 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1609 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1611 | SubExpr, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | |
| 1613 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1614 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1616 | SubExpr, RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1618 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1619 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1621 | SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1624 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1625 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1626 | RAngleLoc, LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1627 | SubExpr, RParenLoc); |
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 | default: |
| 1630 | assert(false && "Invalid C++ named cast"); |
| 1631 | break; |
| 1632 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1634 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1636 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | /// \brief Build a new C++ static_cast expression. |
| 1638 | /// |
| 1639 | /// By default, performs semantic analysis to build the new expression. |
| 1640 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1641 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1642 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1643 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | SourceLocation RAngleLoc, |
| 1645 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1646 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1648 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1649 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1650 | SourceRange(LAngleLoc, RAngleLoc), |
| 1651 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | /// \brief Build a new C++ dynamic_cast expression. |
| 1655 | /// |
| 1656 | /// By default, performs semantic analysis to build the new expression. |
| 1657 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1658 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1659 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1660 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | SourceLocation RAngleLoc, |
| 1662 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1663 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1664 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1665 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1666 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1667 | SourceRange(LAngleLoc, RAngleLoc), |
| 1668 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1672 | /// |
| 1673 | /// By default, performs semantic analysis to build the new expression. |
| 1674 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1675 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1676 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1677 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | SourceLocation RAngleLoc, |
| 1679 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1680 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1682 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1683 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1684 | SourceRange(LAngleLoc, RAngleLoc), |
| 1685 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /// \brief Build a new C++ const_cast expression. |
| 1689 | /// |
| 1690 | /// By default, performs semantic analysis to build the new expression. |
| 1691 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1692 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1694 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | SourceLocation RAngleLoc, |
| 1696 | SourceLocation LParenLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1697 | Expr *SubExpr, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1699 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1700 | TInfo, SubExpr, |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1701 | SourceRange(LAngleLoc, RAngleLoc), |
| 1702 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1705 | /// \brief Build a new C++ functional-style cast expression. |
| 1706 | /// |
| 1707 | /// By default, performs semantic analysis to build the new expression. |
| 1708 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1709 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1710 | SourceLocation LParenLoc, |
| 1711 | Expr *Sub, |
| 1712 | SourceLocation RParenLoc) { |
| 1713 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1714 | MultiExprArg(&Sub, 1), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1715 | RParenLoc); |
| 1716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | /// \brief Build a new C++ typeid(type) expression. |
| 1719 | /// |
| 1720 | /// By default, performs semantic analysis to build the new expression. |
| 1721 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1722 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1723 | SourceLocation TypeidLoc, |
| 1724 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1725 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1726 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1727 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1730 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1731 | /// \brief Build a new C++ typeid(expr) expression. |
| 1732 | /// |
| 1733 | /// By default, performs semantic analysis to build the new expression. |
| 1734 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1735 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1736 | SourceLocation TypeidLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1737 | Expr *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1738 | SourceLocation RParenLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1739 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1740 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1743 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1744 | /// |
| 1745 | /// By default, performs semantic analysis to build the new expression. |
| 1746 | /// Subclasses may override this routine to provide different behavior. |
| 1747 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1748 | SourceLocation TypeidLoc, |
| 1749 | TypeSourceInfo *Operand, |
| 1750 | SourceLocation RParenLoc) { |
| 1751 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1752 | RParenLoc); |
| 1753 | } |
| 1754 | |
| 1755 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1756 | /// |
| 1757 | /// By default, performs semantic analysis to build the new expression. |
| 1758 | /// Subclasses may override this routine to provide different behavior. |
| 1759 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1760 | SourceLocation TypeidLoc, |
| 1761 | Expr *Operand, |
| 1762 | SourceLocation RParenLoc) { |
| 1763 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1764 | RParenLoc); |
| 1765 | } |
| 1766 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | /// \brief Build a new C++ "this" expression. |
| 1768 | /// |
| 1769 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1770 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1771 | /// different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1772 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1773 | QualType ThisType, |
| 1774 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1775 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1776 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1777 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | /// \brief Build a new C++ throw expression. |
| 1781 | /// |
| 1782 | /// By default, performs semantic analysis to build the new expression. |
| 1783 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1784 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1785 | return getSema().ActOnCXXThrow(ThrowLoc, Sub); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /// \brief Build a new C++ default-argument expression. |
| 1789 | /// |
| 1790 | /// By default, builds a new default-argument expression, which does not |
| 1791 | /// require any semantic analysis. Subclasses may override this routine to |
| 1792 | /// provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1793 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1794 | ParmVarDecl *Param) { |
| 1795 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1796 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | /// \brief Build a new C++ zero-initialization expression. |
| 1800 | /// |
| 1801 | /// By default, performs semantic analysis to build the new expression. |
| 1802 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1803 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1804 | SourceLocation LParenLoc, |
| 1805 | SourceLocation RParenLoc) { |
| 1806 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1808 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1809 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1811 | /// \brief Build a new C++ "new" expression. |
| 1812 | /// |
| 1813 | /// By default, performs semantic analysis to build the new expression. |
| 1814 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1815 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1816 | bool UseGlobal, |
| 1817 | SourceLocation PlacementLParen, |
| 1818 | MultiExprArg PlacementArgs, |
| 1819 | SourceLocation PlacementRParen, |
| 1820 | SourceRange TypeIdParens, |
| 1821 | QualType AllocatedType, |
| 1822 | TypeSourceInfo *AllocatedTypeInfo, |
| 1823 | Expr *ArraySize, |
| 1824 | SourceLocation ConstructorLParen, |
| 1825 | MultiExprArg ConstructorArgs, |
| 1826 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1827 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1828 | PlacementLParen, |
| 1829 | move(PlacementArgs), |
| 1830 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1831 | TypeIdParens, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1832 | AllocatedType, |
| 1833 | AllocatedTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1834 | ArraySize, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1835 | ConstructorLParen, |
| 1836 | move(ConstructorArgs), |
| 1837 | ConstructorRParen); |
| 1838 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1840 | /// \brief Build a new C++ "delete" expression. |
| 1841 | /// |
| 1842 | /// By default, performs semantic analysis to build the new expression. |
| 1843 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1844 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1845 | bool IsGlobalDelete, |
| 1846 | bool IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1847 | Expr *Operand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1848 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1849 | Operand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1850 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1852 | /// \brief Build a new unary type trait expression. |
| 1853 | /// |
| 1854 | /// By default, performs semantic analysis to build the new expression. |
| 1855 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1856 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1857 | SourceLocation StartLoc, |
| 1858 | TypeSourceInfo *T, |
| 1859 | SourceLocation RParenLoc) { |
| 1860 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1863 | /// \brief Build a new binary type trait expression. |
| 1864 | /// |
| 1865 | /// By default, performs semantic analysis to build the new expression. |
| 1866 | /// Subclasses may override this routine to provide different behavior. |
| 1867 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1868 | SourceLocation StartLoc, |
| 1869 | TypeSourceInfo *LhsT, |
| 1870 | TypeSourceInfo *RhsT, |
| 1871 | SourceLocation RParenLoc) { |
| 1872 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1873 | } |
| 1874 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1876 | /// expression. |
| 1877 | /// |
| 1878 | /// By default, performs semantic analysis to build the new expression. |
| 1879 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1880 | ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1881 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1882 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1883 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1884 | CXXScopeSpec SS; |
| 1885 | SS.setRange(QualifierRange); |
| 1886 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1887 | |
| 1888 | if (TemplateArgs) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1889 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1890 | *TemplateArgs); |
| 1891 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1892 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | /// \brief Build a new template-id expression. |
| 1896 | /// |
| 1897 | /// By default, performs semantic analysis to build the new expression. |
| 1898 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1899 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1900 | LookupResult &R, |
| 1901 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1902 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1903 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /// \brief Build a new object-construction expression. |
| 1907 | /// |
| 1908 | /// By default, performs semantic analysis to build the new expression. |
| 1909 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1910 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1911 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1912 | CXXConstructorDecl *Constructor, |
| 1913 | bool IsElidable, |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1914 | MultiExprArg Args, |
| 1915 | bool RequiresZeroInit, |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1916 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 1917 | SourceRange ParenRange) { |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1918 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1919 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1920 | ConvertedArgs)) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1921 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1922 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1923 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1924 | move_arg(ConvertedArgs), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1925 | RequiresZeroInit, ConstructKind, |
| 1926 | ParenRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | /// \brief Build a new object-construction expression. |
| 1930 | /// |
| 1931 | /// By default, performs semantic analysis to build the new expression. |
| 1932 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1933 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 1934 | SourceLocation LParenLoc, |
| 1935 | MultiExprArg Args, |
| 1936 | SourceLocation RParenLoc) { |
| 1937 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1938 | LParenLoc, |
| 1939 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | RParenLoc); |
| 1941 | } |
| 1942 | |
| 1943 | /// \brief Build a new object-construction expression. |
| 1944 | /// |
| 1945 | /// By default, performs semantic analysis to build the new expression. |
| 1946 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1947 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 1948 | SourceLocation LParenLoc, |
| 1949 | MultiExprArg Args, |
| 1950 | SourceLocation RParenLoc) { |
| 1951 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | LParenLoc, |
| 1953 | move(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1954 | RParenLoc); |
| 1955 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1956 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1957 | /// \brief Build a new member reference expression. |
| 1958 | /// |
| 1959 | /// By default, performs semantic analysis to build the new expression. |
| 1960 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1961 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1962 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1963 | bool IsArrow, |
| 1964 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1965 | NestedNameSpecifier *Qualifier, |
| 1966 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1967 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1968 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1969 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1970 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1971 | SS.setRange(QualifierRange); |
| 1972 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1973 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1974 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1975 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1976 | SS, FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1977 | MemberNameInfo, |
| 1978 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1981 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1982 | /// |
| 1983 | /// By default, performs semantic analysis to build the new expression. |
| 1984 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1985 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1986 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1987 | SourceLocation OperatorLoc, |
| 1988 | bool IsArrow, |
| 1989 | NestedNameSpecifier *Qualifier, |
| 1990 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1991 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1992 | LookupResult &R, |
| 1993 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1994 | CXXScopeSpec SS; |
| 1995 | SS.setRange(QualifierRange); |
| 1996 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1998 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1999 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2000 | SS, FirstQualifierInScope, |
| 2001 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2004 | /// \brief Build a new noexcept expression. |
| 2005 | /// |
| 2006 | /// By default, performs semantic analysis to build the new expression. |
| 2007 | /// Subclasses may override this routine to provide different behavior. |
| 2008 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2009 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2010 | } |
| 2011 | |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2012 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2013 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2014 | SourceLocation PackLoc, |
| 2015 | SourceLocation RParenLoc, |
| 2016 | unsigned Length) { |
| 2017 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2018 | OperatorLoc, Pack, PackLoc, |
| 2019 | RParenLoc, Length); |
| 2020 | } |
| 2021 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2022 | /// \brief Build a new Objective-C @encode expression. |
| 2023 | /// |
| 2024 | /// By default, performs semantic analysis to build the new expression. |
| 2025 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2026 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2027 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2028 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2029 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2030 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2032 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2033 | /// \brief Build a new Objective-C class message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2034 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2035 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2036 | SourceLocation SelectorLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2037 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2038 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2039 | MultiExprArg Args, |
| 2040 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2041 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2042 | ReceiverTypeInfo->getType(), |
| 2043 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2044 | Sel, Method, LBracLoc, SelectorLoc, |
| 2045 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | /// \brief Build a new Objective-C instance message. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2049 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2050 | Selector Sel, |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2051 | SourceLocation SelectorLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2052 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2053 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2054 | MultiExprArg Args, |
| 2055 | SourceLocation RBracLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2056 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2057 | Receiver->getType(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2058 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2059 | Sel, Method, LBracLoc, SelectorLoc, |
| 2060 | RBracLoc, move(Args)); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2063 | /// \brief Build a new Objective-C ivar reference expression. |
| 2064 | /// |
| 2065 | /// By default, performs semantic analysis to build the new expression. |
| 2066 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2067 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2068 | SourceLocation IvarLoc, |
| 2069 | bool IsArrow, bool IsFreeIvar) { |
| 2070 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2071 | CXXScopeSpec SS; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2072 | Expr *Base = BaseArg; |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2073 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2074 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2075 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2076 | /*FIME:*/IvarLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2077 | SS, 0, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2078 | false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2079 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2080 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2081 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2082 | if (Result.get()) |
| 2083 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2084 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2085 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2086 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2087 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2088 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2089 | /*TemplateArgs=*/0); |
| 2090 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2091 | |
| 2092 | /// \brief Build a new Objective-C property reference expression. |
| 2093 | /// |
| 2094 | /// By default, performs semantic analysis to build the new expression. |
| 2095 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2096 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2097 | ObjCPropertyDecl *Property, |
| 2098 | SourceLocation PropertyLoc) { |
| 2099 | CXXScopeSpec SS; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2100 | Expr *Base = BaseArg; |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2101 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2102 | Sema::LookupMemberName); |
| 2103 | bool IsArrow = false; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2104 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2105 | /*FIME:*/PropertyLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2106 | SS, 0, false); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2107 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2108 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2109 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2110 | if (Result.get()) |
| 2111 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2112 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2113 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2114 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2115 | SS, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2116 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2117 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2118 | /*TemplateArgs=*/0); |
| 2119 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2120 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2121 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2122 | /// |
| 2123 | /// By default, performs semantic analysis to build the new expression. |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2124 | /// Subclasses may override this routine to provide different behavior. |
| 2125 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2126 | ObjCMethodDecl *Getter, |
| 2127 | ObjCMethodDecl *Setter, |
| 2128 | SourceLocation PropertyLoc) { |
| 2129 | // Since these expressions can only be value-dependent, we do not |
| 2130 | // need to perform semantic analysis again. |
| 2131 | return Owned( |
| 2132 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2133 | VK_LValue, OK_ObjCProperty, |
| 2134 | PropertyLoc, Base)); |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2137 | /// \brief Build a new Objective-C "isa" expression. |
| 2138 | /// |
| 2139 | /// By default, performs semantic analysis to build the new expression. |
| 2140 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2141 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2142 | bool IsArrow) { |
| 2143 | CXXScopeSpec SS; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2144 | Expr *Base = BaseArg; |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2145 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2146 | Sema::LookupMemberName); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2147 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2148 | /*FIME:*/IsaLoc, |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2149 | SS, 0, false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2150 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2151 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2152 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2153 | if (Result.get()) |
| 2154 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2155 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2156 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2157 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2158 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2159 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2160 | /*TemplateArgs=*/0); |
| 2161 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2163 | /// \brief Build a new shuffle vector expression. |
| 2164 | /// |
| 2165 | /// By default, performs semantic analysis to build the new expression. |
| 2166 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2167 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2168 | MultiExprArg SubExprs, |
| 2169 | SourceLocation RParenLoc) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2170 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2172 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2173 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2174 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2175 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | // Build a reference to the __builtin_shufflevector builtin |
| 2178 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2179 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2180 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2181 | VK_LValue, BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2182 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | |
| 2184 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2185 | unsigned NumSubExprs = SubExprs.size(); |
| 2186 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2187 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 2188 | Subs, NumSubExprs, |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2189 | Builtin->getCallResultType(), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2190 | Expr::getValueKindForType(Builtin->getResultType()), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2191 | RParenLoc); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2192 | ExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2194 | // Type-check the __builtin_shufflevector expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2195 | ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2196 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2197 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2199 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2200 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2201 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2202 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2203 | /// \brief Build a new template argument pack expansion. |
| 2204 | /// |
| 2205 | /// By default, performs semantic analysis to build a new pack expansion |
| 2206 | /// for a template argument. Subclasses may override this routine to provide |
| 2207 | /// different behavior. |
| 2208 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2209 | SourceLocation EllipsisLoc, |
| 2210 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2211 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2212 | case TemplateArgument::Expression: { |
| 2213 | ExprResult Result |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2214 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2215 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 7a21fd4 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2216 | if (Result.isInvalid()) |
| 2217 | return TemplateArgumentLoc(); |
| 2218 | |
| 2219 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2220 | } |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2221 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2222 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2223 | return TemplateArgumentLoc(TemplateArgument( |
| 2224 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2225 | NumExpansions), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2226 | Pattern.getTemplateQualifierRange(), |
| 2227 | Pattern.getTemplateNameLoc(), |
| 2228 | EllipsisLoc); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2229 | |
| 2230 | case TemplateArgument::Null: |
| 2231 | case TemplateArgument::Integral: |
| 2232 | case TemplateArgument::Declaration: |
| 2233 | case TemplateArgument::Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2234 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2235 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2236 | |
| 2237 | case TemplateArgument::Type: |
| 2238 | if (TypeSourceInfo *Expansion |
| 2239 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2240 | EllipsisLoc, |
| 2241 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2242 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2243 | Expansion); |
| 2244 | break; |
| 2245 | } |
| 2246 | |
| 2247 | return TemplateArgumentLoc(); |
| 2248 | } |
| 2249 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2250 | /// \brief Build a new expression pack expansion. |
| 2251 | /// |
| 2252 | /// By default, performs semantic analysis to build a new pack expansion |
| 2253 | /// for an expression. Subclasses may override this routine to provide |
| 2254 | /// different behavior. |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2255 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2256 | llvm::Optional<unsigned> NumExpansions) { |
| 2257 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2260 | private: |
| 2261 | QualType TransformTypeInObjectScope(QualType T, |
| 2262 | QualType ObjectType, |
| 2263 | NamedDecl *FirstQualifierInScope, |
| 2264 | NestedNameSpecifier *Prefix); |
| 2265 | |
| 2266 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T, |
| 2267 | QualType ObjectType, |
| 2268 | NamedDecl *FirstQualifierInScope, |
| 2269 | NestedNameSpecifier *Prefix); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2270 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2271 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2272 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2273 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2274 | if (!S) |
| 2275 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2277 | switch (S->getStmtClass()) { |
| 2278 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2279 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2280 | // Transform individual statement nodes |
| 2281 | #define STMT(Node, Parent) \ |
| 2282 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 2283 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2284 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2285 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2286 | // Transform expressions by calling TransformExpr. |
| 2287 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2288 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2289 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2290 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2291 | { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2292 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2293 | if (E.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2294 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2295 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2296 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2297 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2300 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2302 | |
| 2303 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2304 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2305 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | if (!E) |
| 2307 | return SemaRef.Owned(E); |
| 2308 | |
| 2309 | switch (E->getStmtClass()) { |
| 2310 | case Stmt::NoStmtClass: break; |
| 2311 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2312 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2313 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2314 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2315 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2318 | return SemaRef.Owned(E); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | template<typename Derived> |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2322 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2323 | unsigned NumInputs, |
| 2324 | bool IsCall, |
| 2325 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 2326 | bool *ArgChanged) { |
| 2327 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2328 | // If requested, drop call arguments that need to be dropped. |
| 2329 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2330 | if (ArgChanged) |
| 2331 | *ArgChanged = true; |
| 2332 | |
| 2333 | break; |
| 2334 | } |
| 2335 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2336 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2337 | Expr *Pattern = Expansion->getPattern(); |
| 2338 | |
| 2339 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2340 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2341 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2342 | |
| 2343 | // Determine whether the set of unexpanded parameter packs can and should |
| 2344 | // be expanded. |
| 2345 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2346 | bool RetainExpansion = false; |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2347 | llvm::Optional<unsigned> OrigNumExpansions |
| 2348 | = Expansion->getNumExpansions(); |
| 2349 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2350 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2351 | Pattern->getSourceRange(), |
| 2352 | Unexpanded.data(), |
| 2353 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2354 | Expand, RetainExpansion, |
| 2355 | NumExpansions)) |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2356 | return true; |
| 2357 | |
| 2358 | if (!Expand) { |
| 2359 | // The transform has determined that we should perform a simple |
| 2360 | // transformation on the pack expansion, producing another pack |
| 2361 | // expansion. |
| 2362 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2363 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2364 | if (OutPattern.isInvalid()) |
| 2365 | return true; |
| 2366 | |
| 2367 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2368 | Expansion->getEllipsisLoc(), |
| 2369 | NumExpansions); |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2370 | if (Out.isInvalid()) |
| 2371 | return true; |
| 2372 | |
| 2373 | if (ArgChanged) |
| 2374 | *ArgChanged = true; |
| 2375 | Outputs.push_back(Out.get()); |
| 2376 | continue; |
| 2377 | } |
| 2378 | |
| 2379 | // The transform has determined that we should perform an elementwise |
| 2380 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2381 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2382 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2383 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2384 | if (Out.isInvalid()) |
| 2385 | return true; |
| 2386 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2387 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2388 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2389 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2390 | if (Out.isInvalid()) |
| 2391 | return true; |
| 2392 | } |
| 2393 | |
Douglas Gregor | dcaa1ca | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2394 | if (ArgChanged) |
| 2395 | *ArgChanged = true; |
| 2396 | Outputs.push_back(Out.get()); |
| 2397 | } |
| 2398 | |
| 2399 | continue; |
| 2400 | } |
| 2401 | |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2402 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2403 | if (Result.isInvalid()) |
| 2404 | return true; |
| 2405 | |
| 2406 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2407 | *ArgChanged = true; |
| 2408 | |
| 2409 | Outputs.push_back(Result.get()); |
| 2410 | } |
| 2411 | |
| 2412 | return false; |
| 2413 | } |
| 2414 | |
| 2415 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2416 | NestedNameSpecifier * |
| 2417 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2418 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2419 | QualType ObjectType, |
| 2420 | NamedDecl *FirstQualifierInScope) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2421 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2422 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2423 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2424 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2425 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2426 | ObjectType, |
| 2427 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2428 | if (!Prefix) |
| 2429 | return 0; |
| 2430 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2431 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2432 | switch (NNS->getKind()) { |
| 2433 | case NestedNameSpecifier::Identifier: |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2434 | if (Prefix) { |
| 2435 | // The object type and qualifier-in-scope really apply to the |
| 2436 | // leftmost entity. |
| 2437 | ObjectType = QualType(); |
| 2438 | FirstQualifierInScope = 0; |
| 2439 | } |
| 2440 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2441 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2442 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2443 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2444 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2445 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2446 | |
| 2447 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2448 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2449 | ObjectType, |
| 2450 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2451 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2452 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2453 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2454 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2455 | getDerived().TransformDecl(Range.getBegin(), |
| 2456 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2457 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2458 | Prefix == NNS->getPrefix() && |
| 2459 | NS == NNS->getAsNamespace()) |
| 2460 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2461 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2462 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2463 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2464 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2465 | case NestedNameSpecifier::Global: |
| 2466 | // There is no meaningful transformation that one could perform on the |
| 2467 | // global scope. |
| 2468 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2469 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2470 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2471 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2472 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2473 | QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0), |
| 2474 | ObjectType, |
| 2475 | FirstQualifierInScope, |
| 2476 | Prefix); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2477 | if (T.isNull()) |
| 2478 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2479 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2480 | if (!getDerived().AlwaysRebuild() && |
| 2481 | Prefix == NNS->getPrefix() && |
| 2482 | T == QualType(NNS->getAsType(), 0)) |
| 2483 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2484 | |
| 2485 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2486 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2487 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2488 | } |
| 2489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2490 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2491 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2492 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2496 | DeclarationNameInfo |
| 2497 | TreeTransform<Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2498 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2499 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2500 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2501 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2502 | |
| 2503 | switch (Name.getNameKind()) { |
| 2504 | case DeclarationName::Identifier: |
| 2505 | case DeclarationName::ObjCZeroArgSelector: |
| 2506 | case DeclarationName::ObjCOneArgSelector: |
| 2507 | case DeclarationName::ObjCMultiArgSelector: |
| 2508 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2509 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2510 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2511 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2512 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2513 | case DeclarationName::CXXConstructorName: |
| 2514 | case DeclarationName::CXXDestructorName: |
| 2515 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2516 | TypeSourceInfo *NewTInfo; |
| 2517 | CanQualType NewCanTy; |
| 2518 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2519 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2520 | if (!NewTInfo) |
| 2521 | return DeclarationNameInfo(); |
| 2522 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2523 | } |
| 2524 | else { |
| 2525 | NewTInfo = 0; |
| 2526 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2527 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2528 | if (NewT.isNull()) |
| 2529 | return DeclarationNameInfo(); |
| 2530 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2531 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2532 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2533 | DeclarationName NewName |
| 2534 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2535 | NewCanTy); |
| 2536 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2537 | NewNameInfo.setName(NewName); |
| 2538 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2539 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2540 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2543 | assert(0 && "Unknown name kind."); |
| 2544 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2548 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2549 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2550 | QualType ObjectType, |
| 2551 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2552 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2553 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2554 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2555 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2556 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2557 | /*FIXME*/ SourceRange(Loc), |
| 2558 | ObjectType, |
| 2559 | FirstQualifierInScope); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2560 | if (!NNS) |
| 2561 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2562 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2563 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2564 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2565 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2566 | if (!TransTemplate) |
| 2567 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2568 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2569 | if (!getDerived().AlwaysRebuild() && |
| 2570 | NNS == QTN->getQualifier() && |
| 2571 | TransTemplate == Template) |
| 2572 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2573 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2574 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2575 | TransTemplate); |
| 2576 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2577 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2578 | // 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] | 2579 | llvm_unreachable("overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2580 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2582 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2583 | NestedNameSpecifier *NNS = DTN->getQualifier(); |
| 2584 | if (NNS) { |
| 2585 | NNS = getDerived().TransformNestedNameSpecifier(NNS, |
| 2586 | /*FIXME:*/SourceRange(Loc), |
| 2587 | ObjectType, |
| 2588 | FirstQualifierInScope); |
| 2589 | if (!NNS) return TemplateName(); |
| 2590 | |
| 2591 | // These apply to the scope specifier, not the template. |
| 2592 | ObjectType = QualType(); |
| 2593 | FirstQualifierInScope = 0; |
| 2594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2595 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2596 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2597 | NNS == DTN->getQualifier() && |
| 2598 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2599 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2600 | |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2601 | if (DTN->isIdentifier()) { |
| 2602 | // FIXME: Bad range |
| 2603 | SourceRange QualifierRange(getDerived().getBaseLocation()); |
| 2604 | return getDerived().RebuildTemplateName(NNS, QualifierRange, |
| 2605 | *DTN->getIdentifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2606 | ObjectType, |
| 2607 | FirstQualifierInScope); |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2608 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2609 | |
| 2610 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2611 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2613 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2614 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2615 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2616 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2617 | if (!TransTemplate) |
| 2618 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2620 | if (!getDerived().AlwaysRebuild() && |
| 2621 | TransTemplate == Template) |
| 2622 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2624 | return TemplateName(TransTemplate); |
| 2625 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2626 | |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 2627 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2628 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2629 | TemplateTemplateParmDecl *TransParam |
| 2630 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2631 | getDerived().TransformDecl(Loc, SubstPack->getParameterPack())); |
| 2632 | if (!TransParam) |
| 2633 | return TemplateName(); |
| 2634 | |
| 2635 | if (!getDerived().AlwaysRebuild() && |
| 2636 | TransParam == SubstPack->getParameterPack()) |
| 2637 | return Name; |
| 2638 | |
| 2639 | return getDerived().RebuildTemplateName(TransParam, |
| 2640 | SubstPack->getArgumentPack()); |
| 2641 | } |
| 2642 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2643 | // These should be getting filtered out before they reach the AST. |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2644 | llvm_unreachable("overloaded function decl survived to here"); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2645 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2649 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2650 | const TemplateArgument &Arg, |
| 2651 | TemplateArgumentLoc &Output) { |
| 2652 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2653 | switch (Arg.getKind()) { |
| 2654 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2655 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2656 | break; |
| 2657 | |
| 2658 | case TemplateArgument::Type: |
| 2659 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2660 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2661 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2662 | break; |
| 2663 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2664 | case TemplateArgument::Template: |
| 2665 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2666 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2667 | |
| 2668 | case TemplateArgument::TemplateExpansion: |
| 2669 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc); |
| 2670 | break; |
| 2671 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2672 | case TemplateArgument::Expression: |
| 2673 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2674 | break; |
| 2675 | |
| 2676 | case TemplateArgument::Declaration: |
| 2677 | case TemplateArgument::Integral: |
| 2678 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2679 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | template<typename Derived> |
| 2685 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2686 | const TemplateArgumentLoc &Input, |
| 2687 | TemplateArgumentLoc &Output) { |
| 2688 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2689 | switch (Arg.getKind()) { |
| 2690 | case TemplateArgument::Null: |
| 2691 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2692 | Output = Input; |
| 2693 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2694 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2695 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2696 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2697 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2698 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2699 | |
| 2700 | DI = getDerived().TransformType(DI); |
| 2701 | if (!DI) return true; |
| 2702 | |
| 2703 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2704 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2705 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2706 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2707 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2708 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2709 | DeclarationName Name; |
| 2710 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2711 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2712 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2713 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2714 | if (!D) return true; |
| 2715 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2716 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2717 | if (SourceExpr) { |
| 2718 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2719 | Sema::Unevaluated); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2720 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2721 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2725 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2726 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2727 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2728 | case TemplateArgument::Template: { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2729 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2730 | TemplateName Template |
| 2731 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2732 | if (Template.isNull()) |
| 2733 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2734 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2735 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2736 | Input.getTemplateQualifierRange(), |
| 2737 | Input.getTemplateNameLoc()); |
| 2738 | return false; |
| 2739 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2740 | |
| 2741 | case TemplateArgument::TemplateExpansion: |
| 2742 | llvm_unreachable("Caller should expand pack expansions"); |
| 2743 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2744 | case TemplateArgument::Expression: { |
| 2745 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2746 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2747 | Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2749 | Expr *InputExpr = Input.getSourceExpression(); |
| 2750 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2751 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2752 | ExprResult E |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2753 | = getDerived().TransformExpr(InputExpr); |
| 2754 | if (E.isInvalid()) return true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2755 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2756 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2758 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2759 | case TemplateArgument::Pack: { |
| 2760 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2761 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2762 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2763 | AEnd = Arg.pack_end(); |
| 2764 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2766 | // FIXME: preserve source information here when we start |
| 2767 | // caring about parameter packs. |
| 2768 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2769 | TemplateArgumentLoc InputArg; |
| 2770 | TemplateArgumentLoc OutputArg; |
| 2771 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2772 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2773 | return true; |
| 2774 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2775 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2776 | } |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2777 | |
| 2778 | TemplateArgument *TransformedArgsPtr |
| 2779 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2780 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2781 | TransformedArgsPtr); |
| 2782 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2783 | TransformedArgs.size()), |
| 2784 | Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2785 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2786 | } |
| 2787 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2788 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2789 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2790 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2793 | /// \brief Iterator adaptor that invents template argument location information |
| 2794 | /// for each of the template arguments in its underlying iterator. |
| 2795 | template<typename Derived, typename InputIterator> |
| 2796 | class TemplateArgumentLocInventIterator { |
| 2797 | TreeTransform<Derived> &Self; |
| 2798 | InputIterator Iter; |
| 2799 | |
| 2800 | public: |
| 2801 | typedef TemplateArgumentLoc value_type; |
| 2802 | typedef TemplateArgumentLoc reference; |
| 2803 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2804 | difference_type; |
| 2805 | typedef std::input_iterator_tag iterator_category; |
| 2806 | |
| 2807 | class pointer { |
| 2808 | TemplateArgumentLoc Arg; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2809 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2810 | public: |
| 2811 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2812 | |
| 2813 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2814 | }; |
| 2815 | |
| 2816 | TemplateArgumentLocInventIterator() { } |
| 2817 | |
| 2818 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2819 | InputIterator Iter) |
| 2820 | : Self(Self), Iter(Iter) { } |
| 2821 | |
| 2822 | TemplateArgumentLocInventIterator &operator++() { |
| 2823 | ++Iter; |
| 2824 | return *this; |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2827 | TemplateArgumentLocInventIterator operator++(int) { |
| 2828 | TemplateArgumentLocInventIterator Old(*this); |
| 2829 | ++(*this); |
| 2830 | return Old; |
| 2831 | } |
| 2832 | |
| 2833 | reference operator*() const { |
| 2834 | TemplateArgumentLoc Result; |
| 2835 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 2836 | return Result; |
| 2837 | } |
| 2838 | |
| 2839 | pointer operator->() const { return pointer(**this); } |
| 2840 | |
| 2841 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 2842 | const TemplateArgumentLocInventIterator &Y) { |
| 2843 | return X.Iter == Y.Iter; |
| 2844 | } |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2845 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2846 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 2847 | const TemplateArgumentLocInventIterator &Y) { |
| 2848 | return X.Iter != Y.Iter; |
| 2849 | } |
| 2850 | }; |
| 2851 | |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2852 | template<typename Derived> |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2853 | template<typename InputIterator> |
| 2854 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 2855 | InputIterator Last, |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2856 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2857 | for (; First != Last; ++First) { |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2858 | TemplateArgumentLoc Out; |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2859 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2860 | |
| 2861 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 2862 | // Unpack argument packs, which we translate them into separate |
| 2863 | // arguments. |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2864 | // FIXME: We could do much better if we could guarantee that the |
| 2865 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 2866 | // all of the template arguments in the argument pack. |
| 2867 | typedef TemplateArgumentLocInventIterator<Derived, |
| 2868 | TemplateArgument::pack_iterator> |
| 2869 | PackLocIterator; |
| 2870 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 2871 | In.getArgument().pack_begin()), |
| 2872 | PackLocIterator(*this, |
| 2873 | In.getArgument().pack_end()), |
| 2874 | Outputs)) |
| 2875 | return true; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2876 | |
| 2877 | continue; |
| 2878 | } |
| 2879 | |
| 2880 | if (In.getArgument().isPackExpansion()) { |
| 2881 | // We have a pack expansion, for which we will be substituting into |
| 2882 | // the pattern. |
| 2883 | SourceLocation Ellipsis; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2884 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2885 | TemplateArgumentLoc Pattern |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2886 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 2887 | getSema().Context); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2888 | |
| 2889 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2890 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2891 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2892 | |
| 2893 | // Determine whether the set of unexpanded parameter packs can and should |
| 2894 | // be expanded. |
| 2895 | bool Expand = true; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2896 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2897 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2898 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 2899 | Pattern.getSourceRange(), |
| 2900 | Unexpanded.data(), |
| 2901 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2902 | Expand, |
| 2903 | RetainExpansion, |
| 2904 | NumExpansions)) |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2905 | return true; |
| 2906 | |
| 2907 | if (!Expand) { |
| 2908 | // The transform has determined that we should perform a simple |
| 2909 | // transformation on the pack expansion, producing another pack |
| 2910 | // expansion. |
| 2911 | TemplateArgumentLoc OutPattern; |
| 2912 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2913 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 2914 | return true; |
| 2915 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2916 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 2917 | NumExpansions); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2918 | if (Out.getArgument().isNull()) |
| 2919 | return true; |
| 2920 | |
| 2921 | Outputs.addArgument(Out); |
| 2922 | continue; |
| 2923 | } |
| 2924 | |
| 2925 | // The transform has determined that we should perform an elementwise |
| 2926 | // expansion of the pattern. Do so. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2927 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2928 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2929 | |
| 2930 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 2931 | return true; |
| 2932 | |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2933 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2934 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 2935 | OrigNumExpansions); |
Douglas Gregor | 77d6bb9 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2936 | if (Out.getArgument().isNull()) |
| 2937 | return true; |
| 2938 | } |
| 2939 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2940 | Outputs.addArgument(Out); |
| 2941 | } |
| 2942 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 2943 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 2944 | // forgetting the partially-substituted parameter pack. |
| 2945 | if (RetainExpansion) { |
| 2946 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 2947 | |
| 2948 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 2949 | return true; |
| 2950 | |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2951 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 2952 | OrigNumExpansions); |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 2953 | if (Out.getArgument().isNull()) |
| 2954 | return true; |
| 2955 | |
| 2956 | Outputs.addArgument(Out); |
| 2957 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2958 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2959 | continue; |
| 2960 | } |
| 2961 | |
| 2962 | // The simple case: |
| 2963 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2964 | return true; |
| 2965 | |
| 2966 | Outputs.addArgument(Out); |
| 2967 | } |
| 2968 | |
| 2969 | return false; |
| 2970 | |
| 2971 | } |
| 2972 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2973 | //===----------------------------------------------------------------------===// |
| 2974 | // Type transformation |
| 2975 | //===----------------------------------------------------------------------===// |
| 2976 | |
| 2977 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2978 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2979 | if (getDerived().AlreadyTransformed(T)) |
| 2980 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2981 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2982 | // Temporary workaround. All of these transformations should |
| 2983 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 2984 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 2985 | getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2986 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2987 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2988 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2989 | if (!NewDI) |
| 2990 | return QualType(); |
| 2991 | |
| 2992 | return NewDI->getType(); |
| 2993 | } |
| 2994 | |
| 2995 | template<typename Derived> |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2996 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2997 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2998 | return DI; |
| 2999 | |
| 3000 | TypeLocBuilder TLB; |
| 3001 | |
| 3002 | TypeLoc TL = DI->getTypeLoc(); |
| 3003 | TLB.reserve(TL.getFullDataSize()); |
| 3004 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3005 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3006 | if (Result.isNull()) |
| 3007 | return 0; |
| 3008 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3009 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | template<typename Derived> |
| 3013 | QualType |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3014 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3015 | switch (T.getTypeLocClass()) { |
| 3016 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3017 | #define TYPELOC(CLASS, PARENT) \ |
| 3018 | case TypeLoc::CLASS: \ |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3019 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3020 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3023 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3024 | return QualType(); |
| 3025 | } |
| 3026 | |
| 3027 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3028 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3029 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3030 | /// types). This is the right thing for template instantiation, but |
| 3031 | /// probably not for other clients. |
| 3032 | template<typename Derived> |
| 3033 | QualType |
| 3034 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3035 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3036 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3037 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3038 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3039 | if (Result.isNull()) |
| 3040 | return QualType(); |
| 3041 | |
| 3042 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3043 | // FIXME: this is the right thing for template instantiation, but |
| 3044 | // probably not for other clients. |
| 3045 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3046 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 | |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3048 | if (!Quals.empty()) { |
| 3049 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3050 | TLB.push<QualifiedTypeLoc>(Result); |
| 3051 | // No location information to preserve. |
| 3052 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3053 | |
| 3054 | return Result; |
| 3055 | } |
| 3056 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3057 | /// \brief Transforms a type that was written in a scope specifier, |
| 3058 | /// given an object type, the results of unqualified lookup, and |
| 3059 | /// an already-instantiated prefix. |
| 3060 | /// |
| 3061 | /// The object type is provided iff the scope specifier qualifies the |
| 3062 | /// member of a dependent member-access expression. The prefix is |
| 3063 | /// provided iff the the scope specifier in which this appears has a |
| 3064 | /// prefix. |
| 3065 | /// |
| 3066 | /// This is private to TreeTransform. |
| 3067 | template<typename Derived> |
| 3068 | QualType |
| 3069 | TreeTransform<Derived>::TransformTypeInObjectScope(QualType T, |
| 3070 | QualType ObjectType, |
| 3071 | NamedDecl *UnqualLookup, |
| 3072 | NestedNameSpecifier *Prefix) { |
| 3073 | if (getDerived().AlreadyTransformed(T)) |
| 3074 | return T; |
| 3075 | |
| 3076 | TypeSourceInfo *TSI = |
Douglas Gregor | c21c7e9 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3077 | SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation()); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3078 | |
| 3079 | TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType, |
| 3080 | UnqualLookup, Prefix); |
| 3081 | if (!TSI) return QualType(); |
| 3082 | return TSI->getType(); |
| 3083 | } |
| 3084 | |
| 3085 | template<typename Derived> |
| 3086 | TypeSourceInfo * |
| 3087 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI, |
| 3088 | QualType ObjectType, |
| 3089 | NamedDecl *UnqualLookup, |
| 3090 | NestedNameSpecifier *Prefix) { |
| 3091 | // TODO: in some cases, we might be some verification to do here. |
| 3092 | if (ObjectType.isNull()) |
| 3093 | return getDerived().TransformType(TSI); |
| 3094 | |
| 3095 | QualType T = TSI->getType(); |
| 3096 | if (getDerived().AlreadyTransformed(T)) |
| 3097 | return TSI; |
| 3098 | |
| 3099 | TypeLocBuilder TLB; |
| 3100 | QualType Result; |
| 3101 | |
| 3102 | if (isa<TemplateSpecializationType>(T)) { |
| 3103 | TemplateSpecializationTypeLoc TL |
| 3104 | = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3105 | |
| 3106 | TemplateName Template = |
| 3107 | getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(), |
| 3108 | ObjectType, UnqualLookup); |
| 3109 | if (Template.isNull()) return 0; |
| 3110 | |
| 3111 | Result = getDerived() |
| 3112 | .TransformTemplateSpecializationType(TLB, TL, Template); |
| 3113 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3114 | DependentTemplateSpecializationTypeLoc TL |
| 3115 | = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3116 | |
| 3117 | Result = getDerived() |
| 3118 | .TransformDependentTemplateSpecializationType(TLB, TL, Prefix); |
| 3119 | } else { |
| 3120 | // Nothing special needs to be done for these. |
| 3121 | Result = getDerived().TransformType(TLB, TSI->getTypeLoc()); |
| 3122 | } |
| 3123 | |
| 3124 | if (Result.isNull()) return 0; |
| 3125 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3126 | } |
| 3127 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3128 | template <class TyLoc> static inline |
| 3129 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3130 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3131 | NewT.setNameLoc(T.getNameLoc()); |
| 3132 | return T.getType(); |
| 3133 | } |
| 3134 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3135 | template<typename Derived> |
| 3136 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3137 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3138 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3139 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3140 | if (T.needsExtraLocalData()) |
| 3141 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3142 | return T.getType(); |
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>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3147 | ComplexTypeLoc T) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3148 | // FIXME: recurse? |
| 3149 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3151 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3152 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3153 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3154 | PointerTypeLoc TL) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3155 | QualType PointeeType |
| 3156 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3157 | if (PointeeType.isNull()) |
| 3158 | return QualType(); |
| 3159 | |
| 3160 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3161 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3162 | // A dependent pointer type 'T *' has is being transformed such |
| 3163 | // that an Objective-C class type is being replaced for 'T'. The |
| 3164 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3165 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3166 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3167 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3168 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3169 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3170 | return Result; |
| 3171 | } |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3172 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3173 | if (getDerived().AlwaysRebuild() || |
| 3174 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3175 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3176 | if (Result.isNull()) |
| 3177 | return QualType(); |
| 3178 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3179 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3180 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3181 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3182 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3184 | |
| 3185 | template<typename Derived> |
| 3186 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3187 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3188 | BlockPointerTypeLoc TL) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3189 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3190 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3191 | if (PointeeType.isNull()) |
| 3192 | return QualType(); |
| 3193 | |
| 3194 | QualType Result = TL.getType(); |
| 3195 | if (getDerived().AlwaysRebuild() || |
| 3196 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3197 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3198 | TL.getSigilLoc()); |
| 3199 | if (Result.isNull()) |
| 3200 | return QualType(); |
| 3201 | } |
| 3202 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3203 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3204 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3205 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3208 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3209 | /// don't care whether the type itself is an l-value type or an r-value |
| 3210 | /// type; we only care if the type was *written* as an l-value type |
| 3211 | /// or an r-value type. |
| 3212 | template<typename Derived> |
| 3213 | QualType |
| 3214 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3215 | ReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3216 | const ReferenceType *T = TL.getTypePtr(); |
| 3217 | |
| 3218 | // Note that this works with the pointee-as-written. |
| 3219 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3220 | if (PointeeType.isNull()) |
| 3221 | return QualType(); |
| 3222 | |
| 3223 | QualType Result = TL.getType(); |
| 3224 | if (getDerived().AlwaysRebuild() || |
| 3225 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3226 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3227 | T->isSpelledAsLValue(), |
| 3228 | TL.getSigilLoc()); |
| 3229 | if (Result.isNull()) |
| 3230 | return QualType(); |
| 3231 | } |
| 3232 | |
| 3233 | // r-value references can be rebuilt as l-value references. |
| 3234 | ReferenceTypeLoc NewTL; |
| 3235 | if (isa<LValueReferenceType>(Result)) |
| 3236 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3237 | else |
| 3238 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3239 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3240 | |
| 3241 | return Result; |
| 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>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3247 | LValueReferenceTypeLoc TL) { |
| 3248 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3251 | template<typename Derived> |
| 3252 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3253 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3254 | RValueReferenceTypeLoc TL) { |
| 3255 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3258 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3259 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3260 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3261 | MemberPointerTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3262 | const MemberPointerType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3263 | |
| 3264 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3265 | if (PointeeType.isNull()) |
| 3266 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3268 | // TODO: preserve source information for this. |
| 3269 | QualType ClassType |
| 3270 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3271 | if (ClassType.isNull()) |
| 3272 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3274 | QualType Result = TL.getType(); |
| 3275 | if (getDerived().AlwaysRebuild() || |
| 3276 | PointeeType != T->getPointeeType() || |
| 3277 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3278 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 3279 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3280 | if (Result.isNull()) |
| 3281 | return QualType(); |
| 3282 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3283 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3284 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3285 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3286 | |
| 3287 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | template<typename Derived> |
| 3291 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3292 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3293 | ConstantArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3294 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3295 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3296 | if (ElementType.isNull()) |
| 3297 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3298 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3299 | QualType Result = TL.getType(); |
| 3300 | if (getDerived().AlwaysRebuild() || |
| 3301 | ElementType != T->getElementType()) { |
| 3302 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3303 | T->getSizeModifier(), |
| 3304 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3305 | T->getIndexTypeCVRQualifiers(), |
| 3306 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3307 | if (Result.isNull()) |
| 3308 | return QualType(); |
| 3309 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3310 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3311 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3312 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3313 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3314 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3315 | Expr *Size = TL.getSizeExpr(); |
| 3316 | if (Size) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3317 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3318 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3319 | } |
| 3320 | NewTL.setSizeExpr(Size); |
| 3321 | |
| 3322 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3325 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3326 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3327 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3328 | IncompleteArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3329 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3330 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3331 | if (ElementType.isNull()) |
| 3332 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3334 | QualType Result = TL.getType(); |
| 3335 | if (getDerived().AlwaysRebuild() || |
| 3336 | ElementType != T->getElementType()) { |
| 3337 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3338 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3339 | T->getIndexTypeCVRQualifiers(), |
| 3340 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3341 | if (Result.isNull()) |
| 3342 | return QualType(); |
| 3343 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3344 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3345 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3346 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3347 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3348 | NewTL.setSizeExpr(0); |
| 3349 | |
| 3350 | return Result; |
| 3351 | } |
| 3352 | |
| 3353 | template<typename Derived> |
| 3354 | QualType |
| 3355 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3356 | VariableArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3357 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3358 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3359 | if (ElementType.isNull()) |
| 3360 | return QualType(); |
| 3361 | |
| 3362 | // Array bounds are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3363 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3364 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3365 | ExprResult SizeResult |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3366 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3367 | if (SizeResult.isInvalid()) |
| 3368 | return QualType(); |
| 3369 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3370 | Expr *Size = SizeResult.take(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3371 | |
| 3372 | QualType Result = TL.getType(); |
| 3373 | if (getDerived().AlwaysRebuild() || |
| 3374 | ElementType != T->getElementType() || |
| 3375 | Size != T->getSizeExpr()) { |
| 3376 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3377 | T->getSizeModifier(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3378 | Size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3379 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3380 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3381 | if (Result.isNull()) |
| 3382 | return QualType(); |
| 3383 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3384 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3385 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3386 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3387 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3388 | NewTL.setSizeExpr(Size); |
| 3389 | |
| 3390 | return Result; |
| 3391 | } |
| 3392 | |
| 3393 | template<typename Derived> |
| 3394 | QualType |
| 3395 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3396 | DependentSizedArrayTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3397 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3398 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3399 | if (ElementType.isNull()) |
| 3400 | return QualType(); |
| 3401 | |
| 3402 | // Array bounds are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3403 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3404 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3405 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3406 | Expr *origSize = TL.getSizeExpr(); |
| 3407 | if (!origSize) origSize = T->getSizeExpr(); |
| 3408 | |
| 3409 | ExprResult sizeResult |
| 3410 | = getDerived().TransformExpr(origSize); |
| 3411 | if (sizeResult.isInvalid()) |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3412 | return QualType(); |
| 3413 | |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3414 | Expr *size = sizeResult.get(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3415 | |
| 3416 | QualType Result = TL.getType(); |
| 3417 | if (getDerived().AlwaysRebuild() || |
| 3418 | ElementType != T->getElementType() || |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3419 | size != origSize) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3420 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3421 | T->getSizeModifier(), |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3422 | size, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3423 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3424 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3425 | if (Result.isNull()) |
| 3426 | return QualType(); |
| 3427 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3428 | |
| 3429 | // We might have any sort of array type now, but fortunately they |
| 3430 | // all have the same location layout. |
| 3431 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3432 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3433 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 3b65751 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3434 | NewTL.setSizeExpr(size); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3435 | |
| 3436 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | |
| 3439 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3440 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3441 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3442 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3443 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3444 | |
| 3445 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3446 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3447 | if (ElementType.isNull()) |
| 3448 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3450 | // Vector sizes are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3451 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3452 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3453 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3454 | if (Size.isInvalid()) |
| 3455 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3457 | QualType Result = TL.getType(); |
| 3458 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3459 | ElementType != T->getElementType() || |
| 3460 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3461 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3462 | Size.take(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3463 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3464 | if (Result.isNull()) |
| 3465 | return QualType(); |
| 3466 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3467 | |
| 3468 | // Result might be dependent or not. |
| 3469 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3470 | DependentSizedExtVectorTypeLoc NewTL |
| 3471 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3472 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3473 | } else { |
| 3474 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3475 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3476 | } |
| 3477 | |
| 3478 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
| 3481 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3482 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3483 | VectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3484 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3485 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3486 | if (ElementType.isNull()) |
| 3487 | return QualType(); |
| 3488 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3489 | QualType Result = TL.getType(); |
| 3490 | if (getDerived().AlwaysRebuild() || |
| 3491 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3492 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3493 | T->getVectorKind()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3494 | if (Result.isNull()) |
| 3495 | return QualType(); |
| 3496 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3497 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3498 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3499 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3501 | return Result; |
| 3502 | } |
| 3503 | |
| 3504 | template<typename Derived> |
| 3505 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3506 | ExtVectorTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3507 | const VectorType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3508 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3509 | if (ElementType.isNull()) |
| 3510 | return QualType(); |
| 3511 | |
| 3512 | QualType Result = TL.getType(); |
| 3513 | if (getDerived().AlwaysRebuild() || |
| 3514 | ElementType != T->getElementType()) { |
| 3515 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3516 | T->getNumElements(), |
| 3517 | /*FIXME*/ SourceLocation()); |
| 3518 | if (Result.isNull()) |
| 3519 | return QualType(); |
| 3520 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3521 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3522 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3523 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3524 | |
| 3525 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3526 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | |
| 3528 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3529 | ParmVarDecl * |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3530 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 3531 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3532 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3533 | TypeSourceInfo *NewDI = 0; |
| 3534 | |
| 3535 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3536 | // If we're substituting into a pack expansion type and we know the |
| 3537 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3538 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3539 | |
| 3540 | TypeLocBuilder TLB; |
| 3541 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3542 | TLB.reserve(NewTL.getFullDataSize()); |
| 3543 | |
| 3544 | QualType Result = getDerived().TransformType(TLB, |
| 3545 | OldExpansionTL.getPatternLoc()); |
| 3546 | if (Result.isNull()) |
| 3547 | return 0; |
| 3548 | |
| 3549 | Result = RebuildPackExpansionType(Result, |
| 3550 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3551 | OldExpansionTL.getEllipsisLoc(), |
| 3552 | NumExpansions); |
| 3553 | if (Result.isNull()) |
| 3554 | return 0; |
| 3555 | |
| 3556 | PackExpansionTypeLoc NewExpansionTL |
| 3557 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3558 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3559 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3560 | } else |
| 3561 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3562 | if (!NewDI) |
| 3563 | return 0; |
| 3564 | |
| 3565 | if (NewDI == OldDI) |
| 3566 | return OldParm; |
| 3567 | else |
| 3568 | return ParmVarDecl::Create(SemaRef.Context, |
| 3569 | OldParm->getDeclContext(), |
| 3570 | OldParm->getLocation(), |
| 3571 | OldParm->getIdentifier(), |
| 3572 | NewDI->getType(), |
| 3573 | NewDI, |
| 3574 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 3575 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3576 | /* DefArg */ NULL); |
| 3577 | } |
| 3578 | |
| 3579 | template<typename Derived> |
| 3580 | bool TreeTransform<Derived>:: |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3581 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3582 | ParmVarDecl **Params, unsigned NumParams, |
| 3583 | const QualType *ParamTypes, |
| 3584 | llvm::SmallVectorImpl<QualType> &OutParamTypes, |
| 3585 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { |
| 3586 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3587 | if (ParmVarDecl *OldParm = Params[i]) { |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3588 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3589 | if (OldParm->isParameterPack()) { |
| 3590 | // We have a function parameter pack that may need to be expanded. |
| 3591 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3592 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3593 | // Find the parameter packs that could be expanded. |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3594 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3595 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3596 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3597 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3598 | |
| 3599 | // Determine whether we should expand the parameter packs. |
| 3600 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3601 | bool RetainExpansion = false; |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3602 | llvm::Optional<unsigned> OrigNumExpansions |
| 3603 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3604 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | c8a16fb | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3605 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3606 | Pattern.getSourceRange(), |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3607 | Unexpanded.data(), |
| 3608 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3609 | ShouldExpand, |
| 3610 | RetainExpansion, |
| 3611 | NumExpansions)) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3612 | return true; |
| 3613 | } |
| 3614 | |
| 3615 | if (ShouldExpand) { |
| 3616 | // Expand the function parameter pack into multiple, separate |
| 3617 | // parameters. |
Douglas Gregor | 12c9c00 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3618 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3619 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3620 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3621 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3622 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3623 | OrigNumExpansions); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3624 | if (!NewParm) |
| 3625 | return true; |
| 3626 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3627 | OutParamTypes.push_back(NewParm->getType()); |
| 3628 | if (PVars) |
| 3629 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3630 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3631 | |
| 3632 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3633 | // forgetting the partially-substituted parameter pack. |
| 3634 | if (RetainExpansion) { |
| 3635 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3636 | ParmVarDecl *NewParm |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3637 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3638 | OrigNumExpansions); |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3639 | if (!NewParm) |
| 3640 | return true; |
| 3641 | |
| 3642 | OutParamTypes.push_back(NewParm->getType()); |
| 3643 | if (PVars) |
| 3644 | PVars->push_back(NewParm); |
| 3645 | } |
| 3646 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3647 | // We're done with the pack expansion. |
| 3648 | continue; |
| 3649 | } |
| 3650 | |
| 3651 | // We'll substitute the parameter now without expanding the pack |
| 3652 | // expansion. |
| 3653 | } |
| 3654 | |
| 3655 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Douglas Gregor | 6a24bfd | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3656 | ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3657 | NumExpansions); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3658 | if (!NewParm) |
| 3659 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3660 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3661 | OutParamTypes.push_back(NewParm->getType()); |
| 3662 | if (PVars) |
| 3663 | PVars->push_back(NewParm); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3664 | continue; |
| 3665 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3666 | |
| 3667 | // Deal with the possibility that we don't have a parameter |
| 3668 | // declaration for this parameter. |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3669 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3670 | bool IsPackExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3671 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3672 | if (const PackExpansionType *Expansion |
| 3673 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3674 | // We have a function parameter pack that may need to be expanded. |
| 3675 | QualType Pattern = Expansion->getPattern(); |
| 3676 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3677 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3678 | |
| 3679 | // Determine whether we should expand the parameter packs. |
| 3680 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3681 | bool RetainExpansion = false; |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3682 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3683 | Unexpanded.data(), |
| 3684 | Unexpanded.size(), |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3685 | ShouldExpand, |
| 3686 | RetainExpansion, |
| 3687 | NumExpansions)) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3688 | return true; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | if (ShouldExpand) { |
| 3692 | // Expand the function parameter pack into multiple, separate |
| 3693 | // parameters. |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3694 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3695 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3696 | QualType NewType = getDerived().TransformType(Pattern); |
| 3697 | if (NewType.isNull()) |
| 3698 | return true; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3700 | OutParamTypes.push_back(NewType); |
| 3701 | if (PVars) |
| 3702 | PVars->push_back(0); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | // We're done with the pack expansion. |
| 3706 | continue; |
| 3707 | } |
| 3708 | |
Douglas Gregor | 3cae5c9 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3709 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3710 | // forgetting the partially-substituted parameter pack. |
| 3711 | if (RetainExpansion) { |
| 3712 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3713 | QualType NewType = getDerived().TransformType(Pattern); |
| 3714 | if (NewType.isNull()) |
| 3715 | return true; |
| 3716 | |
| 3717 | OutParamTypes.push_back(NewType); |
| 3718 | if (PVars) |
| 3719 | PVars->push_back(0); |
| 3720 | } |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3721 | |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3722 | // We'll substitute the parameter now without expanding the pack |
| 3723 | // expansion. |
| 3724 | OldType = Expansion->getPattern(); |
| 3725 | IsPackExpansion = true; |
| 3726 | } |
| 3727 | |
| 3728 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3729 | QualType NewType = getDerived().TransformType(OldType); |
| 3730 | if (NewType.isNull()) |
| 3731 | return true; |
| 3732 | |
| 3733 | if (IsPackExpansion) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3734 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3735 | NumExpansions); |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3736 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3737 | OutParamTypes.push_back(NewType); |
| 3738 | if (PVars) |
| 3739 | PVars->push_back(0); |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | return false; |
Douglas Gregor | 603cfb4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3743 | } |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3744 | |
| 3745 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3746 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3747 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3748 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3749 | // Transform the parameters and return type. |
| 3750 | // |
| 3751 | // We instantiate in source order, with the return type first followed by |
| 3752 | // the parameters, because users tend to expect this (even if they shouldn't |
| 3753 | // rely on it!). |
| 3754 | // |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3755 | // When the function has a trailing return type, we instantiate the |
| 3756 | // parameters before the return type, since the return type can then refer |
| 3757 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 3758 | // |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3759 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3760 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3761 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 7e010a0 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3762 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3763 | QualType ResultType; |
| 3764 | |
| 3765 | if (TL.getTrailingReturn()) { |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3766 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3767 | TL.getParmArray(), |
| 3768 | TL.getNumArgs(), |
| 3769 | TL.getTypePtr()->arg_type_begin(), |
| 3770 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3771 | return QualType(); |
| 3772 | |
| 3773 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3774 | if (ResultType.isNull()) |
| 3775 | return QualType(); |
| 3776 | } |
| 3777 | else { |
| 3778 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3779 | if (ResultType.isNull()) |
| 3780 | return QualType(); |
| 3781 | |
Douglas Gregor | a009b59 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3782 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3783 | TL.getParmArray(), |
| 3784 | TL.getNumArgs(), |
| 3785 | TL.getTypePtr()->arg_type_begin(), |
| 3786 | ParamTypes, &ParamDecls)) |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3787 | return QualType(); |
| 3788 | } |
| 3789 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3790 | QualType Result = TL.getType(); |
| 3791 | if (getDerived().AlwaysRebuild() || |
| 3792 | ResultType != T->getResultType() || |
Douglas Gregor | bd5f9f7 | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 3793 | T->getNumArgs() != ParamTypes.size() || |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3794 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 3795 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 3796 | ParamTypes.data(), |
| 3797 | ParamTypes.size(), |
| 3798 | T->isVariadic(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3799 | T->getTypeQuals(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3800 | T->getRefQualifier(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3801 | T->getExtInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3802 | if (Result.isNull()) |
| 3803 | return QualType(); |
| 3804 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3806 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 3807 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3808 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3809 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3810 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 3811 | NewTL.setArg(i, ParamDecls[i]); |
| 3812 | |
| 3813 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3814 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3816 | template<typename Derived> |
| 3817 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3818 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3819 | FunctionNoProtoTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3820 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3821 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3822 | if (ResultType.isNull()) |
| 3823 | return QualType(); |
| 3824 | |
| 3825 | QualType Result = TL.getType(); |
| 3826 | if (getDerived().AlwaysRebuild() || |
| 3827 | ResultType != T->getResultType()) |
| 3828 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 3829 | |
| 3830 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 3831 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3832 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3833 | NewTL.setTrailingReturn(false); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3834 | |
| 3835 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3836 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3838 | template<typename Derived> QualType |
| 3839 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3840 | UnresolvedUsingTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3841 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3842 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3843 | if (!D) |
| 3844 | return QualType(); |
| 3845 | |
| 3846 | QualType Result = TL.getType(); |
| 3847 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 3848 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 3849 | if (Result.isNull()) |
| 3850 | return QualType(); |
| 3851 | } |
| 3852 | |
| 3853 | // We might get an arbitrary type spec type back. We should at |
| 3854 | // least always get a type spec type, though. |
| 3855 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 3856 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3857 | |
| 3858 | return Result; |
| 3859 | } |
| 3860 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3861 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3862 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3863 | TypedefTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3864 | const TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3865 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3866 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3867 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3868 | if (!Typedef) |
| 3869 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3870 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3871 | QualType Result = TL.getType(); |
| 3872 | if (getDerived().AlwaysRebuild() || |
| 3873 | Typedef != T->getDecl()) { |
| 3874 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3875 | if (Result.isNull()) |
| 3876 | return QualType(); |
| 3877 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3878 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3879 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3880 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3881 | |
| 3882 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3883 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3885 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3886 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3887 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3888 | // typeof expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3889 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3890 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3891 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3892 | if (E.isInvalid()) |
| 3893 | return QualType(); |
| 3894 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3895 | QualType Result = TL.getType(); |
| 3896 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3897 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 3898 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3899 | if (Result.isNull()) |
| 3900 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3901 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3902 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3904 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3905 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3906 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3907 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3908 | |
| 3909 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3910 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
| 3912 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3913 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3914 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3915 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3916 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3917 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3918 | return QualType(); |
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 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3921 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3922 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3923 | if (Result.isNull()) |
| 3924 | return QualType(); |
| 3925 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3927 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3928 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3929 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3930 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3931 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3932 | |
| 3933 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | |
| 3936 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3937 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3938 | DecltypeTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3939 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3941 | // decltype expressions are not potentially evaluated contexts |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3942 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3943 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3944 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3945 | if (E.isInvalid()) |
| 3946 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3947 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3948 | QualType Result = TL.getType(); |
| 3949 | if (getDerived().AlwaysRebuild() || |
| 3950 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 3951 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3952 | if (Result.isNull()) |
| 3953 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3954 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3955 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3957 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3958 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3959 | |
| 3960 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3964 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3965 | RecordTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3966 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3967 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3968 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3969 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3970 | if (!Record) |
| 3971 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3973 | QualType Result = TL.getType(); |
| 3974 | if (getDerived().AlwaysRebuild() || |
| 3975 | Record != T->getDecl()) { |
| 3976 | Result = getDerived().RebuildRecordType(Record); |
| 3977 | if (Result.isNull()) |
| 3978 | return QualType(); |
| 3979 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3981 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3982 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3983 | |
| 3984 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | |
| 3987 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3988 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3989 | EnumTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3990 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3991 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3992 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3993 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3994 | if (!Enum) |
| 3995 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3996 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3997 | QualType Result = TL.getType(); |
| 3998 | if (getDerived().AlwaysRebuild() || |
| 3999 | Enum != T->getDecl()) { |
| 4000 | Result = getDerived().RebuildEnumType(Enum); |
| 4001 | if (Result.isNull()) |
| 4002 | return QualType(); |
| 4003 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4004 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4005 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4006 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4007 | |
| 4008 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4009 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4010 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4011 | template<typename Derived> |
| 4012 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4013 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4014 | InjectedClassNameTypeLoc TL) { |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4015 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4016 | TL.getTypePtr()->getDecl()); |
| 4017 | if (!D) return QualType(); |
| 4018 | |
| 4019 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4020 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4021 | return T; |
| 4022 | } |
| 4023 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4024 | template<typename Derived> |
| 4025 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
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 | TemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4028 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4031 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4032 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4033 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4034 | SubstTemplateTypeParmTypeLoc TL) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4035 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | template<typename Derived> |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4039 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4040 | TypeLocBuilder &TLB, |
| 4041 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4042 | return TransformTypeSpecType(TLB, TL); |
| 4043 | } |
| 4044 | |
| 4045 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4046 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4047 | TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4048 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4049 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4050 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | TemplateName Template |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4052 | = getDerived().TransformTemplateName(T->getTemplateName()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4053 | if (Template.isNull()) |
| 4054 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4055 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4056 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4057 | } |
| 4058 | |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4059 | namespace { |
| 4060 | /// \brief Simple iterator that traverses the template arguments in a |
| 4061 | /// container that provides a \c getArgLoc() member function. |
| 4062 | /// |
| 4063 | /// This iterator is intended to be used with the iterator form of |
| 4064 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4065 | template<typename ArgLocContainer> |
| 4066 | class TemplateArgumentLocContainerIterator { |
| 4067 | ArgLocContainer *Container; |
| 4068 | unsigned Index; |
| 4069 | |
| 4070 | public: |
| 4071 | typedef TemplateArgumentLoc value_type; |
| 4072 | typedef TemplateArgumentLoc reference; |
| 4073 | typedef int difference_type; |
| 4074 | typedef std::input_iterator_tag iterator_category; |
| 4075 | |
| 4076 | class pointer { |
| 4077 | TemplateArgumentLoc Arg; |
| 4078 | |
| 4079 | public: |
| 4080 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4081 | |
| 4082 | const TemplateArgumentLoc *operator->() const { |
| 4083 | return &Arg; |
| 4084 | } |
| 4085 | }; |
| 4086 | |
| 4087 | |
| 4088 | TemplateArgumentLocContainerIterator() {} |
| 4089 | |
| 4090 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4091 | unsigned Index) |
| 4092 | : Container(&Container), Index(Index) { } |
| 4093 | |
| 4094 | TemplateArgumentLocContainerIterator &operator++() { |
| 4095 | ++Index; |
| 4096 | return *this; |
| 4097 | } |
| 4098 | |
| 4099 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4100 | TemplateArgumentLocContainerIterator Old(*this); |
| 4101 | ++(*this); |
| 4102 | return Old; |
| 4103 | } |
| 4104 | |
| 4105 | TemplateArgumentLoc operator*() const { |
| 4106 | return Container->getArgLoc(Index); |
| 4107 | } |
| 4108 | |
| 4109 | pointer operator->() const { |
| 4110 | return pointer(Container->getArgLoc(Index)); |
| 4111 | } |
| 4112 | |
| 4113 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4114 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4115 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4116 | } |
| 4117 | |
| 4118 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | f7dd699 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4119 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4120 | return !(X == Y); |
| 4121 | } |
| 4122 | }; |
| 4123 | } |
| 4124 | |
| 4125 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4126 | template <typename Derived> |
| 4127 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4128 | TypeLocBuilder &TLB, |
| 4129 | TemplateSpecializationTypeLoc TL, |
| 4130 | TemplateName Template) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4131 | TemplateArgumentListInfo NewTemplateArgs; |
| 4132 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4133 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4134 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4135 | ArgIterator; |
| 4136 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4137 | ArgIterator(TL, TL.getNumArgs()), |
| 4138 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4139 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4141 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4142 | |
| 4143 | QualType Result = |
| 4144 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4145 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4146 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4147 | |
| 4148 | if (!Result.isNull()) { |
| 4149 | TemplateSpecializationTypeLoc NewTL |
| 4150 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4151 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4152 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4153 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4154 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4155 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4158 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
| 4161 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4162 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4163 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4164 | ElaboratedTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4165 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4166 | |
| 4167 | NestedNameSpecifier *NNS = 0; |
| 4168 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 4169 | if (T->getQualifier() != 0) { |
| 4170 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4171 | TL.getQualifierRange()); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4172 | if (!NNS) |
| 4173 | return QualType(); |
| 4174 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4176 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4177 | if (NamedT.isNull()) |
| 4178 | return QualType(); |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4179 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4180 | QualType Result = TL.getType(); |
| 4181 | if (getDerived().AlwaysRebuild() || |
| 4182 | NNS != T->getQualifier() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4183 | NamedT != T->getNamedType()) { |
John McCall | 21e413f | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4184 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
| 4185 | T->getKeyword(), NNS, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4186 | if (Result.isNull()) |
| 4187 | return QualType(); |
| 4188 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4189 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4190 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4191 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4192 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4193 | |
| 4194 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4195 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
| 4197 | template<typename Derived> |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4198 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4199 | TypeLocBuilder &TLB, |
| 4200 | AttributedTypeLoc TL) { |
| 4201 | const AttributedType *oldType = TL.getTypePtr(); |
| 4202 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4203 | if (modifiedType.isNull()) |
| 4204 | return QualType(); |
| 4205 | |
| 4206 | QualType result = TL.getType(); |
| 4207 | |
| 4208 | // FIXME: dependent operand expressions? |
| 4209 | if (getDerived().AlwaysRebuild() || |
| 4210 | modifiedType != oldType->getModifiedType()) { |
| 4211 | // TODO: this is really lame; we should really be rebuilding the |
| 4212 | // equivalent type from first principles. |
| 4213 | QualType equivalentType |
| 4214 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4215 | if (equivalentType.isNull()) |
| 4216 | return QualType(); |
| 4217 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4218 | modifiedType, |
| 4219 | equivalentType); |
| 4220 | } |
| 4221 | |
| 4222 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4223 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4224 | if (TL.hasAttrOperand()) |
| 4225 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4226 | if (TL.hasAttrExprOperand()) |
| 4227 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4228 | else if (TL.hasAttrEnumOperand()) |
| 4229 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4230 | |
| 4231 | return result; |
| 4232 | } |
| 4233 | |
| 4234 | template<typename Derived> |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4235 | QualType |
| 4236 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4237 | ParenTypeLoc TL) { |
| 4238 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4239 | if (Inner.isNull()) |
| 4240 | return QualType(); |
| 4241 | |
| 4242 | QualType Result = TL.getType(); |
| 4243 | if (getDerived().AlwaysRebuild() || |
| 4244 | Inner != TL.getInnerLoc().getType()) { |
| 4245 | Result = getDerived().RebuildParenType(Inner); |
| 4246 | if (Result.isNull()) |
| 4247 | return QualType(); |
| 4248 | } |
| 4249 | |
| 4250 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4251 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4252 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4253 | return Result; |
| 4254 | } |
| 4255 | |
| 4256 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4257 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4258 | DependentNameTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4259 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4260 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4261 | NestedNameSpecifier *NNS |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4262 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4263 | TL.getQualifierRange()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4264 | if (!NNS) |
| 4265 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4267 | QualType Result |
| 4268 | = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 4269 | T->getIdentifier(), |
| 4270 | TL.getKeywordLoc(), |
| 4271 | TL.getQualifierRange(), |
| 4272 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4273 | if (Result.isNull()) |
| 4274 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4275 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4276 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4277 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4278 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4279 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4280 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4281 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4282 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4283 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4284 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4285 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4286 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 4287 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4288 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4289 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4292 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4293 | QualType TreeTransform<Derived>:: |
| 4294 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4295 | DependentTemplateSpecializationTypeLoc TL) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4296 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4297 | |
| 4298 | NestedNameSpecifier *NNS |
| 4299 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4300 | TL.getQualifierRange()); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4301 | if (!NNS) |
| 4302 | return QualType(); |
| 4303 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4304 | return getDerived() |
| 4305 | .TransformDependentTemplateSpecializationType(TLB, TL, NNS); |
| 4306 | } |
| 4307 | |
| 4308 | template<typename Derived> |
| 4309 | QualType TreeTransform<Derived>:: |
| 4310 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4311 | DependentTemplateSpecializationTypeLoc TL, |
| 4312 | NestedNameSpecifier *NNS) { |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4313 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4314 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4315 | TemplateArgumentListInfo NewTemplateArgs; |
| 4316 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4317 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 7ca7ac4 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4318 | |
| 4319 | typedef TemplateArgumentLocContainerIterator< |
| 4320 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4321 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4322 | ArgIterator(TL, TL.getNumArgs()), |
| 4323 | NewTemplateArgs)) |
Douglas Gregor | 7f61f2f | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4324 | return QualType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4326 | QualType Result |
| 4327 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4328 | NNS, |
| 4329 | TL.getQualifierRange(), |
| 4330 | T->getIdentifier(), |
| 4331 | TL.getNameLoc(), |
| 4332 | NewTemplateArgs); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4333 | if (Result.isNull()) |
| 4334 | return QualType(); |
| 4335 | |
| 4336 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4337 | QualType NamedT = ElabT->getNamedType(); |
| 4338 | |
| 4339 | // Copy information relevant to the template specialization. |
| 4340 | TemplateSpecializationTypeLoc NamedTL |
| 4341 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4342 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4343 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4344 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4345 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4346 | |
| 4347 | // Copy information relevant to the elaborated type. |
| 4348 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4349 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4350 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 4351 | } else { |
Douglas Gregor | e2872d0 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 4352 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4353 | TLB.pushFullCopy(NewTL); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4354 | } |
| 4355 | return Result; |
| 4356 | } |
| 4357 | |
| 4358 | template<typename Derived> |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4359 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4360 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4361 | QualType Pattern |
| 4362 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4363 | if (Pattern.isNull()) |
| 4364 | return QualType(); |
| 4365 | |
| 4366 | QualType Result = TL.getType(); |
| 4367 | if (getDerived().AlwaysRebuild() || |
| 4368 | Pattern != TL.getPatternLoc().getType()) { |
| 4369 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4370 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4371 | TL.getEllipsisLoc(), |
| 4372 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 2fc1bb7 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4373 | if (Result.isNull()) |
| 4374 | return QualType(); |
| 4375 | } |
| 4376 | |
| 4377 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4378 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4379 | return Result; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4383 | QualType |
| 4384 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4385 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4386 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4387 | TLB.pushFullCopy(TL); |
| 4388 | return TL.getType(); |
| 4389 | } |
| 4390 | |
| 4391 | template<typename Derived> |
| 4392 | QualType |
| 4393 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4394 | ObjCObjectTypeLoc TL) { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4395 | // ObjCObjectType is never dependent. |
| 4396 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4397 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
| 4400 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4401 | QualType |
| 4402 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4403 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4404 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4405 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4406 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4409 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4410 | // Statement transformation |
| 4411 | //===----------------------------------------------------------------------===// |
| 4412 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4413 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4415 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4419 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4420 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4421 | return getDerived().TransformCompoundStmt(S, false); |
| 4422 | } |
| 4423 | |
| 4424 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4425 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4427 | bool IsStmtExpr) { |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4428 | bool SubStmtInvalid = false; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4429 | bool SubStmtChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4430 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4431 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4432 | B != BEnd; ++B) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4433 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4434 | if (Result.isInvalid()) { |
| 4435 | // Immediately fail if this was a DeclStmt, since it's very |
| 4436 | // likely that this will cause problems for future statements. |
| 4437 | if (isa<DeclStmt>(*B)) |
| 4438 | return StmtError(); |
| 4439 | |
| 4440 | // Otherwise, just keep processing substatements and fail later. |
| 4441 | SubStmtInvalid = true; |
| 4442 | continue; |
| 4443 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4445 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4446 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4447 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4448 | |
John McCall | 7114cba | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4449 | if (SubStmtInvalid) |
| 4450 | return StmtError(); |
| 4451 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4452 | if (!getDerived().AlwaysRebuild() && |
| 4453 | !SubStmtChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4454 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4455 | |
| 4456 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4457 | move_arg(Statements), |
| 4458 | S->getRBracLoc(), |
| 4459 | IsStmtExpr); |
| 4460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4462 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4463 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4464 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4465 | ExprResult LHS, RHS; |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4466 | { |
| 4467 | // The case value expressions are not potentially evaluated. |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4468 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4470 | // Transform the left-hand case value. |
| 4471 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4472 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4473 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4475 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4476 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4477 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4478 | return StmtError(); |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4480 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4481 | // Build the case statement. |
| 4482 | // Case statements are always rebuilt so that they will attached to their |
| 4483 | // transformed switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4484 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4485 | LHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4486 | S->getEllipsisLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4487 | RHS.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4488 | S->getColonLoc()); |
| 4489 | if (Case.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4490 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4491 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4492 | // Transform the statement following the case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4493 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4494 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4495 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4497 | // Attach the body to the case statement |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4498 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4502 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4504 | // Transform the statement following the default case |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4505 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4506 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4507 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4509 | // Default statements are always rebuilt |
| 4510 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4511 | SubStmt.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4512 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4515 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4516 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4517 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4518 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4519 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4520 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4521 | // FIXME: Pass the real colon location in. |
| 4522 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 4523 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
Argyrios Kyrtzidis | 1a18600 | 2010-09-28 14:54:07 +0000 | [diff] [blame] | 4524 | SubStmt.get(), S->HasUnusedAttribute()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4526 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4527 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4528 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4530 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4531 | ExprResult Cond; |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4532 | VarDecl *ConditionVar = 0; |
| 4533 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4534 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4535 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4536 | getDerived().TransformDefinition( |
| 4537 | S->getConditionVariable()->getLocation(), |
| 4538 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4539 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4540 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4541 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4542 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4543 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4544 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4545 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4546 | |
| 4547 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4548 | if (S->getCond()) { |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4549 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 4550 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4551 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4552 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4553 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4554 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4555 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4556 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4557 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4558 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4559 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4560 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4561 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4562 | // Transform the "then" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4563 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4564 | if (Then.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 | // Transform the "else" branch. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4568 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4569 | if (Else.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4570 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4572 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4573 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4574 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4575 | Then.get() == S->getThen() && |
| 4576 | Else.get() == S->getElse()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4577 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4579 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 4580 | Then.get(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4581 | S->getElseLoc(), Else.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4585 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4586 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4587 | // Transform the condition. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4588 | ExprResult Cond; |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4589 | VarDecl *ConditionVar = 0; |
| 4590 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4591 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4592 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4593 | getDerived().TransformDefinition( |
| 4594 | S->getConditionVariable()->getLocation(), |
| 4595 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4596 | if (!ConditionVar) |
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 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4599 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4600 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4601 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4602 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4605 | // Rebuild the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4606 | StmtResult Switch |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4607 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 4608 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4609 | if (Switch.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 | // Transform the body of the switch statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4613 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4614 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4615 | return StmtError(); |
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 | // Complete the switch statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4618 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 4619 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4620 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4622 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4623 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4624 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4625 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4626 | ExprResult Cond; |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4627 | VarDecl *ConditionVar = 0; |
| 4628 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4629 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4630 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4631 | getDerived().TransformDefinition( |
| 4632 | S->getConditionVariable()->getLocation(), |
| 4633 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4634 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4635 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4636 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4637 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4638 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4639 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4640 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4641 | |
| 4642 | if (S->getCond()) { |
| 4643 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4644 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 4645 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4646 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4647 | return StmtError(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4648 | Cond = CondE; |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4649 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4650 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4651 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4652 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4653 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4654 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4655 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4656 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4657 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4658 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4659 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4660 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4661 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4662 | FullCond.get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4663 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4664 | Body.get() == S->getBody()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4665 | return Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4666 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4667 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4668 | ConditionVar, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4671 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4672 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4673 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4674 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4675 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4676 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4677 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4678 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4679 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4680 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4681 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4682 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4683 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4684 | if (!getDerived().AlwaysRebuild() && |
| 4685 | Cond.get() == S->getCond() && |
| 4686 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4687 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4689 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 4690 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4691 | S->getRParenLoc()); |
| 4692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4693 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4694 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4695 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4697 | // Transform the initialization statement |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4698 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4699 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4700 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4701 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4702 | // Transform the condition |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4703 | ExprResult Cond; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4704 | VarDecl *ConditionVar = 0; |
| 4705 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4706 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4707 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4708 | getDerived().TransformDefinition( |
| 4709 | S->getConditionVariable()->getLocation(), |
| 4710 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4711 | if (!ConditionVar) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4712 | return StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4713 | } else { |
| 4714 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4715 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4716 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4717 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4718 | |
| 4719 | if (S->getCond()) { |
| 4720 | // Convert the condition to a boolean value. |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4721 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 4722 | Cond.get()); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4723 | if (CondE.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4724 | return StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4725 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4726 | Cond = CondE.get(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4727 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4729 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4730 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4731 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4732 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4733 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4734 | // Transform the increment |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4735 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4736 | if (Inc.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4737 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4739 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 4740 | if (S->getInc() && !FullInc.get()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4741 | return StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4742 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4743 | // Transform the body |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4744 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4745 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4746 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4747 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4748 | if (!getDerived().AlwaysRebuild() && |
| 4749 | Init.get() == S->getInit() && |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4750 | FullCond.get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4751 | Inc.get() == S->getInc() && |
| 4752 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4753 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4755 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4756 | Init.get(), FullCond, ConditionVar, |
| 4757 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4761 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4762 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4763 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4765 | S->getLabel()); |
| 4766 | } |
| 4767 | |
| 4768 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4769 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4771 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4772 | if (Target.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4773 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4775 | if (!getDerived().AlwaysRebuild() && |
| 4776 | Target.get() == S->getTarget()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4777 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4778 | |
| 4779 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4780 | Target.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4784 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4785 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4786 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4787 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4789 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4790 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4791 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4792 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4795 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4796 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4798 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4799 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4800 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4801 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4802 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4803 | // to tell whether the return type of the function has changed. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4804 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4807 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4808 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4809 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4810 | bool DeclChanged = false; |
| 4811 | llvm::SmallVector<Decl *, 4> Decls; |
| 4812 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 4813 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4814 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 4815 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4816 | if (!Transformed) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4817 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4818 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4819 | if (Transformed != *D) |
| 4820 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4822 | Decls.push_back(Transformed); |
| 4823 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4825 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4826 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | |
| 4828 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4829 | S->getStartLoc(), S->getEndLoc()); |
| 4830 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4831 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4832 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4833 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4834 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4835 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4836 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4840 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4841 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4842 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4843 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 4844 | ASTOwningVector<Expr*> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 4845 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 4846 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4847 | ExprResult AsmString; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4848 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4849 | |
| 4850 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4851 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4852 | // Go through the outputs. |
| 4853 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 4854 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4855 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4856 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4857 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4858 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4859 | // Transform the output expr. |
| 4860 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4861 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4862 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4863 | return StmtError(); |
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 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4866 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4867 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4868 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4869 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4870 | // Go through the inputs. |
| 4871 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 4872 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4873 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4874 | // No need to transform the constraint literal. |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4875 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4876 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4877 | // Transform the input expr. |
| 4878 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4879 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4880 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4881 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4882 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4883 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4884 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4885 | Exprs.push_back(Result.get()); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4886 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4887 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4888 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4889 | return SemaRef.Owned(S); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4890 | |
| 4891 | // Go through the clobbers. |
| 4892 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4893 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4894 | |
| 4895 | // No need to transform the asm string literal. |
| 4896 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 4897 | |
| 4898 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 4899 | S->isSimple(), |
| 4900 | S->isVolatile(), |
| 4901 | S->getNumOutputs(), |
| 4902 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 4903 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4904 | move_arg(Constraints), |
| 4905 | move_arg(Exprs), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4906 | AsmString.get(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 4907 | move_arg(Clobbers), |
| 4908 | S->getRParenLoc(), |
| 4909 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | |
| 4913 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4914 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4915 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4916 | // Transform the body of the @try. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4917 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4918 | if (TryBody.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4919 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4921 | // Transform the @catch statements (if present). |
| 4922 | bool AnyCatchChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4923 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4924 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4925 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4926 | if (Catch.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4927 | return StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4928 | if (Catch.get() != S->getCatchStmt(I)) |
| 4929 | AnyCatchChanged = true; |
| 4930 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4931 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4932 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4933 | // Transform the @finally statement (if present). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4934 | StmtResult Finally; |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4935 | if (S->getFinallyStmt()) { |
| 4936 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 4937 | if (Finally.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4938 | return StmtError(); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | // If nothing changed, just retain this statement. |
| 4942 | if (!getDerived().AlwaysRebuild() && |
| 4943 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 4944 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4945 | Finally.get() == S->getFinallyStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4946 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4947 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4948 | // Build a new statement. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4949 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 4950 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4951 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4952 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4953 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4954 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4955 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4956 | // Transform the @catch parameter, if there is one. |
| 4957 | VarDecl *Var = 0; |
| 4958 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 4959 | TypeSourceInfo *TSInfo = 0; |
| 4960 | if (FromVar->getTypeSourceInfo()) { |
| 4961 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 4962 | if (!TSInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4963 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4964 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4965 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4966 | QualType T; |
| 4967 | if (TSInfo) |
| 4968 | T = TSInfo->getType(); |
| 4969 | else { |
| 4970 | T = getDerived().TransformType(FromVar->getType()); |
| 4971 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4972 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4973 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4974 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4975 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 4976 | if (!Var) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4977 | return StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4978 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4979 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4980 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4981 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4982 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4983 | |
| 4984 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4985 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4986 | Var, Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4987 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4989 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4990 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4991 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4992 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4993 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4994 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4995 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4996 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4997 | // If nothing changed, just retain this statement. |
| 4998 | if (!getDerived().AlwaysRebuild() && |
| 4999 | Body.get() == S->getFinallyBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5000 | return SemaRef.Owned(S); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5001 | |
| 5002 | // Build a new statement. |
| 5003 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5004 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5005 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5006 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5007 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5008 | StmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5009 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5010 | ExprResult Operand; |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5011 | if (S->getThrowExpr()) { |
| 5012 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5013 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5014 | return StmtError(); |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5015 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5016 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5017 | if (!getDerived().AlwaysRebuild() && |
| 5018 | Operand.get() == S->getThrowExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5019 | return getSema().Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5020 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5021 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5023 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5024 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5025 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5026 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5027 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5028 | // Transform the object we are locking. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5029 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5030 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5031 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5032 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5033 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5034 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5035 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5036 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5037 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5038 | // If nothing change, just retain the current statement. |
| 5039 | if (!getDerived().AlwaysRebuild() && |
| 5040 | Object.get() == S->getSynchExpr() && |
| 5041 | Body.get() == S->getSynchBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5042 | return SemaRef.Owned(S); |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5043 | |
| 5044 | // Build a new statement. |
| 5045 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5046 | Object.get(), Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5050 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5051 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5052 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5053 | // Transform the element statement. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5054 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5055 | if (Element.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5056 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5057 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5058 | // Transform the collection expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5059 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5060 | if (Collection.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5061 | return StmtError(); |
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 | // Transform the body. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5064 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5065 | if (Body.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5066 | return StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5067 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5068 | // If nothing changed, just retain this statement. |
| 5069 | if (!getDerived().AlwaysRebuild() && |
| 5070 | Element.get() == S->getElement() && |
| 5071 | Collection.get() == S->getCollection() && |
| 5072 | Body.get() == S->getBody()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5073 | return SemaRef.Owned(S); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5074 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5075 | // Build a new statement. |
| 5076 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5077 | /*FIXME:*/S->getForLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5078 | Element.get(), |
| 5079 | Collection.get(), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5080 | S->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5081 | Body.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5082 | } |
| 5083 | |
| 5084 | |
| 5085 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5086 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5087 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5088 | // Transform the exception declaration, if any. |
| 5089 | VarDecl *Var = 0; |
| 5090 | if (S->getExceptionDecl()) { |
| 5091 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5092 | TypeSourceInfo *T = getDerived().TransformType( |
| 5093 | ExceptionDecl->getTypeSourceInfo()); |
| 5094 | if (!T) |
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 | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5097 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5098 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | 83cb942 | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5099 | ExceptionDecl->getLocation()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5100 | if (!Var || Var->isInvalidDecl()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5101 | return StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5103 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5104 | // Transform the actual exception handler. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5105 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5106 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5107 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5108 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5109 | if (!getDerived().AlwaysRebuild() && |
| 5110 | !Var && |
| 5111 | Handler.get() == S->getHandlerBlock()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5112 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5113 | |
| 5114 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5115 | Var, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5116 | Handler.get()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5118 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5119 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5120 | StmtResult |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5121 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5122 | // Transform the try block itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5123 | StmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5124 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5125 | if (TryBlock.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5126 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5127 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5128 | // Transform the handlers. |
| 5129 | bool HandlerChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5130 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5131 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5132 | StmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5133 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5134 | if (Handler.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5135 | return StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5136 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5137 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5138 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5139 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5140 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5141 | if (!getDerived().AlwaysRebuild() && |
| 5142 | TryBlock.get() == S->getTryBlock() && |
| 5143 | !HandlerChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5144 | return SemaRef.Owned(S); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5145 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5146 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5150 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5151 | // Expression transformation |
| 5152 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5154 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5155 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5156 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
| 5159 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5160 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5161 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5162 | NestedNameSpecifier *Qualifier = 0; |
| 5163 | if (E->getQualifier()) { |
| 5164 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5165 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5166 | if (!Qualifier) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5167 | return ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5168 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5169 | |
| 5170 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5171 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5172 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5173 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5174 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5176 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5177 | if (NameInfo.getName()) { |
| 5178 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5179 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5180 | return ExprError(); |
John McCall | ec8045d | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5181 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5182 | |
| 5183 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5184 | Qualifier == E->getQualifier() && |
| 5185 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5186 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5187 | !E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5188 | |
| 5189 | // Mark it referenced in the new context regardless. |
| 5190 | // FIXME: this is a bit instantiation-specific. |
| 5191 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5192 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5193 | return SemaRef.Owned(E); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5194 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5195 | |
| 5196 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5197 | if (E->hasExplicitTemplateArgs()) { |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5198 | TemplateArgs = &TransArgs; |
| 5199 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5200 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5201 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5202 | E->getNumTemplateArgs(), |
| 5203 | TransArgs)) |
| 5204 | return ExprError(); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5205 | } |
| 5206 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5207 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5208 | ND, NameInfo, TemplateArgs); |
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>::TransformIntegerLiteral(IntegerLiteral *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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5226 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformStringLiteral(StringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5232 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5235 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5236 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5237 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5238 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5242 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5243 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5244 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5245 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5246 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5247 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5248 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5249 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5250 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5251 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5252 | E->getRParen()); |
| 5253 | } |
| 5254 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5255 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5256 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5257 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5258 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5259 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5260 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5261 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5262 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5263 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5265 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5266 | E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5267 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5269 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5270 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5271 | ExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5272 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5273 | // Transform the type. |
| 5274 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5275 | if (!Type) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5276 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5277 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5278 | // Transform all of the components into components similar to what the |
| 5279 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5280 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5281 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5282 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5283 | // template code that we don't care. |
| 5284 | bool ExprChanged = false; |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5285 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5286 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 5287 | llvm::SmallVector<Component, 4> Components; |
| 5288 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5289 | const Node &ON = E->getComponent(I); |
| 5290 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5291 | Comp.isBrackets = true; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5292 | Comp.LocStart = ON.getRange().getBegin(); |
| 5293 | Comp.LocEnd = ON.getRange().getEnd(); |
| 5294 | switch (ON.getKind()) { |
| 5295 | case Node::Array: { |
| 5296 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5297 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5298 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5299 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5300 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5301 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5302 | Comp.isBrackets = true; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5303 | Comp.U.E = Index.get(); |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5304 | break; |
| 5305 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5306 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5307 | case Node::Field: |
| 5308 | case Node::Identifier: |
| 5309 | Comp.isBrackets = false; |
| 5310 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5311 | if (!Comp.U.IdentInfo) |
| 5312 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5313 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5314 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5315 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5316 | case Node::Base: |
| 5317 | // Will be recomputed during the rebuild. |
| 5318 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5319 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5320 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5321 | Components.push_back(Comp); |
| 5322 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5323 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5324 | // If nothing changed, retain the existing expression. |
| 5325 | if (!getDerived().AlwaysRebuild() && |
| 5326 | Type == E->getTypeSourceInfo() && |
| 5327 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5328 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5329 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5330 | // Build a new offsetof expression. |
| 5331 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5332 | Components.data(), Components.size(), |
| 5333 | E->getRParenLoc()); |
| 5334 | } |
| 5335 | |
| 5336 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5337 | ExprResult |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5338 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5339 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5340 | "opaque value expression requires transformation"); |
| 5341 | return SemaRef.Owned(E); |
| 5342 | } |
| 5343 | |
| 5344 | template<typename Derived> |
| 5345 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5346 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5347 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5348 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5349 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5350 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5351 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5352 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5353 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5354 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5355 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5356 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5357 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5358 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5359 | E->getSourceRange()); |
| 5360 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5361 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5362 | ExprResult SubExpr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5363 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5364 | // C++0x [expr.sizeof]p1: |
| 5365 | // The operand is either an expression, which is an unevaluated operand |
| 5366 | // [...] |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5367 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5368 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5369 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5370 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5371 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5373 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5374 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5377 | return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5378 | E->isSizeOf(), |
| 5379 | E->getSourceRange()); |
| 5380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5382 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5383 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5384 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5385 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5386 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5387 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5388 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5389 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5390 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5391 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5392 | |
| 5393 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5394 | if (!getDerived().AlwaysRebuild() && |
| 5395 | LHS.get() == E->getLHS() && |
| 5396 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5397 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5398 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5399 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5401 | RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5402 | E->getRBracketLoc()); |
| 5403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5404 | |
| 5405 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5406 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5407 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5408 | // Transform the callee. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5409 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5410 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5411 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5412 | |
| 5413 | // Transform arguments. |
| 5414 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5415 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5416 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5417 | &ArgChanged)) |
| 5418 | return ExprError(); |
| 5419 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5420 | if (!getDerived().AlwaysRebuild() && |
| 5421 | Callee.get() == E->getCallee() && |
| 5422 | !ArgChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5423 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5425 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5426 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5427 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5428 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5429 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5430 | E->getRParenLoc()); |
| 5431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5432 | |
| 5433 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5434 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5435 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5436 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5437 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5438 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5439 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5440 | NestedNameSpecifier *Qualifier = 0; |
| 5441 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5442 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5443 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5444 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 5445 | if (Qualifier == 0) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5446 | return ExprError(); |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5447 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5448 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 5449 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5450 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 5451 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5452 | if (!Member) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5453 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5454 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5455 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 5456 | if (FoundDecl == E->getMemberDecl()) { |
| 5457 | FoundDecl = Member; |
| 5458 | } else { |
| 5459 | FoundDecl = cast_or_null<NamedDecl>( |
| 5460 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 5461 | if (!FoundDecl) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5462 | return ExprError(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5463 | } |
| 5464 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5465 | if (!getDerived().AlwaysRebuild() && |
| 5466 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5467 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5468 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5469 | FoundDecl == E->getFoundDecl() && |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5470 | !E->hasExplicitTemplateArgs()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5471 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5472 | // Mark it referenced in the new context regardless. |
| 5473 | // FIXME: this is a bit instantiation-specific. |
| 5474 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5475 | return SemaRef.Owned(E); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5476 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5477 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5478 | TemplateArgumentListInfo TransArgs; |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5479 | if (E->hasExplicitTemplateArgs()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5480 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5481 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5482 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5483 | E->getNumTemplateArgs(), |
| 5484 | TransArgs)) |
| 5485 | return ExprError(); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5486 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5488 | // FIXME: Bogus source location for the operator |
| 5489 | SourceLocation FakeOperatorLoc |
| 5490 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 5491 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5492 | // FIXME: to do this check properly, we will need to preserve the |
| 5493 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5494 | // base (and therefore couldn't do the check) and a |
| 5495 | // nested-name-qualifier (and therefore could do the lookup). |
| 5496 | NamedDecl *FirstQualifierInScope = 0; |
| 5497 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5498 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5500 | Qualifier, |
| 5501 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5502 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5503 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5504 | FoundDecl, |
John McCall | 096832c | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5505 | (E->hasExplicitTemplateArgs() |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5506 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5507 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5509 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5510 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5511 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5512 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5513 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5514 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5515 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5516 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5517 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5518 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5519 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5520 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5521 | if (!getDerived().AlwaysRebuild() && |
| 5522 | LHS.get() == E->getLHS() && |
| 5523 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5524 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5525 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5526 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5527 | LHS.get(), RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5528 | } |
| 5529 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5531 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5532 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5533 | CompoundAssignOperator *E) { |
| 5534 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5536 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5537 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5538 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5539 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5540 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5541 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5542 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5543 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5544 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5545 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5546 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5547 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5548 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5549 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5550 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5551 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5552 | if (!getDerived().AlwaysRebuild() && |
| 5553 | Cond.get() == E->getCond() && |
| 5554 | LHS.get() == E->getLHS() && |
| 5555 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5556 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5557 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5558 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5559 | E->getQuestionLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5560 | LHS.get(), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5561 | E->getColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5562 | RHS.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5564 | |
| 5565 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5566 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5567 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5568 | // Implicit casts are eliminated during transformation, since they |
| 5569 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5570 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5571 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5574 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5575 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5576 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5577 | if (!Type) |
| 5578 | return ExprError(); |
| 5579 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5580 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5581 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5582 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5583 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5585 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5586 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5587 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5588 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5589 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5590 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5591 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5592 | E->getRParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5593 | SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5594 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5597 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5598 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5599 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 5600 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 5601 | if (!NewT) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5602 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5604 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5605 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5606 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5608 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5609 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5610 | Init.get() == E->getInitializer()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5611 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5612 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 5613 | // Note: the expression type doesn't necessarily match the |
| 5614 | // type-as-written, but that's okay, because it should always be |
| 5615 | // derivable from the initializer. |
| 5616 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5617 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5618 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5619 | Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5620 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5622 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5623 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5624 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5625 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5626 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5627 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 5630 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5631 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5633 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5635 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5636 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5637 | E->getAccessorLoc(), |
| 5638 | E->getAccessor()); |
| 5639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5641 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5642 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5643 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5645 | |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5646 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5647 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 5648 | Inits, &InitChanged)) |
| 5649 | return ExprError(); |
| 5650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5651 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5652 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 5655 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5658 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5659 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5660 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5661 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5663 | // transform the initializer value |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5664 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5665 | if (Init.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5666 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5668 | // transform the designators. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5669 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5670 | bool ExprChanged = false; |
| 5671 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 5672 | DEnd = E->designators_end(); |
| 5673 | D != DEnd; ++D) { |
| 5674 | if (D->isFieldDesignator()) { |
| 5675 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 5676 | D->getDotLoc(), |
| 5677 | D->getFieldLoc())); |
| 5678 | continue; |
| 5679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5681 | if (D->isArrayDesignator()) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5682 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5683 | if (Index.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5684 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | |
| 5686 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5687 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5688 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5689 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 5690 | ArrayExprs.push_back(Index.release()); |
| 5691 | continue; |
| 5692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5695 | ExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5696 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 5697 | if (Start.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5698 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5699 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5700 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5701 | if (End.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5702 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5703 | |
| 5704 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5705 | End.get(), |
| 5706 | D->getLBracketLoc(), |
| 5707 | D->getEllipsisLoc())); |
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 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 5710 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5711 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5712 | ArrayExprs.push_back(Start.release()); |
| 5713 | ArrayExprs.push_back(End.release()); |
| 5714 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5715 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5716 | if (!getDerived().AlwaysRebuild() && |
| 5717 | Init.get() == E->getInit() && |
| 5718 | !ExprChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5719 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5720 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5721 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 5722 | E->getEqualOrColonLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5723 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5724 | } |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5727 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5728 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5729 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5730 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5731 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5732 | // FIXME: Will we ever have proper type location here? Will we actually |
| 5733 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5734 | QualType T = getDerived().TransformType(E->getType()); |
| 5735 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5736 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5737 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5738 | if (!getDerived().AlwaysRebuild() && |
| 5739 | T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5740 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5742 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 5743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5744 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5745 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5746 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5747 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 5748 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 5749 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5750 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5751 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5752 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5753 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5754 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5755 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5756 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 5757 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5758 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5759 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5760 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5761 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 5762 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5766 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5767 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5768 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5769 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5770 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 5771 | &ArgumentChanged)) |
| 5772 | return ExprError(); |
| 5773 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5774 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 5775 | move_arg(Inits), |
| 5776 | E->getRParenLoc()); |
| 5777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5779 | /// \brief Transform an address-of-label expression. |
| 5780 | /// |
| 5781 | /// By default, the transformation of an address-of-label expression always |
| 5782 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 5783 | /// the corresponding label statement by semantic analysis. |
| 5784 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5785 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5786 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5787 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 5788 | E->getLabel()); |
| 5789 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5790 | |
| 5791 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5792 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5793 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5794 | StmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5795 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 5796 | if (SubStmt.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5797 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5798 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5799 | if (!getDerived().AlwaysRebuild() && |
| 5800 | SubStmt.get() == E->getSubStmt()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5801 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5802 | |
| 5803 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5804 | SubStmt.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5805 | E->getRParenLoc()); |
| 5806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5807 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5808 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5809 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5810 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5811 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5812 | if (Cond.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5813 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5814 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5815 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5816 | if (LHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5817 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5818 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5819 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5820 | if (RHS.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5821 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5823 | if (!getDerived().AlwaysRebuild() && |
| 5824 | Cond.get() == E->getCond() && |
| 5825 | LHS.get() == E->getLHS() && |
| 5826 | RHS.get() == E->getRHS()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5827 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5829 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5830 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5831 | E->getRParenLoc()); |
| 5832 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5834 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5835 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5836 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5837 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5841 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5842 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5843 | switch (E->getOperator()) { |
| 5844 | case OO_New: |
| 5845 | case OO_Delete: |
| 5846 | case OO_Array_New: |
| 5847 | case OO_Array_Delete: |
| 5848 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5849 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5850 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5851 | case OO_Call: { |
| 5852 | // This is a call to an object's operator(). |
| 5853 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 5854 | |
| 5855 | // Transform the object itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5856 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5857 | if (Object.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5858 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5859 | |
| 5860 | // FIXME: Poor location information |
| 5861 | SourceLocation FakeLParenLoc |
| 5862 | = SemaRef.PP.getLocForEndOfToken( |
| 5863 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 5864 | |
| 5865 | // Transform the call arguments. |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5866 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5867 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 5868 | Args)) |
| 5869 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5870 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5871 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5872 | move_arg(Args), |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5873 | E->getLocEnd()); |
| 5874 | } |
| 5875 | |
| 5876 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 5877 | case OO_##Name: |
| 5878 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 5879 | #include "clang/Basic/OperatorKinds.def" |
| 5880 | case OO_Subscript: |
| 5881 | // Handled below. |
| 5882 | break; |
| 5883 | |
| 5884 | case OO_Conditional: |
| 5885 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5886 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5887 | |
| 5888 | case OO_None: |
| 5889 | case NUM_OVERLOADED_OPERATORS: |
| 5890 | llvm_unreachable("not an overloaded operator?"); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5891 | return ExprError(); |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5894 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5895 | if (Callee.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5896 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5897 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5898 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5899 | if (First.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5900 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5901 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5902 | ExprResult Second; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5903 | if (E->getNumArgs() == 2) { |
| 5904 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 5905 | if (Second.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5906 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5907 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5908 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5909 | if (!getDerived().AlwaysRebuild() && |
| 5910 | Callee.get() == E->getCallee() && |
| 5911 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5912 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5913 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5914 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5915 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 5916 | E->getOperatorLoc(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5917 | Callee.get(), |
| 5918 | First.get(), |
| 5919 | Second.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5920 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5921 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5922 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5923 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5924 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5925 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5926 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5927 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5928 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5929 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5930 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5931 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5932 | if (!Type) |
| 5933 | return ExprError(); |
| 5934 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5935 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5936 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5937 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5938 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5939 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5940 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5941 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5942 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5943 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5944 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5945 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5946 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5947 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5948 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 5949 | SourceLocation FakeRParenLoc |
| 5950 | = SemaRef.PP.getLocForEndOfToken( |
| 5951 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5952 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5953 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5954 | FakeLAngleLoc, |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5955 | Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5956 | FakeRAngleLoc, |
| 5957 | FakeRAngleLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5958 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5959 | FakeRParenLoc); |
| 5960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5961 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5962 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5963 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5964 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5965 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5966 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5967 | |
| 5968 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5969 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5970 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5971 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5972 | } |
| 5973 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5974 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5975 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5976 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5977 | CXXReinterpretCastExpr *E) { |
| 5978 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5979 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5981 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5982 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5983 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5984 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5986 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5987 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5988 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5989 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5990 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5991 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5992 | if (!Type) |
| 5993 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5994 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5995 | ExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5996 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5997 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5998 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5999 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6000 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6001 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6002 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6003 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6004 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6005 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6006 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6007 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6008 | E->getRParenLoc()); |
| 6009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6011 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6012 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6013 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6014 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6015 | TypeSourceInfo *TInfo |
| 6016 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6017 | if (!TInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6018 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6020 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6021 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6022 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6024 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6025 | E->getLocStart(), |
| 6026 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6027 | E->getLocEnd()); |
| 6028 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6029 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6030 | // We don't know whether the expression is potentially evaluated until |
| 6031 | // after we perform semantic analysis, so the expression is potentially |
| 6032 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6033 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6034 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6035 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6036 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6037 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6038 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6039 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6040 | if (!getDerived().AlwaysRebuild() && |
| 6041 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6042 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6043 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6044 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6045 | E->getLocStart(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6046 | SubExpr.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6047 | E->getLocEnd()); |
| 6048 | } |
| 6049 | |
| 6050 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6051 | ExprResult |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6052 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6053 | if (E->isTypeOperand()) { |
| 6054 | TypeSourceInfo *TInfo |
| 6055 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6056 | if (!TInfo) |
| 6057 | return ExprError(); |
| 6058 | |
| 6059 | if (!getDerived().AlwaysRebuild() && |
| 6060 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6061 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6062 | |
| 6063 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6064 | E->getLocStart(), |
| 6065 | TInfo, |
| 6066 | E->getLocEnd()); |
| 6067 | } |
| 6068 | |
| 6069 | // We don't know whether the expression is potentially evaluated until |
| 6070 | // after we perform semantic analysis, so the expression is potentially |
| 6071 | // potentially evaluated. |
| 6072 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6073 | |
| 6074 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6075 | if (SubExpr.isInvalid()) |
| 6076 | return ExprError(); |
| 6077 | |
| 6078 | if (!getDerived().AlwaysRebuild() && |
| 6079 | SubExpr.get() == E->getExprOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6080 | return SemaRef.Owned(E); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6081 | |
| 6082 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6083 | E->getLocStart(), |
| 6084 | SubExpr.get(), |
| 6085 | E->getLocEnd()); |
| 6086 | } |
| 6087 | |
| 6088 | template<typename Derived> |
| 6089 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6090 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6091 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6092 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6094 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6095 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6096 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6097 | CXXNullPtrLiteralExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6098 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6100 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6101 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6102 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6103 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6104 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
| 6105 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); |
| 6106 | QualType T = MD->getThisType(getSema().Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6107 | |
Douglas Gregor | ba48d6a | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6108 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6109 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6110 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6111 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6113 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6114 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6115 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6116 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6117 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6118 | if (SubExpr.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6119 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6121 | if (!getDerived().AlwaysRebuild() && |
| 6122 | SubExpr.get() == E->getSubExpr()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6123 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6124 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6125 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6128 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6129 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6130 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6131 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6132 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6133 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6134 | if (!Param) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6135 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6136 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6137 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6138 | Param == E->getParam()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6139 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6140 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6141 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6145 | ExprResult |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6146 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6147 | CXXScalarValueInitExpr *E) { |
| 6148 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6149 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6150 | return ExprError(); |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6151 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6152 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6153 | T == E->getTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6154 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6155 | |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6156 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6157 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6158 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6160 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6161 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6162 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6163 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6164 | // Transform the type that we're allocating |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6165 | TypeSourceInfo *AllocTypeInfo |
| 6166 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6167 | if (!AllocTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6168 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6169 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6170 | // Transform the size of the array we're allocating (if any). |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6171 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6172 | if (ArraySize.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6173 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6174 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6175 | // Transform the placement arguments (if any). |
| 6176 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6177 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6178 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6179 | E->getNumPlacementArgs(), true, |
| 6180 | PlacementArgs, &ArgumentChanged)) |
| 6181 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6182 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6183 | // transform the constructor arguments (if any). |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6184 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6185 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6186 | ConstructorArgs, &ArgumentChanged)) |
| 6187 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6188 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6189 | // Transform constructor, new operator, and delete operator. |
| 6190 | CXXConstructorDecl *Constructor = 0; |
| 6191 | if (E->getConstructor()) { |
| 6192 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6193 | getDerived().TransformDecl(E->getLocStart(), |
| 6194 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6195 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6196 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | FunctionDecl *OperatorNew = 0; |
| 6200 | if (E->getOperatorNew()) { |
| 6201 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6202 | getDerived().TransformDecl(E->getLocStart(), |
| 6203 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6204 | if (!OperatorNew) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6205 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | FunctionDecl *OperatorDelete = 0; |
| 6209 | if (E->getOperatorDelete()) { |
| 6210 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6211 | getDerived().TransformDecl(E->getLocStart(), |
| 6212 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6213 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6214 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6215 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6216 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6217 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6218 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6219 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6220 | Constructor == E->getConstructor() && |
| 6221 | OperatorNew == E->getOperatorNew() && |
| 6222 | OperatorDelete == E->getOperatorDelete() && |
| 6223 | !ArgumentChanged) { |
| 6224 | // Mark any declarations we need as referenced. |
| 6225 | // FIXME: instantiation-specific. |
| 6226 | if (Constructor) |
| 6227 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6228 | if (OperatorNew) |
| 6229 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6230 | if (OperatorDelete) |
| 6231 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6232 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6233 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6234 | |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6235 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6236 | if (!ArraySize.get()) { |
| 6237 | // If no array size was specified, but the new expression was |
| 6238 | // instantiated with an array type (e.g., "new T" where T is |
| 6239 | // instantiated with "int[4]"), extract the outer bound from the |
| 6240 | // array type as our array size. We do this with constant and |
| 6241 | // dependently-sized array types. |
| 6242 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6243 | if (!ArrayT) { |
| 6244 | // Do nothing |
| 6245 | } else if (const ConstantArrayType *ConsArrayT |
| 6246 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6247 | ArraySize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6248 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6249 | ConsArrayT->getSize(), |
| 6250 | SemaRef.Context.getSizeType(), |
| 6251 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6252 | AllocType = ConsArrayT->getElementType(); |
| 6253 | } else if (const DependentSizedArrayType *DepArrayT |
| 6254 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6255 | if (DepArrayT->getSizeExpr()) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6256 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6257 | AllocType = DepArrayT->getElementType(); |
| 6258 | } |
| 6259 | } |
| 6260 | } |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6261 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6262 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6263 | E->isGlobalNew(), |
| 6264 | /*FIXME:*/E->getLocStart(), |
| 6265 | move_arg(PlacementArgs), |
| 6266 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6267 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6268 | AllocType, |
Douglas Gregor | 1bb2a93 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6269 | AllocTypeInfo, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6270 | ArraySize.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6271 | /*FIXME:*/E->getLocStart(), |
| 6272 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6273 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6275 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6276 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6277 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6278 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6279 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6280 | if (Operand.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6281 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6282 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6283 | // Transform the delete operator, if known. |
| 6284 | FunctionDecl *OperatorDelete = 0; |
| 6285 | if (E->getOperatorDelete()) { |
| 6286 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6287 | getDerived().TransformDecl(E->getLocStart(), |
| 6288 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6289 | if (!OperatorDelete) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6290 | return ExprError(); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6291 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6292 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6293 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6294 | Operand.get() == E->getArgument() && |
| 6295 | OperatorDelete == E->getOperatorDelete()) { |
| 6296 | // Mark any declarations we need as referenced. |
| 6297 | // FIXME: instantiation-specific. |
| 6298 | if (OperatorDelete) |
| 6299 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 5833b0b | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 6300 | |
| 6301 | if (!E->getArgument()->isTypeDependent()) { |
| 6302 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 6303 | E->getDestroyedType()); |
| 6304 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 6305 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 6306 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 6307 | SemaRef.LookupDestructor(Record)); |
| 6308 | } |
| 6309 | } |
| 6310 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6311 | return SemaRef.Owned(E); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6313 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6314 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 6315 | E->isGlobalDelete(), |
| 6316 | E->isArrayForm(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6317 | Operand.get()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6319 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6320 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6321 | ExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6322 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6323 | CXXPseudoDestructorExpr *E) { |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6324 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6325 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6326 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6327 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6328 | ParsedType ObjectTypePtr; |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6329 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6330 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6331 | E->getOperatorLoc(), |
| 6332 | E->isArrow()? tok::arrow : tok::period, |
| 6333 | ObjectTypePtr, |
| 6334 | MayBePseudoDestructor); |
| 6335 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6336 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6337 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6338 | QualType ObjectType = ObjectTypePtr.get(); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6339 | NestedNameSpecifier *Qualifier = E->getQualifier(); |
| 6340 | if (Qualifier) { |
| 6341 | Qualifier |
| 6342 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 6343 | E->getQualifierRange(), |
| 6344 | ObjectType); |
| 6345 | if (!Qualifier) |
| 6346 | return ExprError(); |
| 6347 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6348 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6349 | PseudoDestructorTypeStorage Destroyed; |
| 6350 | if (E->getDestroyedTypeInfo()) { |
| 6351 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6352 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
| 6353 | ObjectType, 0, Qualifier); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6354 | if (!DestroyedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6355 | return ExprError(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6356 | Destroyed = DestroyedTypeInfo; |
| 6357 | } else if (ObjectType->isDependentType()) { |
| 6358 | // We aren't likely to be able to resolve the identifier down to a type |
| 6359 | // now anyway, so just retain the identifier. |
| 6360 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 6361 | E->getDestroyedTypeLoc()); |
| 6362 | } else { |
| 6363 | // Look for a destructor known with the given name. |
| 6364 | CXXScopeSpec SS; |
| 6365 | if (Qualifier) { |
| 6366 | SS.setScopeRep(Qualifier); |
| 6367 | SS.setRange(E->getQualifierRange()); |
| 6368 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6369 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6370 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6371 | *E->getDestroyedTypeIdentifier(), |
| 6372 | E->getDestroyedTypeLoc(), |
| 6373 | /*Scope=*/0, |
| 6374 | SS, ObjectTypePtr, |
| 6375 | false); |
| 6376 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6377 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6378 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6379 | Destroyed |
| 6380 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 6381 | E->getDestroyedTypeLoc()); |
| 6382 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6383 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6384 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 6385 | if (E->getScopeTypeInfo()) { |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6386 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6387 | if (!ScopeTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6388 | return ExprError(); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6389 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6390 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6391 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6392 | E->getOperatorLoc(), |
| 6393 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6394 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6395 | E->getQualifierRange(), |
| 6396 | ScopeTypeInfo, |
| 6397 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6398 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6399 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6400 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6401 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6402 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6403 | ExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6404 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6405 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6406 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 6407 | |
| 6408 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 6409 | Sema::LookupOrdinaryName); |
| 6410 | |
| 6411 | // Transform all the decls. |
| 6412 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 6413 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6414 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6415 | getDerived().TransformDecl(Old->getNameLoc(), |
| 6416 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6417 | if (!InstD) { |
| 6418 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6419 | // This can happen because of dependent hiding. |
| 6420 | if (isa<UsingShadowDecl>(*I)) |
| 6421 | continue; |
| 6422 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6423 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6424 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6425 | |
| 6426 | // Expand using declarations. |
| 6427 | if (isa<UsingDecl>(InstD)) { |
| 6428 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6429 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6430 | E = UD->shadow_end(); I != E; ++I) |
| 6431 | R.addDecl(*I); |
| 6432 | continue; |
| 6433 | } |
| 6434 | |
| 6435 | R.addDecl(InstD); |
| 6436 | } |
| 6437 | |
| 6438 | // Resolve a kind, but don't do any further analysis. If it's |
| 6439 | // ambiguous, the callee needs to deal with it. |
| 6440 | R.resolveKind(); |
| 6441 | |
| 6442 | // Rebuild the nested-name qualifier, if present. |
| 6443 | CXXScopeSpec SS; |
| 6444 | NestedNameSpecifier *Qualifier = 0; |
| 6445 | if (Old->getQualifier()) { |
| 6446 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6447 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6448 | if (!Qualifier) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6449 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6450 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6451 | SS.setScopeRep(Qualifier); |
| 6452 | SS.setRange(Old->getQualifierRange()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6453 | } |
| 6454 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6455 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6456 | CXXRecordDecl *NamingClass |
| 6457 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 6458 | Old->getNameLoc(), |
| 6459 | Old->getNamingClass())); |
| 6460 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6461 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6462 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6463 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | // If we have no template arguments, it's a normal declaration name. |
| 6467 | if (!Old->hasExplicitTemplateArgs()) |
| 6468 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 6469 | |
| 6470 | // If we have template arguments, rebuild them, then rebuild the |
| 6471 | // templateid expression. |
| 6472 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6473 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6474 | Old->getNumTemplateArgs(), |
| 6475 | TransArgs)) |
| 6476 | return ExprError(); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6477 | |
| 6478 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 6479 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6482 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6483 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6484 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6485 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 6486 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6487 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6488 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6489 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3d37c0a | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6490 | T == E->getQueriedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6491 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6492 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6494 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6495 | T, |
| 6496 | E->getLocEnd()); |
| 6497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6498 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6499 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6500 | ExprResult |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 6501 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 6502 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 6503 | if (!LhsT) |
| 6504 | return ExprError(); |
| 6505 | |
| 6506 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 6507 | if (!RhsT) |
| 6508 | return ExprError(); |
| 6509 | |
| 6510 | if (!getDerived().AlwaysRebuild() && |
| 6511 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 6512 | return SemaRef.Owned(E); |
| 6513 | |
| 6514 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 6515 | E->getLocStart(), |
| 6516 | LhsT, RhsT, |
| 6517 | E->getLocEnd()); |
| 6518 | } |
| 6519 | |
| 6520 | template<typename Derived> |
| 6521 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6522 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6523 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6524 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6525 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6526 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6527 | if (!NNS) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6528 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6529 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6530 | // TODO: If this is a conversion-function-id, verify that the |
| 6531 | // destination type name (if present) resolves the same way after |
| 6532 | // instantiation as it did in the local scope. |
| 6533 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6534 | DeclarationNameInfo NameInfo |
| 6535 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 6536 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6537 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6538 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6539 | if (!E->hasExplicitTemplateArgs()) { |
| 6540 | if (!getDerived().AlwaysRebuild() && |
| 6541 | NNS == E->getQualifier() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6542 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 6543 | // if name has not changed, DNLoc has not changed either. |
| 6544 | NameInfo.getName() == E->getDeclName()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6545 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6546 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6547 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 6548 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6549 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6550 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6551 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6552 | |
| 6553 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6554 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6555 | E->getNumTemplateArgs(), |
| 6556 | TransArgs)) |
| 6557 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6558 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6559 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 6560 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6561 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6562 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6566 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6567 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 6568 | // CXXConstructExprs are always implicit, so when we have a |
| 6569 | // 1-argument construction we just transform that argument. |
| 6570 | if (E->getNumArgs() == 1 || |
| 6571 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 6572 | return getDerived().TransformExpr(E->getArg(0)); |
| 6573 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6574 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 6575 | |
| 6576 | QualType T = getDerived().TransformType(E->getType()); |
| 6577 | if (T.isNull()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6578 | return ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6579 | |
| 6580 | CXXConstructorDecl *Constructor |
| 6581 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6582 | getDerived().TransformDecl(E->getLocStart(), |
| 6583 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6584 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6585 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6586 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6587 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6588 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6589 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6590 | &ArgumentChanged)) |
| 6591 | return ExprError(); |
| 6592 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6593 | if (!getDerived().AlwaysRebuild() && |
| 6594 | T == E->getType() && |
| 6595 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6596 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6597 | // Mark the constructor as referenced. |
| 6598 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6599 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6600 | return SemaRef.Owned(E); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6601 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6602 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 6603 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 6604 | Constructor, E->isElidable(), |
Douglas Gregor | 8c3e554 | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 6605 | move_arg(Args), |
| 6606 | E->requiresZeroInitialization(), |
Chandler Carruth | 428edaf | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 6607 | E->getConstructionKind(), |
| 6608 | E->getParenRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6610 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6611 | /// \brief Transform a C++ temporary-binding expression. |
| 6612 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6613 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 6614 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6615 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6616 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6617 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6618 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6620 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6621 | /// \brief Transform a C++ expression that contains cleanups that should |
| 6622 | /// be run after the expression is evaluated. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6623 | /// |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6624 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6625 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6626 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6627 | ExprResult |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6628 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6629 | return getDerived().TransformExpr(E->getSubExpr()); |
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 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6633 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6634 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6635 | CXXTemporaryObjectExpr *E) { |
| 6636 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6637 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6638 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6639 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6640 | CXXConstructorDecl *Constructor |
| 6641 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6642 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6643 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6644 | if (!Constructor) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6645 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6646 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6647 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6648 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6649 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6650 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6651 | &ArgumentChanged)) |
| 6652 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6655 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6656 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6657 | !ArgumentChanged) { |
| 6658 | // FIXME: Instantiation-specific |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6659 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6660 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6661 | } |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6662 | |
| 6663 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 6664 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6666 | E->getLocEnd()); |
| 6667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6669 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6670 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6671 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6672 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6673 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6674 | if (!T) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6675 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6676 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6677 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6678 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6679 | Args.reserve(E->arg_size()); |
| 6680 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 6681 | &ArgumentChanged)) |
| 6682 | return ExprError(); |
| 6683 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6684 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6685 | T == E->getTypeSourceInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6686 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6687 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6688 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6689 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | ab6677e | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6690 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6691 | E->getLParenLoc(), |
| 6692 | move_arg(Args), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6693 | E->getRParenLoc()); |
| 6694 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6695 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6696 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6697 | ExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6698 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6699 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6700 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6701 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6702 | Expr *OldBase; |
| 6703 | QualType BaseType; |
| 6704 | QualType ObjectType; |
| 6705 | if (!E->isImplicitAccess()) { |
| 6706 | OldBase = E->getBase(); |
| 6707 | Base = getDerived().TransformExpr(OldBase); |
| 6708 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6709 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6710 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6711 | // Start the member reference and compute the object's type. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6712 | ParsedType ObjectTy; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 6713 | bool MayBePseudoDestructor = false; |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6714 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6715 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6716 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 6717 | ObjectTy, |
| 6718 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6719 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6720 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6721 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6722 | ObjectType = ObjectTy.get(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6723 | BaseType = ((Expr*) Base.get())->getType(); |
| 6724 | } else { |
| 6725 | OldBase = 0; |
| 6726 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 6727 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 6728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6729 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 6730 | // Transform the first part of the nested-name-specifier that qualifies |
| 6731 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6732 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 6733 | = getDerived().TransformFirstQualifierInScope( |
| 6734 | E->getFirstQualifierFoundInScope(), |
| 6735 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6736 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6737 | NestedNameSpecifier *Qualifier = 0; |
| 6738 | if (E->getQualifier()) { |
| 6739 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 6740 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6741 | ObjectType, |
| 6742 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6743 | if (!Qualifier) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6744 | return ExprError(); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6745 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6746 | |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6747 | // TODO: If this is a conversion-function-id, verify that the |
| 6748 | // destination type name (if present) resolves the same way after |
| 6749 | // instantiation as it did in the local scope. |
| 6750 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6751 | DeclarationNameInfo NameInfo |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6752 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6753 | if (!NameInfo.getName()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6754 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6755 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6756 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6757 | // This is a reference to a member without an explicitly-specified |
| 6758 | // template argument list. Optimize for this common case. |
| 6759 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6760 | Base.get() == OldBase && |
| 6761 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6762 | Qualifier == E->getQualifier() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6763 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6764 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6765 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6766 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6767 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6768 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6769 | E->isArrow(), |
| 6770 | E->getOperatorLoc(), |
| 6771 | Qualifier, |
| 6772 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6773 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6774 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6775 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6776 | } |
| 6777 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6778 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6779 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6780 | E->getNumTemplateArgs(), |
| 6781 | TransArgs)) |
| 6782 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6783 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6784 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6785 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6786 | E->isArrow(), |
| 6787 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6788 | Qualifier, |
| 6789 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6790 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6791 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6792 | &TransArgs); |
| 6793 | } |
| 6794 | |
| 6795 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6796 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6797 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6798 | // Transform the base of the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6799 | ExprResult Base((Expr*) 0); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6800 | QualType BaseType; |
| 6801 | if (!Old->isImplicitAccess()) { |
| 6802 | Base = getDerived().TransformExpr(Old->getBase()); |
| 6803 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6804 | return ExprError(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6805 | BaseType = ((Expr*) Base.get())->getType(); |
| 6806 | } else { |
| 6807 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 6808 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6809 | |
| 6810 | NestedNameSpecifier *Qualifier = 0; |
| 6811 | if (Old->getQualifier()) { |
| 6812 | Qualifier |
| 6813 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6814 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6815 | if (Qualifier == 0) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6816 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6819 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6820 | Sema::LookupOrdinaryName); |
| 6821 | |
| 6822 | // Transform all the decls. |
| 6823 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 6824 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6825 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6826 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 6827 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6828 | if (!InstD) { |
| 6829 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6830 | // This can happen because of dependent hiding. |
| 6831 | if (isa<UsingShadowDecl>(*I)) |
| 6832 | continue; |
| 6833 | else |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6834 | return ExprError(); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6835 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6836 | |
| 6837 | // Expand using declarations. |
| 6838 | if (isa<UsingDecl>(InstD)) { |
| 6839 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6840 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6841 | E = UD->shadow_end(); I != E; ++I) |
| 6842 | R.addDecl(*I); |
| 6843 | continue; |
| 6844 | } |
| 6845 | |
| 6846 | R.addDecl(InstD); |
| 6847 | } |
| 6848 | |
| 6849 | R.resolveKind(); |
| 6850 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6851 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 6852 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6853 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6854 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6855 | Old->getMemberLoc(), |
| 6856 | Old->getNamingClass())); |
| 6857 | if (!NamingClass) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6858 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6859 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6860 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6861 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6862 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6863 | TemplateArgumentListInfo TransArgs; |
| 6864 | if (Old->hasExplicitTemplateArgs()) { |
| 6865 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 6866 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | fcc1253 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6867 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6868 | Old->getNumTemplateArgs(), |
| 6869 | TransArgs)) |
| 6870 | return ExprError(); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6871 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6872 | |
| 6873 | // FIXME: to do this check properly, we will need to preserve the |
| 6874 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6875 | // base (and therefore couldn't do the check) and a |
| 6876 | // nested-name-qualifier (and therefore could do the lookup). |
| 6877 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6878 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6879 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6880 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6881 | Old->getOperatorLoc(), |
| 6882 | Old->isArrow(), |
| 6883 | Qualifier, |
| 6884 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6885 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6886 | R, |
| 6887 | (Old->hasExplicitTemplateArgs() |
| 6888 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6892 | ExprResult |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 6893 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6894 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 6895 | if (SubExpr.isInvalid()) |
| 6896 | return ExprError(); |
| 6897 | |
| 6898 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6899 | return SemaRef.Owned(E); |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 6900 | |
| 6901 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 6902 | } |
| 6903 | |
| 6904 | template<typename Derived> |
| 6905 | ExprResult |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6906 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 4f1d282 | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 6907 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 6908 | if (Pattern.isInvalid()) |
| 6909 | return ExprError(); |
| 6910 | |
| 6911 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 6912 | return SemaRef.Owned(E); |
| 6913 | |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 6914 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 6915 | E->getNumExpansions()); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6916 | } |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6917 | |
| 6918 | template<typename Derived> |
| 6919 | ExprResult |
| 6920 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6921 | // If E is not value-dependent, then nothing will change when we transform it. |
| 6922 | // Note: This is an instantiation-centric view. |
| 6923 | if (!E->isValueDependent()) |
| 6924 | return SemaRef.Owned(E); |
| 6925 | |
| 6926 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 6927 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 6928 | // so |
| 6929 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 6930 | bool ShouldExpand = false; |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 6931 | bool RetainExpansion = false; |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6932 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6933 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 6934 | &Unexpanded, 1, |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 6935 | ShouldExpand, RetainExpansion, |
| 6936 | NumExpansions)) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6937 | return ExprError(); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6938 | |
Douglas Gregor | d373119 | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 6939 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6940 | return SemaRef.Owned(E); |
| 6941 | |
| 6942 | // We now know the length of the parameter pack, so build a new expression |
| 6943 | // that stores that length. |
| 6944 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 6945 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6946 | *NumExpansions); |
Douglas Gregor | ee8aff0 | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 6947 | } |
| 6948 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 6949 | template<typename Derived> |
| 6950 | ExprResult |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 6951 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 6952 | SubstNonTypeTemplateParmPackExpr *E) { |
| 6953 | // Default behavior is to do nothing with this transformation. |
| 6954 | return SemaRef.Owned(E); |
| 6955 | } |
| 6956 | |
| 6957 | template<typename Derived> |
| 6958 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6959 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6960 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6961 | } |
| 6962 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6963 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6964 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6965 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6966 | TypeSourceInfo *EncodedTypeInfo |
| 6967 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 6968 | if (!EncodedTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6969 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6971 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6972 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6973 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6974 | |
| 6975 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6976 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6977 | E->getRParenLoc()); |
| 6978 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6979 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6980 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6981 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6982 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6983 | // Transform arguments. |
| 6984 | bool ArgChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6985 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6986 | Args.reserve(E->getNumArgs()); |
| 6987 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 6988 | &ArgChanged)) |
| 6989 | return ExprError(); |
| 6990 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6991 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 6992 | // Class message: transform the receiver type. |
| 6993 | TypeSourceInfo *ReceiverTypeInfo |
| 6994 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 6995 | if (!ReceiverTypeInfo) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6996 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6997 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6998 | // If nothing changed, just retain the existing message send. |
| 6999 | if (!getDerived().AlwaysRebuild() && |
| 7000 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7001 | return SemaRef.Owned(E); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7002 | |
| 7003 | // Build a new class message send. |
| 7004 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7005 | E->getSelector(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7006 | E->getSelectorLoc(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7007 | E->getMethodDecl(), |
| 7008 | E->getLeftLoc(), |
| 7009 | move_arg(Args), |
| 7010 | E->getRightLoc()); |
| 7011 | } |
| 7012 | |
| 7013 | // Instance message: transform the receiver |
| 7014 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7015 | "Only class and instance messages may be instantiated"); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7016 | ExprResult Receiver |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7017 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7018 | if (Receiver.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7019 | return ExprError(); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7020 | |
| 7021 | // If nothing changed, just retain the existing message send. |
| 7022 | if (!getDerived().AlwaysRebuild() && |
| 7023 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7024 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7025 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7026 | // Build a new instance message send. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7027 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7028 | E->getSelector(), |
Argyrios Kyrtzidis | f40f0d5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7029 | E->getSelectorLoc(), |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7030 | E->getMethodDecl(), |
| 7031 | E->getLeftLoc(), |
| 7032 | move_arg(Args), |
| 7033 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7034 | } |
| 7035 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7036 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7037 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7038 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7039 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7040 | } |
| 7041 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7042 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7043 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7044 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7045 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7046 | } |
| 7047 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7048 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7049 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7050 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7051 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7052 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7053 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7054 | return ExprError(); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7055 | |
| 7056 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7057 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7058 | // If nothing changed, just retain the existing expression. |
| 7059 | if (!getDerived().AlwaysRebuild() && |
| 7060 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7061 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7062 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7063 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7064 | E->getLocation(), |
| 7065 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7066 | } |
| 7067 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7068 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7069 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7070 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7071 | // 'super' and types never change. Property never changes. Just |
| 7072 | // retain the existing expression. |
| 7073 | if (!E->isObjectReceiver()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7074 | return SemaRef.Owned(E); |
Fariborz Jahanian | 8ac2d44 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7075 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7076 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7077 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7078 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7079 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7080 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7081 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7082 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7083 | // If nothing changed, just retain the existing expression. |
| 7084 | if (!getDerived().AlwaysRebuild() && |
| 7085 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7086 | return SemaRef.Owned(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7087 | |
John McCall | 12f78a6 | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7088 | if (E->isExplicitProperty()) |
| 7089 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7090 | E->getExplicitProperty(), |
| 7091 | E->getLocation()); |
| 7092 | |
| 7093 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7094 | E->getType(), |
| 7095 | E->getImplicitPropertyGetter(), |
| 7096 | E->getImplicitPropertySetter(), |
| 7097 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7098 | } |
| 7099 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7100 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7101 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7102 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7103 | // Transform the base expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7104 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7105 | if (Base.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7106 | return ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7107 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7108 | // If nothing changed, just retain the existing expression. |
| 7109 | if (!getDerived().AlwaysRebuild() && |
| 7110 | Base.get() == E->getBase()) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7111 | return SemaRef.Owned(E); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7112 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7113 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7114 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7115 | } |
| 7116 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7117 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7118 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7119 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7120 | bool ArgumentChanged = false; |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7121 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | aa165f8 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7122 | SubExprs.reserve(E->getNumSubExprs()); |
| 7123 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7124 | SubExprs, &ArgumentChanged)) |
| 7125 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7127 | if (!getDerived().AlwaysRebuild() && |
| 7128 | !ArgumentChanged) |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7129 | return SemaRef.Owned(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7130 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7131 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7132 | move_arg(SubExprs), |
| 7133 | E->getRParenLoc()); |
| 7134 | } |
| 7135 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7136 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7137 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7138 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7139 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7140 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7141 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7142 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7143 | |
| 7144 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 7145 | llvm::SmallVector<ParmVarDecl*, 4> params; |
| 7146 | llvm::SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7147 | |
| 7148 | // Parameter substitution. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7149 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7150 | oldBlock->param_begin(), |
| 7151 | oldBlock->param_size(), |
| 7152 | 0, paramTypes, ¶ms)) |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7153 | return true; |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7154 | |
| 7155 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7156 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7157 | if (!exprResultType.isNull()) { |
| 7158 | if (!exprResultType->isDependentType()) |
| 7159 | blockScope->ReturnType = exprResultType; |
| 7160 | else if (exprResultType != getSema().Context.DependentTy) |
| 7161 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7162 | } |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7163 | |
| 7164 | // If the return type has not been determined yet, leave it as a dependent |
| 7165 | // type; it'll get set when we process the body. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7166 | if (blockScope->ReturnType.isNull()) |
| 7167 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7168 | |
| 7169 | // Don't allow returning a objc interface by value. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7170 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7171 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7172 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7173 | << 0 << blockScope->ReturnType; |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7174 | return ExprError(); |
| 7175 | } |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7176 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7177 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7178 | blockScope->ReturnType, |
| 7179 | paramTypes.data(), |
| 7180 | paramTypes.size(), |
| 7181 | oldBlock->isVariadic(), |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7182 | 0, RQ_None, |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7183 | exprFunctionType->getExtInfo()); |
| 7184 | blockScope->FunctionType = functionType; |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7185 | |
| 7186 | // Set the parameters on the block decl. |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7187 | if (!params.empty()) |
| 7188 | blockScope->TheDecl->setParams(params.data(), params.size()); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7189 | |
| 7190 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7191 | // dependent type (DependentTy); clear out the return type setting so |
| 7192 | // 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] | 7193 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7194 | blockScope->ReturnType = QualType(); |
Douglas Gregor | a779d9c | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7195 | |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7196 | // Transform the body |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7197 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7198 | if (body.isInvalid()) |
John McCall | 711c52b | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7199 | return ExprError(); |
| 7200 | |
John McCall | c6ac9c3 | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7201 | #ifndef NDEBUG |
| 7202 | // In builds with assertions, make sure that we captured everything we |
| 7203 | // captured before. |
| 7204 | |
| 7205 | if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); |
| 7206 | |
| 7207 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 7208 | e = oldBlock->capture_end(); i != e; ++i) { |
| 7209 | VarDecl *oldCapture = *i; |
| 7210 | |
| 7211 | // Ignore parameter packs. |
| 7212 | if (isa<ParmVarDecl>(oldCapture) && |
| 7213 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 7214 | continue; |
| 7215 | |
| 7216 | VarDecl *newCapture = |
| 7217 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 7218 | oldCapture)); |
| 7219 | assert(blockScope->Captures.count(newCapture)); |
| 7220 | } |
| 7221 | #endif |
| 7222 | |
| 7223 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 7224 | /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7225 | } |
| 7226 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7227 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7228 | ExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7229 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7230 | NestedNameSpecifier *Qualifier = 0; |
| 7231 | |
| 7232 | ValueDecl *ND |
| 7233 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7234 | E->getDecl())); |
| 7235 | if (!ND) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7236 | return ExprError(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7237 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7238 | if (!getDerived().AlwaysRebuild() && |
| 7239 | ND == E->getDecl()) { |
| 7240 | // Mark it referenced in the new context regardless. |
| 7241 | // FIXME: this is a bit instantiation-specific. |
| 7242 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 7243 | |
John McCall | 3fa5cae | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7244 | return SemaRef.Owned(E); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7247 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7248 | return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7249 | ND, NameInfo, 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7251 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7252 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7253 | // Type reconstruction |
| 7254 | //===----------------------------------------------------------------------===// |
| 7255 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7256 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7257 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 7258 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7259 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7260 | getDerived().getBaseEntity()); |
| 7261 | } |
| 7262 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7263 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7264 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 7265 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7266 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7267 | getDerived().getBaseEntity()); |
| 7268 | } |
| 7269 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7270 | template<typename Derived> |
| 7271 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7272 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 7273 | bool WrittenAsLValue, |
| 7274 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7275 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7276 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7277 | } |
| 7278 | |
| 7279 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7280 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7281 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 7282 | QualType ClassType, |
| 7283 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7284 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7285 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7289 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7290 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 7291 | ArrayType::ArraySizeModifier SizeMod, |
| 7292 | const llvm::APInt *Size, |
| 7293 | Expr *SizeExpr, |
| 7294 | unsigned IndexTypeQuals, |
| 7295 | SourceRange BracketsRange) { |
| 7296 | if (SizeExpr || !Size) |
| 7297 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 7298 | IndexTypeQuals, BracketsRange, |
| 7299 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7300 | |
| 7301 | QualType Types[] = { |
| 7302 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 7303 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 7304 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7305 | }; |
| 7306 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 7307 | QualType SizeType; |
| 7308 | for (unsigned I = 0; I != NumTypes; ++I) |
| 7309 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 7310 | SizeType = Types[I]; |
| 7311 | break; |
| 7312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7313 | |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7314 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 7315 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7316 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7317 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7318 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7319 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7320 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7321 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7322 | QualType |
| 7323 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7324 | ArrayType::ArraySizeModifier SizeMod, |
| 7325 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7326 | unsigned IndexTypeQuals, |
| 7327 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7328 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7329 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7333 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7334 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7335 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7336 | unsigned IndexTypeQuals, |
| 7337 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7338 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7339 | IndexTypeQuals, BracketsRange); |
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>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7345 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7346 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +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, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7350 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7351 | IndexTypeQuals, BracketsRange); |
| 7352 | } |
| 7353 | |
| 7354 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7355 | QualType |
| 7356 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7357 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7358 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7359 | unsigned IndexTypeQuals, |
| 7360 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7361 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7362 | SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7363 | IndexTypeQuals, BracketsRange); |
| 7364 | } |
| 7365 | |
| 7366 | template<typename Derived> |
| 7367 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7368 | unsigned NumElements, |
| 7369 | VectorType::VectorKind VecKind) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7370 | // FIXME: semantic checking! |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7371 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7373 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7374 | template<typename Derived> |
| 7375 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 7376 | unsigned NumElements, |
| 7377 | SourceLocation AttributeLoc) { |
| 7378 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 7379 | NumElements, true); |
| 7380 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 9996a7f | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7381 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 7382 | AttributeLoc); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7383 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7385 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7386 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7387 | QualType |
| 7388 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7389 | Expr *SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7390 | SourceLocation AttributeLoc) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7391 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7393 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7394 | template<typename Derived> |
| 7395 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7396 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7397 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7398 | bool Variadic, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7399 | unsigned Quals, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7400 | RefQualifierKind RefQualifier, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7401 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7402 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7403 | Quals, RefQualifier, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7404 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7405 | getDerived().getBaseEntity(), |
| 7406 | Info); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7408 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7409 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 7410 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 7411 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 7412 | } |
| 7413 | |
| 7414 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7415 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 7416 | assert(D && "no decl found"); |
| 7417 | if (D->isInvalidDecl()) return QualType(); |
| 7418 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7419 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7420 | TypeDecl *Ty; |
| 7421 | if (isa<UsingDecl>(D)) { |
| 7422 | UsingDecl *Using = cast<UsingDecl>(D); |
| 7423 | assert(Using->isTypeName() && |
| 7424 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 7425 | |
| 7426 | // A valid resolved using typename decl points to exactly one type decl. |
| 7427 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 7428 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7429 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7430 | } else { |
| 7431 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 7432 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 7433 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 7434 | } |
| 7435 | |
| 7436 | return SemaRef.Context.getTypeDeclType(Ty); |
| 7437 | } |
| 7438 | |
| 7439 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7440 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 7441 | SourceLocation Loc) { |
| 7442 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | template<typename Derived> |
| 7446 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 7447 | return SemaRef.Context.getTypeOfType(Underlying); |
| 7448 | } |
| 7449 | |
| 7450 | template<typename Derived> |
John McCall | 2a984ca | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7451 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 7452 | SourceLocation Loc) { |
| 7453 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | template<typename Derived> |
| 7457 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 7458 | TemplateName Template, |
| 7459 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7460 | const TemplateArgumentListInfo &TemplateArgs) { |
| 7461 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7462 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7463 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7464 | template<typename Derived> |
| 7465 | NestedNameSpecifier * |
| 7466 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7467 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7468 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7469 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7470 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7471 | CXXScopeSpec SS; |
| 7472 | // FIXME: The source location information is all wrong. |
| 7473 | SS.setRange(Range); |
| 7474 | SS.setScopeRep(Prefix); |
| 7475 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7476 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 7477 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7478 | ObjectType, |
| 7479 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 7480 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7481 | } |
| 7482 | |
| 7483 | template<typename Derived> |
| 7484 | NestedNameSpecifier * |
| 7485 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7486 | SourceRange Range, |
| 7487 | NamespaceDecl *NS) { |
| 7488 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 7489 | } |
| 7490 | |
| 7491 | template<typename Derived> |
| 7492 | NestedNameSpecifier * |
| 7493 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7494 | SourceRange Range, |
| 7495 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 7496 | QualType T) { |
| 7497 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7498 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 7499 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7500 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 7501 | T.getTypePtr()); |
| 7502 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7503 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7504 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 7505 | return 0; |
| 7506 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7507 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7508 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7509 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7510 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7511 | bool TemplateKW, |
| 7512 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7513 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7514 | Template); |
| 7515 | } |
| 7516 | |
| 7517 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7518 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7519 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 7520 | SourceRange QualifierRange, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7521 | const IdentifierInfo &II, |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7522 | QualType ObjectType, |
| 7523 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7524 | CXXScopeSpec SS; |
Douglas Gregor | 1efb6c7 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 7525 | SS.setRange(QualifierRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7526 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 7527 | UnqualifiedId Name; |
| 7528 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7529 | Sema::TemplateTy Template; |
| 7530 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 7531 | /*FIXME:*/getDerived().getBaseLocation(), |
| 7532 | SS, |
| 7533 | Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7534 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7535 | /*EnteringContext=*/false, |
| 7536 | Template); |
John McCall | 43fed0d | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7537 | return Template.get(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7538 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7539 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7540 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7541 | TemplateName |
| 7542 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7543 | OverloadedOperatorKind Operator, |
| 7544 | QualType ObjectType) { |
| 7545 | CXXScopeSpec SS; |
| 7546 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 7547 | SS.setScopeRep(Qualifier); |
| 7548 | UnqualifiedId Name; |
| 7549 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 7550 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 7551 | Operator, SymbolLocations); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7552 | Sema::TemplateTy Template; |
| 7553 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7554 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7555 | SS, |
| 7556 | Name, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7557 | ParsedType::make(ObjectType), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7558 | /*EnteringContext=*/false, |
| 7559 | Template); |
| 7560 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7561 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7562 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7563 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7564 | ExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7565 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 7566 | SourceLocation OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7567 | Expr *OrigCallee, |
| 7568 | Expr *First, |
| 7569 | Expr *Second) { |
| 7570 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 7571 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7572 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7573 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7574 | if (Op == OO_Subscript) { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7575 | if (!First->getType()->isOverloadableType() && |
| 7576 | !Second->getType()->isOverloadableType()) |
| 7577 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 7578 | Callee->getLocStart(), |
| 7579 | Second, OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 7580 | } else if (Op == OO_Arrow) { |
| 7581 | // -> is never a builtin operation. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7582 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 7583 | } else if (Second == 0 || isPostIncDec) { |
| 7584 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7585 | // The argument is not of overloadable type, so try to create a |
| 7586 | // built-in unary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7587 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7588 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7589 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7590 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7591 | } |
| 7592 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7593 | if (!First->getType()->isOverloadableType() && |
| 7594 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7595 | // Neither of the arguments is an overloadable type, so try to |
| 7596 | // create a built-in binary operation. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7597 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7598 | ExprResult Result |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7599 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7600 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7601 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7602 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7603 | return move(Result); |
| 7604 | } |
| 7605 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7606 | |
| 7607 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7608 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7609 | UnresolvedSet<16> Functions; |
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 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7612 | assert(ULE->requiresADL()); |
| 7613 | |
| 7614 | // FIXME: Do we have to check |
| 7615 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7616 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7617 | } else { |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7618 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7621 | // Add any functions found via argument-dependent lookup. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7622 | Expr *Args[2] = { First, Second }; |
| 7623 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7624 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7625 | // Create the overloaded operator invocation for unary operators. |
| 7626 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7627 | UnaryOperatorKind Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7628 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7629 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7631 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7632 | if (Op == OO_Subscript) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7633 | return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7634 | OpLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7635 | First, |
| 7636 | Second); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7638 | // Create the overloaded operator invocation for binary operators. |
John McCall | 2de56d1 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7639 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7640 | ExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7641 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 7642 | if (Result.isInvalid()) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7643 | return ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7644 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7645 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7647 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7648 | template<typename Derived> |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7649 | ExprResult |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7650 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7651 | SourceLocation OperatorLoc, |
| 7652 | bool isArrow, |
| 7653 | NestedNameSpecifier *Qualifier, |
| 7654 | SourceRange QualifierRange, |
| 7655 | TypeSourceInfo *ScopeType, |
| 7656 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7657 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7658 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7659 | CXXScopeSpec SS; |
| 7660 | if (Qualifier) { |
| 7661 | SS.setRange(QualifierRange); |
| 7662 | SS.setScopeRep(Qualifier); |
| 7663 | } |
| 7664 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7665 | QualType BaseType = Base->getType(); |
| 7666 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7667 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7668 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 7669 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 7670 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7671 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7672 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7673 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7674 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7675 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7676 | /*FIXME?*/true); |
| 7677 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7678 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7679 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7680 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 7681 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 7682 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 7683 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 7684 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7685 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7686 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7687 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7688 | OperatorLoc, isArrow, |
| 7689 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7690 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7691 | /*TemplateArgs*/ 0); |
| 7692 | } |
| 7693 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7694 | } // end namespace clang |
| 7695 | |
| 7696 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |