Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
John McCall | 8302463 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 18 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
| 26 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/Stmt.h" |
| 28 | #include "clang/AST/StmtCXX.h" |
| 29 | #include "clang/AST/StmtObjC.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Ownership.h" |
| 31 | #include "clang/Sema/Designator.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 451d1b1 | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 34 | #include "TypeLocBuilder.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | |
| 37 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 38 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 40 | /// \brief A semantic tree transformation that allows one to transform one |
| 41 | /// abstract syntax tree into another. |
| 42 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 44 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 45 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 46 | /// instantiation is implemented as a tree transformation where the |
| 47 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 48 | /// template arguments for their corresponding template parameters; a similar |
| 49 | /// transformation is performed for non-type template parameters and |
| 50 | /// template template parameters. |
| 51 | /// |
| 52 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 54 | /// override any of the transformation or rebuild operators by providing an |
| 55 | /// operation with the same signature as the default implementation. The |
| 56 | /// overridding function should not be virtual. |
| 57 | /// |
| 58 | /// Semantic tree transformations are split into two stages, either of which |
| 59 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 60 | /// or the parts of an AST node using the various transformation functions, |
| 61 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 62 | /// node of the appropriate kind from the pieces. The default transformation |
| 63 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 64 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 65 | /// were changed by the transformation, invokes the rebuild operation to create |
| 66 | /// a new AST node. |
| 67 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 69 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 70 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 71 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 72 | /// new implementations. |
| 73 | /// |
| 74 | /// For more fine-grained transformations, subclasses can replace any of the |
| 75 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 76 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 77 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 78 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 80 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 81 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 82 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 83 | /// be able to use more efficient rebuild steps. |
| 84 | /// |
| 85 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 87 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 88 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 89 | /// default locations and entity names used for type-checking |
| 90 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 91 | template<typename Derived> |
| 92 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 93 | /// \brief Private RAII object that helps us forget and then re-remember |
| 94 | /// the template argument corresponding to a partially-substituted parameter |
| 95 | /// pack. |
| 96 | class ForgetPartiallySubstitutedPackRAII { |
| 97 | Derived &Self; |
| 98 | TemplateArgument Old; |
| 99 | |
| 100 | public: |
| 101 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 102 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 103 | } |
| 104 | |
| 105 | ~ForgetPartiallySubstitutedPackRAII() { |
| 106 | Self.RememberPartiallySubstitutedPack(Old); |
| 107 | } |
| 108 | }; |
| 109 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 110 | protected: |
| 111 | Sema &SemaRef; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 112 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 114 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 115 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 117 | /// \brief Retrieves a reference to the derived class. |
| 118 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 119 | |
| 120 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | const Derived &getDerived() const { |
| 122 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 123 | } |
| 124 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 125 | static inline ExprResult Owned(Expr *E) { return E; } |
| 126 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 128 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 129 | /// this tree transform. |
| 130 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 131 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 132 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 133 | /// if none of the children have changed. |
| 134 | /// |
| 135 | /// Subclasses may override this function to specify when the transformation |
| 136 | /// should rebuild all AST nodes. |
| 137 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 139 | /// \brief Returns the location of the entity being transformed, if that |
| 140 | /// information was not available elsewhere in the AST. |
| 141 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 143 | /// provide an alternative implementation that provides better location |
| 144 | /// information. |
| 145 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 147 | /// \brief Returns the name of the entity being transformed, if that |
| 148 | /// information was not available elsewhere in the AST. |
| 149 | /// |
| 150 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 151 | /// implementation with a more precise name. |
| 152 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | /// \brief Sets the "base" location and entity when that |
| 155 | /// information is known based on another transformation. |
| 156 | /// |
| 157 | /// By default, the source location and entity are ignored. Subclasses can |
| 158 | /// override this function to provide a customized implementation. |
| 159 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 161 | /// \brief RAII object that temporarily sets the base location and entity |
| 162 | /// used for reporting diagnostics in types. |
| 163 | class TemporaryBase { |
| 164 | TreeTransform &Self; |
| 165 | SourceLocation OldLocation; |
| 166 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 168 | public: |
| 169 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 171 | OldLocation = Self.getDerived().getBaseLocation(); |
| 172 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 173 | |
| 174 | if (Location.isValid()) |
| 175 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 178 | ~TemporaryBase() { |
| 179 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 180 | } |
| 181 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | |
| 183 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 184 | /// transformed. |
| 185 | /// |
| 186 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 188 | /// not change. For example, template instantiation need not traverse |
| 189 | /// non-dependent types. |
| 190 | bool AlreadyTransformed(QualType T) { |
| 191 | return T.isNull(); |
| 192 | } |
| 193 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 194 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 195 | /// because it is a default argument. |
| 196 | /// |
| 197 | /// Subclasses can provide an alternative implementation of this routine to |
| 198 | /// determine which kinds of call arguments get dropped. By default, |
| 199 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 200 | bool DropCallArgument(Expr *E) { |
| 201 | return E->isDefaultArgument(); |
| 202 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 203 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 204 | /// \brief Determine whether we should expand a pack expansion with the |
| 205 | /// given set of parameter packs into separate arguments by repeatedly |
| 206 | /// transforming the pattern. |
| 207 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 208 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 209 | /// Subclasses can override this routine to provide different behavior. |
| 210 | /// |
| 211 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 212 | /// pack expansion. |
| 213 | /// |
| 214 | /// \param PatternRange The source range that covers the entire pattern of |
| 215 | /// the pack expansion. |
| 216 | /// |
| 217 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 218 | /// pattern. |
| 219 | /// |
| 220 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 221 | /// \p Unexpanded. |
| 222 | /// |
| 223 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 224 | /// expand the corresponding pack expansions into separate arguments. When |
| 225 | /// set, \c NumExpansions must also be set. |
| 226 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 227 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 228 | /// pack expansion after all of the expanded arguments. This is used |
| 229 | /// when extending explicitly-specified template argument packs per |
| 230 | /// C++0x [temp.arg.explicit]p9. |
| 231 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 232 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 233 | /// the expanded form of the corresponding pack expansion. This is both an |
| 234 | /// input and an output parameter, which can be set by the caller if the |
| 235 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 236 | /// and will be set by the callee when the number of expansions is known. |
| 237 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 238 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 239 | /// |
| 240 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 241 | /// are to be instantiated with arguments of different lengths), false |
| 242 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 243 | /// must be set. |
| 244 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 245 | SourceRange PatternRange, |
| 246 | const UnexpandedParameterPack *Unexpanded, |
| 247 | unsigned NumUnexpanded, |
| 248 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 249 | bool &RetainExpansion, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 250 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | ShouldExpand = false; |
| 252 | return false; |
| 253 | } |
| 254 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 255 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 256 | /// when performing an instantiation that must preserve the parameter pack |
| 257 | /// use. |
| 258 | /// |
| 259 | /// This routine is meant to be overridden by the template instantiator. |
| 260 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 261 | return TemplateArgument(); |
| 262 | } |
| 263 | |
| 264 | /// \brief "Remember" the partially-substituted pack template argument |
| 265 | /// after performing an instantiation that must preserve the parameter pack |
| 266 | /// use. |
| 267 | /// |
| 268 | /// This routine is meant to be overridden by the template instantiator. |
| 269 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 270 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 271 | /// \brief Note to the derived class when a function parameter pack is |
| 272 | /// being expanded. |
| 273 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 274 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 275 | /// \brief Transforms the given type into another type. |
| 276 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 277 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 278 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 279 | /// function. This is expensive, but we don't mind, because |
| 280 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 281 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// |
| 283 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 284 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 286 | /// \brief Transforms the given type-with-location into a new |
| 287 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 288 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 289 | /// By default, this routine transforms a type by delegating to the |
| 290 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 291 | /// may override this function (to take over all type |
| 292 | /// transformations) or some set of the TransformXXXType functions |
| 293 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 294 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 295 | |
| 296 | /// \brief Transform the given type-with-location into a new |
| 297 | /// type, collecting location information in the given builder |
| 298 | /// as necessary. |
| 299 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 300 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 302 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 303 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 305 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 306 | /// statement or the TransformExpr() function to transform an expression. |
| 307 | /// Subclasses may override this function to transform statements using some |
| 308 | /// other mechanism. |
| 309 | /// |
| 310 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 311 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 313 | /// \brief Transform the given expression. |
| 314 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 315 | /// By default, this routine transforms an expression by delegating to the |
| 316 | /// appropriate TransformXXXExpr function to build a new expression. |
| 317 | /// Subclasses may override this function to transform expressions using some |
| 318 | /// other mechanism. |
| 319 | /// |
| 320 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 321 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 323 | /// \brief Transform the given list of expressions. |
| 324 | /// |
| 325 | /// This routine transforms a list of expressions by invoking |
| 326 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 327 | /// support for variadic templates by expanding any pack expansions (if the |
| 328 | /// derived class permits such expansion) along the way. When pack expansions |
| 329 | /// are present, the number of outputs may not equal the number of inputs. |
| 330 | /// |
| 331 | /// \param Inputs The set of expressions to be transformed. |
| 332 | /// |
| 333 | /// \param NumInputs The number of expressions in \c Inputs. |
| 334 | /// |
| 335 | /// \param IsCall If \c true, then this transform is being performed on |
| 336 | /// function-call arguments, and any arguments that should be dropped, will |
| 337 | /// be. |
| 338 | /// |
| 339 | /// \param Outputs The transformed input expressions will be added to this |
| 340 | /// vector. |
| 341 | /// |
| 342 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 343 | /// due to transformation. |
| 344 | /// |
| 345 | /// \returns true if an error occurred, false otherwise. |
| 346 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
| 347 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 348 | bool *ArgChanged = 0); |
| 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Transform the given declaration, which is referenced from a type |
| 351 | /// or expression. |
| 352 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 353 | /// By default, acts as the identity function on declarations. Subclasses |
| 354 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 355 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 356 | |
| 357 | /// \brief Transform the definition of the given declaration. |
| 358 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 360 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 361 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 362 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 365 | /// \brief Transform the given declaration, which was the first part of a |
| 366 | /// nested-name-specifier in a member access expression. |
| 367 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 368 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 369 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 370 | /// the \c T in \c x->T::member |
| 371 | /// |
| 372 | /// By default, invokes TransformDecl() to transform the declaration. |
| 373 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 374 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 375 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 376 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 377 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 378 | /// \brief Transform the given nested-name-specifier. |
| 379 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 381 | /// nested-name-specifier. Subclasses may override this function to provide |
| 382 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 384 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 385 | QualType ObjectType = QualType(), |
| 386 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 388 | /// \brief Transform the given nested-name-specifier with source-location |
| 389 | /// information. |
| 390 | /// |
| 391 | /// By default, transforms all of the types and declarations within the |
| 392 | /// nested-name-specifier. Subclasses may override this function to provide |
| 393 | /// alternate behavior. |
| 394 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 395 | NestedNameSpecifierLoc NNS, |
| 396 | QualType ObjectType = QualType(), |
| 397 | NamedDecl *FirstQualifierInScope = 0); |
| 398 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 399 | /// \brief Transform the given declaration name. |
| 400 | /// |
| 401 | /// By default, transforms the types of conversion function, constructor, |
| 402 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 403 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 404 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 405 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 406 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 407 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 408 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 410 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 412 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 413 | TemplateName TransformTemplateName(TemplateName Name, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 414 | QualType ObjectType = QualType(), |
| 415 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 417 | /// \brief Transform the given template argument. |
| 418 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | /// By default, this operation transforms the type, expression, or |
| 420 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 421 | /// new template argument from the transformed result. Subclasses may |
| 422 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 423 | /// |
| 424 | /// Returns true if there was an error. |
| 425 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 426 | TemplateArgumentLoc &Output); |
| 427 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 428 | /// \brief Transform the given set of template arguments. |
| 429 | /// |
| 430 | /// By default, this operation transforms all of the template arguments |
| 431 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 432 | /// the transformed arguments to the output list. |
| 433 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 434 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 435 | /// a convenience function. Subclasses that wish to override this behavior |
| 436 | /// should override the iterator-based member template version. |
| 437 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 438 | /// \param Inputs The set of template arguments to be transformed. |
| 439 | /// |
| 440 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 441 | /// |
| 442 | /// \param Outputs The set of transformed template arguments output by this |
| 443 | /// routine. |
| 444 | /// |
| 445 | /// Returns true if an error occurred. |
| 446 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 447 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 448 | TemplateArgumentListInfo &Outputs) { |
| 449 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 450 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 451 | |
| 452 | /// \brief Transform the given set of template arguments. |
| 453 | /// |
| 454 | /// By default, this operation transforms all of the template arguments |
| 455 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 456 | /// the transformed arguments to the output list. |
| 457 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 458 | /// \param First An iterator to the first template argument. |
| 459 | /// |
| 460 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 461 | /// |
| 462 | /// \param Outputs The set of transformed template arguments output by this |
| 463 | /// routine. |
| 464 | /// |
| 465 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 466 | template<typename InputIterator> |
| 467 | bool TransformTemplateArguments(InputIterator First, |
| 468 | InputIterator Last, |
| 469 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 470 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 471 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 472 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 473 | TemplateArgumentLoc &ArgLoc); |
| 474 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 475 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 476 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 477 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 478 | getDerived().getBaseLocation()); |
| 479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 481 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 482 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 483 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 484 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 485 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 486 | QualType |
| 487 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 488 | TemplateSpecializationTypeLoc TL, |
| 489 | TemplateName Template); |
| 490 | |
| 491 | QualType |
| 492 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 493 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 494 | TemplateName Template); |
| 495 | |
| 496 | QualType |
| 497 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 498 | DependentTemplateSpecializationTypeLoc TL, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 499 | NestedNameSpecifier *Prefix); |
| 500 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 501 | QualType |
| 502 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 503 | DependentTemplateSpecializationTypeLoc TL, |
| 504 | NestedNameSpecifierLoc QualifierLoc); |
| 505 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 506 | /// \brief Transforms the parameters of a function type into the |
| 507 | /// given vectors. |
| 508 | /// |
| 509 | /// The result vectors should be kept in sync; null entries in the |
| 510 | /// variables vector are acceptable. |
| 511 | /// |
| 512 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 513 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 514 | ParmVarDecl **Params, unsigned NumParams, |
| 515 | const QualType *ParamTypes, |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 516 | llvm::SmallVectorImpl<QualType> &PTypes, |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 517 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 518 | |
| 519 | /// \brief Transforms a single function-type parameter. Return null |
| 520 | /// on error. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 521 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 522 | llvm::Optional<unsigned> NumExpansions); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 523 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 524 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 525 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 526 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 527 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 529 | #define STMT(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 530 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 531 | #define EXPR(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 532 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 533 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 534 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | /// \brief Build a new pointer type given its pointee type. |
| 537 | /// |
| 538 | /// By default, performs semantic analysis when building the pointer type. |
| 539 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 540 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 541 | |
| 542 | /// \brief Build a new block pointer type given its pointee type. |
| 543 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 545 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 546 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 547 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 548 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 550 | /// By default, performs semantic analysis when building the |
| 551 | /// reference type. Subclasses may override this routine to provide |
| 552 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 554 | /// \param LValue whether the type was written with an lvalue sigil |
| 555 | /// or an rvalue sigil. |
| 556 | QualType RebuildReferenceType(QualType ReferentType, |
| 557 | bool LValue, |
| 558 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// \brief Build a new member pointer type given the pointee type and the |
| 561 | /// class type it refers into. |
| 562 | /// |
| 563 | /// By default, performs semantic analysis when building the member pointer |
| 564 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 565 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 566 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 568 | /// \brief Build a new array type given the element type, size |
| 569 | /// modifier, size of the array (if known), size expression, and index type |
| 570 | /// qualifiers. |
| 571 | /// |
| 572 | /// By default, performs semantic analysis when building the array type. |
| 573 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 575 | QualType RebuildArrayType(QualType ElementType, |
| 576 | ArrayType::ArraySizeModifier SizeMod, |
| 577 | const llvm::APInt *Size, |
| 578 | Expr *SizeExpr, |
| 579 | unsigned IndexTypeQuals, |
| 580 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 581 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 582 | /// \brief Build a new constant array type given the element type, size |
| 583 | /// modifier, (known) size of the array, and index type qualifiers. |
| 584 | /// |
| 585 | /// By default, performs semantic analysis when building the array type. |
| 586 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 588 | ArrayType::ArraySizeModifier SizeMod, |
| 589 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 590 | unsigned IndexTypeQuals, |
| 591 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 592 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 593 | /// \brief Build a new incomplete array type given the element type, size |
| 594 | /// modifier, and index type qualifiers. |
| 595 | /// |
| 596 | /// By default, performs semantic analysis when building the array type. |
| 597 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 599 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 600 | unsigned IndexTypeQuals, |
| 601 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 602 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 604 | /// size modifier, size expression, and index type qualifiers. |
| 605 | /// |
| 606 | /// By default, performs semantic analysis when building the array type. |
| 607 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 609 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 610 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 611 | unsigned IndexTypeQuals, |
| 612 | SourceRange BracketsRange); |
| 613 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 615 | /// size modifier, size expression, and index type qualifiers. |
| 616 | /// |
| 617 | /// By default, performs semantic analysis when building the array type. |
| 618 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 620 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 621 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 622 | unsigned IndexTypeQuals, |
| 623 | SourceRange BracketsRange); |
| 624 | |
| 625 | /// \brief Build a new vector type given the element type and |
| 626 | /// number of elements. |
| 627 | /// |
| 628 | /// By default, performs semantic analysis when building the vector type. |
| 629 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 630 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 631 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 633 | /// \brief Build a new extended vector type given the element type and |
| 634 | /// number of elements. |
| 635 | /// |
| 636 | /// By default, performs semantic analysis when building the vector type. |
| 637 | /// Subclasses may override this routine to provide different behavior. |
| 638 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 639 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | |
| 641 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 642 | /// given the element type and number of elements. |
| 643 | /// |
| 644 | /// By default, performs semantic analysis when building the vector type. |
| 645 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 647 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 648 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 650 | /// \brief Build a new function type. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the function type. |
| 653 | /// Subclasses may override this routine to provide different behavior. |
| 654 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 656 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 657 | bool Variadic, unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 658 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 659 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 661 | /// \brief Build a new unprototyped function type. |
| 662 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 663 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 664 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 665 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 666 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 667 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 668 | /// \brief Build a new typedef type. |
| 669 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 670 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 671 | } |
| 672 | |
| 673 | /// \brief Build a new class/struct/union type. |
| 674 | QualType RebuildRecordType(RecordDecl *Record) { |
| 675 | return SemaRef.Context.getTypeDeclType(Record); |
| 676 | } |
| 677 | |
| 678 | /// \brief Build a new Enum type. |
| 679 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 680 | return SemaRef.Context.getTypeDeclType(Enum); |
| 681 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 682 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 684 | /// |
| 685 | /// By default, performs semantic analysis when building the typeof type. |
| 686 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 687 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 688 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 690 | /// |
| 691 | /// By default, builds a new TypeOfType with the given underlying type. |
| 692 | QualType RebuildTypeOfType(QualType Underlying); |
| 693 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | /// |
| 696 | /// By default, performs semantic analysis when building the decltype type. |
| 697 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 698 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 699 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 700 | /// \brief Build a new C++0x auto type. |
| 701 | /// |
| 702 | /// By default, builds a new AutoType with the given deduced type. |
| 703 | QualType RebuildAutoType(QualType Deduced) { |
| 704 | return SemaRef.Context.getAutoType(Deduced); |
| 705 | } |
| 706 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 707 | /// \brief Build a new template specialization type. |
| 708 | /// |
| 709 | /// By default, performs semantic analysis when building the template |
| 710 | /// specialization type. Subclasses may override this routine to provide |
| 711 | /// different behavior. |
| 712 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 713 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 714 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 716 | /// \brief Build a new parenthesized type. |
| 717 | /// |
| 718 | /// By default, builds a new ParenType type from the inner type. |
| 719 | /// Subclasses may override this routine to provide different behavior. |
| 720 | QualType RebuildParenType(QualType InnerType) { |
| 721 | return SemaRef.Context.getParenType(InnerType); |
| 722 | } |
| 723 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 724 | /// \brief Build a new qualified name type. |
| 725 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 726 | /// By default, builds a new ElaboratedType type from the keyword, |
| 727 | /// the nested-name-specifier and the named type. |
| 728 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 729 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 730 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 731 | NestedNameSpecifierLoc QualifierLoc, |
| 732 | QualType Named) { |
| 733 | return SemaRef.Context.getElaboratedType(Keyword, |
| 734 | QualifierLoc.getNestedNameSpecifier(), |
| 735 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 737 | |
| 738 | /// \brief Build a new typename type that refers to a template-id. |
| 739 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 740 | /// By default, builds a new DependentNameType type from the |
| 741 | /// nested-name-specifier and the given type. Subclasses may override |
| 742 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 743 | QualType RebuildDependentTemplateSpecializationType( |
| 744 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 745 | NestedNameSpecifier *Qualifier, |
| 746 | SourceRange QualifierRange, |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 747 | const IdentifierInfo *Name, |
| 748 | SourceLocation NameLoc, |
| 749 | const TemplateArgumentListInfo &Args) { |
| 750 | // Rebuild the template name. |
| 751 | // TODO: avoid TemplateName abstraction |
| 752 | TemplateName InstName = |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 753 | getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 754 | QualType(), 0); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 755 | |
Douglas Gregor | 7ba0c3f | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 756 | if (InstName.isNull()) |
| 757 | return QualType(); |
| 758 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 759 | // If it's still dependent, make a dependent specialization. |
| 760 | if (InstName.getAsDependentTemplateName()) |
| 761 | return SemaRef.Context.getDependentTemplateSpecializationType( |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 762 | Keyword, Qualifier, Name, Args); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 763 | |
| 764 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 765 | // specialization. |
| 766 | QualType T = |
| 767 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 768 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 769 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 770 | if (Keyword == ETK_None && Qualifier == 0) |
Douglas Gregor | 6e06801 | 2011-02-28 00:04:36 +0000 | [diff] [blame] | 771 | return T; |
| 772 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 773 | return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 775 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 776 | /// \brief Build a new typename type that refers to a template-id. |
| 777 | /// |
| 778 | /// By default, builds a new DependentNameType type from the |
| 779 | /// nested-name-specifier and the given type. Subclasses may override |
| 780 | /// this routine to provide different behavior. |
| 781 | QualType RebuildDependentTemplateSpecializationType( |
| 782 | ElaboratedTypeKeyword Keyword, |
| 783 | NestedNameSpecifierLoc QualifierLoc, |
| 784 | const IdentifierInfo *Name, |
| 785 | SourceLocation NameLoc, |
| 786 | const TemplateArgumentListInfo &Args) { |
| 787 | // Rebuild the template name. |
| 788 | // TODO: avoid TemplateName abstraction |
| 789 | TemplateName InstName |
| 790 | = getDerived().RebuildTemplateName(QualifierLoc.getNestedNameSpecifier(), |
| 791 | QualifierLoc.getSourceRange(), *Name, |
| 792 | QualType(), 0); |
| 793 | |
| 794 | if (InstName.isNull()) |
| 795 | return QualType(); |
| 796 | |
| 797 | // If it's still dependent, make a dependent specialization. |
| 798 | if (InstName.getAsDependentTemplateName()) |
| 799 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 800 | QualifierLoc.getNestedNameSpecifier(), |
| 801 | Name, |
| 802 | Args); |
| 803 | |
| 804 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 805 | // specialization. |
| 806 | QualType T = |
| 807 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 808 | if (T.isNull()) return QualType(); |
| 809 | |
| 810 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 811 | return T; |
| 812 | |
| 813 | return SemaRef.Context.getElaboratedType(Keyword, |
| 814 | QualifierLoc.getNestedNameSpecifier(), |
| 815 | T); |
| 816 | } |
| 817 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 818 | /// \brief Build a new typename type that refers to an identifier. |
| 819 | /// |
| 820 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 821 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 822 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 823 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 824 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 825 | NestedNameSpecifierLoc QualifierLoc, |
| 826 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 827 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 828 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 829 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 831 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 832 | // If the name is still dependent, just build a new dependent name type. |
| 833 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 834 | return SemaRef.Context.getDependentNameType(Keyword, |
| 835 | QualifierLoc.getNestedNameSpecifier(), |
| 836 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 839 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 840 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 841 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 842 | |
| 843 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 844 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 845 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 846 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 847 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 848 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 849 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 850 | if (!DC) |
| 851 | return QualType(); |
| 852 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 853 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 854 | return QualType(); |
| 855 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 856 | TagDecl *Tag = 0; |
| 857 | SemaRef.LookupQualifiedName(Result, DC); |
| 858 | switch (Result.getResultKind()) { |
| 859 | case LookupResult::NotFound: |
| 860 | case LookupResult::NotFoundInCurrentInstantiation: |
| 861 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 862 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 863 | case LookupResult::Found: |
| 864 | Tag = Result.getAsSingle<TagDecl>(); |
| 865 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 866 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 867 | case LookupResult::FoundOverloaded: |
| 868 | case LookupResult::FoundUnresolvedValue: |
| 869 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 870 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 871 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 872 | case LookupResult::Ambiguous: |
| 873 | // Let the LookupResult structure handle ambiguities. |
| 874 | return QualType(); |
| 875 | } |
| 876 | |
| 877 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 878 | // Check where the name exists but isn't a tag type and use that to emit |
| 879 | // better diagnostics. |
| 880 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 881 | SemaRef.LookupQualifiedName(Result, DC); |
| 882 | switch (Result.getResultKind()) { |
| 883 | case LookupResult::Found: |
| 884 | case LookupResult::FoundOverloaded: |
| 885 | case LookupResult::FoundUnresolvedValue: { |
| 886 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| 887 | unsigned Kind = 0; |
| 888 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
| 889 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2; |
| 890 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 891 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 892 | break; |
| 893 | } |
| 894 | default: |
| 895 | // FIXME: Would be nice to highlight just the source range. |
| 896 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 897 | << Kind << Id << DC; |
| 898 | break; |
| 899 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 900 | return QualType(); |
| 901 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 902 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 903 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 904 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 905 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 906 | return QualType(); |
| 907 | } |
| 908 | |
| 909 | // Build the elaborated-type-specifier type. |
| 910 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 911 | return SemaRef.Context.getElaboratedType(Keyword, |
| 912 | QualifierLoc.getNestedNameSpecifier(), |
| 913 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 914 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 916 | /// \brief Build a new pack expansion type. |
| 917 | /// |
| 918 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 919 | /// Subclasses may override this routine to provide different behavior. |
| 920 | QualType RebuildPackExpansionType(QualType Pattern, |
| 921 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 922 | SourceLocation EllipsisLoc, |
| 923 | llvm::Optional<unsigned> NumExpansions) { |
| 924 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 925 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 928 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 929 | /// identifier that names the next step in the nested-name-specifier. |
| 930 | /// |
| 931 | /// By default, performs semantic analysis when building the new |
| 932 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 933 | /// different behavior. |
| 934 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 935 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 936 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 937 | QualType ObjectType, |
| 938 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 939 | |
| 940 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 941 | /// namespace named in the next step in the nested-name-specifier. |
| 942 | /// |
| 943 | /// By default, performs semantic analysis when building the new |
| 944 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 945 | /// different behavior. |
| 946 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 947 | SourceRange Range, |
| 948 | NamespaceDecl *NS); |
| 949 | |
| 950 | /// \brief Build a new nested-name-specifier given the prefix and the |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 951 | /// namespace alias named in the next step in the nested-name-specifier. |
| 952 | /// |
| 953 | /// By default, performs semantic analysis when building the new |
| 954 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 955 | /// different behavior. |
| 956 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 957 | SourceRange Range, |
| 958 | NamespaceAliasDecl *Alias); |
| 959 | |
| 960 | /// \brief Build a new nested-name-specifier given the prefix and the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 961 | /// type named in the next step in the nested-name-specifier. |
| 962 | /// |
| 963 | /// By default, performs semantic analysis when building the new |
| 964 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 965 | /// different behavior. |
| 966 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 967 | SourceRange Range, |
| 968 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 969 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 970 | |
| 971 | /// \brief Build a new template name given a nested name specifier, a flag |
| 972 | /// indicating whether the "template" keyword was provided, and the template |
| 973 | /// that the template name refers to. |
| 974 | /// |
| 975 | /// By default, builds the new template name directly. Subclasses may override |
| 976 | /// this routine to provide different behavior. |
| 977 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 978 | bool TemplateKW, |
| 979 | TemplateDecl *Template); |
| 980 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 981 | /// \brief Build a new template name given a nested name specifier and the |
| 982 | /// name that is referred to as a template. |
| 983 | /// |
| 984 | /// By default, performs semantic analysis to determine whether the name can |
| 985 | /// be resolved to a specific template, then builds the appropriate kind of |
| 986 | /// template name. Subclasses may override this routine to provide different |
| 987 | /// behavior. |
| 988 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 989 | SourceRange QualifierRange, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 990 | const IdentifierInfo &II, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 991 | QualType ObjectType, |
| 992 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 993 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 994 | /// \brief Build a new template name given a nested name specifier and the |
| 995 | /// overloaded operator name that is referred to as a template. |
| 996 | /// |
| 997 | /// By default, performs semantic analysis to determine whether the name can |
| 998 | /// be resolved to a specific template, then builds the appropriate kind of |
| 999 | /// template name. Subclasses may override this routine to provide different |
| 1000 | /// behavior. |
| 1001 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 1002 | OverloadedOperatorKind Operator, |
| 1003 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1004 | |
| 1005 | /// \brief Build a new template name given a template template parameter pack |
| 1006 | /// and the |
| 1007 | /// |
| 1008 | /// By default, performs semantic analysis to determine whether the name can |
| 1009 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1010 | /// template name. Subclasses may override this routine to provide different |
| 1011 | /// behavior. |
| 1012 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1013 | const TemplateArgument &ArgPack) { |
| 1014 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1015 | } |
| 1016 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1017 | /// \brief Build a new compound statement. |
| 1018 | /// |
| 1019 | /// By default, performs semantic analysis to build the new statement. |
| 1020 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1021 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1022 | MultiStmtArg Statements, |
| 1023 | SourceLocation RBraceLoc, |
| 1024 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1025 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1026 | IsStmtExpr); |
| 1027 | } |
| 1028 | |
| 1029 | /// \brief Build a new case statement. |
| 1030 | /// |
| 1031 | /// By default, performs semantic analysis to build the new statement. |
| 1032 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1033 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1034 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1035 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1036 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1037 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1038 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1039 | ColonLoc); |
| 1040 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1042 | /// \brief Attach the body to a new case statement. |
| 1043 | /// |
| 1044 | /// By default, performs semantic analysis to build the new statement. |
| 1045 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1046 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1047 | getSema().ActOnCaseStmtBody(S, Body); |
| 1048 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1051 | /// \brief Build a new default statement. |
| 1052 | /// |
| 1053 | /// By default, performs semantic analysis to build the new statement. |
| 1054 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1055 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1056 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1057 | Stmt *SubStmt) { |
| 1058 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | /*CurScope=*/0); |
| 1060 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1062 | /// \brief Build a new label statement. |
| 1063 | /// |
| 1064 | /// By default, performs semantic analysis to build the new statement. |
| 1065 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1066 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1067 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1068 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1069 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1071 | /// \brief Build a new "if" statement. |
| 1072 | /// |
| 1073 | /// By default, performs semantic analysis to build the new statement. |
| 1074 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1075 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1076 | VarDecl *CondVar, Stmt *Then, |
| 1077 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1078 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1079 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1081 | /// \brief Start building a new switch statement. |
| 1082 | /// |
| 1083 | /// By default, performs semantic analysis to build the new statement. |
| 1084 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1085 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1086 | Expr *Cond, VarDecl *CondVar) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1087 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1088 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1091 | /// \brief Attach the body to the switch statement. |
| 1092 | /// |
| 1093 | /// By default, performs semantic analysis to build the new statement. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1095 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1096 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1097 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /// \brief Build a new while statement. |
| 1101 | /// |
| 1102 | /// By default, performs semantic analysis to build the new statement. |
| 1103 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1104 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1105 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1106 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1107 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | /// \brief Build a new do-while statement. |
| 1110 | /// |
| 1111 | /// By default, performs semantic analysis to build the new statement. |
| 1112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1113 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1114 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1115 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1116 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1117 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /// \brief Build a new for statement. |
| 1121 | /// |
| 1122 | /// By default, performs semantic analysis to build the new statement. |
| 1123 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1124 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1125 | Stmt *Init, Sema::FullExprArg Cond, |
| 1126 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1127 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1128 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1129 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1132 | /// \brief Build a new goto statement. |
| 1133 | /// |
| 1134 | /// By default, performs semantic analysis to build the new statement. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1136 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1137 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1138 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /// \brief Build a new indirect goto statement. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new statement. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1145 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1146 | SourceLocation StarLoc, |
| 1147 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1148 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1149 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1151 | /// \brief Build a new return statement. |
| 1152 | /// |
| 1153 | /// By default, performs semantic analysis to build the new statement. |
| 1154 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1155 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1156 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1159 | /// \brief Build a new declaration statement. |
| 1160 | /// |
| 1161 | /// By default, performs semantic analysis to build the new statement. |
| 1162 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1163 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1165 | SourceLocation EndLoc) { |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1166 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1167 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1170 | /// \brief Build a new inline asm statement. |
| 1171 | /// |
| 1172 | /// By default, performs semantic analysis to build the new statement. |
| 1173 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1174 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1175 | bool IsSimple, |
| 1176 | bool IsVolatile, |
| 1177 | unsigned NumOutputs, |
| 1178 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1179 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1180 | MultiExprArg Constraints, |
| 1181 | MultiExprArg Exprs, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1182 | Expr *AsmString, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1183 | MultiExprArg Clobbers, |
| 1184 | SourceLocation RParenLoc, |
| 1185 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1186 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1187 | NumInputs, Names, move(Constraints), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1188 | Exprs, AsmString, Clobbers, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1189 | RParenLoc, MSAsm); |
| 1190 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1191 | |
| 1192 | /// \brief Build a new Objective-C @try statement. |
| 1193 | /// |
| 1194 | /// By default, performs semantic analysis to build the new statement. |
| 1195 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1196 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1197 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1198 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1199 | Stmt *Finally) { |
| 1200 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1201 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1204 | /// \brief Rebuild an Objective-C exception declaration. |
| 1205 | /// |
| 1206 | /// By default, performs semantic analysis to build the new declaration. |
| 1207 | /// Subclasses may override this routine to provide different behavior. |
| 1208 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1209 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1210 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1211 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1212 | ExceptionDecl->getLocation()); |
| 1213 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1214 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1215 | /// \brief Build a new Objective-C @catch statement. |
| 1216 | /// |
| 1217 | /// By default, performs semantic analysis to build the new statement. |
| 1218 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1219 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1220 | SourceLocation RParenLoc, |
| 1221 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1222 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1223 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1224 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1225 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1226 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1227 | /// \brief Build a new Objective-C @finally statement. |
| 1228 | /// |
| 1229 | /// By default, performs semantic analysis to build the new statement. |
| 1230 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1231 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1232 | Stmt *Body) { |
| 1233 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1234 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1235 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1236 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1237 | /// |
| 1238 | /// By default, performs semantic analysis to build the new statement. |
| 1239 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1240 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1241 | Expr *Operand) { |
| 1242 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1243 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1244 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1245 | /// \brief Build a new Objective-C @synchronized statement. |
| 1246 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1247 | /// By default, performs semantic analysis to build the new statement. |
| 1248 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1249 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1250 | Expr *Object, |
| 1251 | Stmt *Body) { |
| 1252 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, |
| 1253 | Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1254 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1255 | |
| 1256 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1257 | /// |
| 1258 | /// By default, performs semantic analysis to build the new statement. |
| 1259 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1260 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1261 | SourceLocation LParenLoc, |
| 1262 | Stmt *Element, |
| 1263 | Expr *Collection, |
| 1264 | SourceLocation RParenLoc, |
| 1265 | Stmt *Body) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1266 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1267 | Element, |
| 1268 | Collection, |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1269 | RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1270 | Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1271 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1272 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1273 | /// \brief Build a new C++ exception declaration. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new decaration. |
| 1276 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1277 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1278 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1279 | IdentifierInfo *Name, |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1280 | SourceLocation Loc) { |
| 1281 | return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | /// \brief Build a new C++ catch statement. |
| 1285 | /// |
| 1286 | /// By default, performs semantic analysis to build the new statement. |
| 1287 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1288 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1289 | VarDecl *ExceptionDecl, |
| 1290 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1291 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1292 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1293 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1295 | /// \brief Build a new C++ try statement. |
| 1296 | /// |
| 1297 | /// By default, performs semantic analysis to build the new statement. |
| 1298 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1299 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1300 | Stmt *TryBlock, |
| 1301 | MultiStmtArg Handlers) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1302 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1303 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | /// \brief Build a new expression that references a declaration. |
| 1306 | /// |
| 1307 | /// By default, performs semantic analysis to build the new expression. |
| 1308 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1309 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1310 | LookupResult &R, |
| 1311 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1312 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | /// \brief Build a new expression that references a declaration. |
| 1317 | /// |
| 1318 | /// By default, performs semantic analysis to build the new expression. |
| 1319 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1320 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1321 | ValueDecl *VD, |
| 1322 | const DeclarationNameInfo &NameInfo, |
| 1323 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1324 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1325 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1326 | |
| 1327 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1328 | |
| 1329 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | /// |
Douglas Gregor | a16548e | 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 | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1336 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1338 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1341 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1343 | /// By default, performs semantic analysis to build the new expression. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1345 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1346 | SourceLocation OperatorLoc, |
| 1347 | bool isArrow, |
| 1348 | CXXScopeSpec &SS, |
| 1349 | TypeSourceInfo *ScopeType, |
| 1350 | SourceLocation CCLoc, |
| 1351 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1352 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1354 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1356 | /// By default, performs semantic analysis to build the new expression. |
| 1357 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1358 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1359 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1360 | Expr *SubExpr) { |
| 1361 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1362 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1363 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1364 | /// \brief Build a new builtin offsetof expression. |
| 1365 | /// |
| 1366 | /// By default, performs semantic analysis to build the new expression. |
| 1367 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1368 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1369 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1370 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1371 | unsigned NumComponents, |
| 1372 | SourceLocation RParenLoc) { |
| 1373 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1374 | NumComponents, RParenLoc); |
| 1375 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1376 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1377 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | /// By default, performs semantic analysis to build the new expression. |
| 1380 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1381 | ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1382 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1384 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1387 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1388 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1390 | /// By default, performs semantic analysis to build the new expression. |
| 1391 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1392 | ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1393 | bool isSizeOf, SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1394 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1395 | = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1396 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1397 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | return move(Result); |
| 1400 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1402 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | /// By default, performs semantic analysis to build the new expression. |
| 1405 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1406 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1407 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1408 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | SourceLocation RBracketLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1410 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1411 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | RBracketLoc); |
| 1413 | } |
| 1414 | |
| 1415 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | /// By default, performs semantic analysis to build the new expression. |
| 1418 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1419 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1420 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1421 | SourceLocation RParenLoc, |
| 1422 | Expr *ExecConfig = 0) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1423 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1424 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | /// By default, performs semantic analysis to build the new expression. |
| 1430 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1431 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1432 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1433 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1434 | const DeclarationNameInfo &MemberNameInfo, |
| 1435 | ValueDecl *Member, |
| 1436 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1437 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1438 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1439 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1440 | // We have a reference to an unnamed field. This is always the |
| 1441 | // base of an anonymous struct/union member access, i.e. the |
| 1442 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1443 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1444 | assert(Member->getType()->isRecordType() && |
| 1445 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1447 | if (getSema().PerformObjectMemberConversion(Base, |
| 1448 | QualifierLoc.getNestedNameSpecifier(), |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1449 | FoundDecl, Member)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1450 | return ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1451 | |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1452 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1454 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1455 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1456 | cast<FieldDecl>(Member)->getType(), |
| 1457 | VK, OK_Ordinary); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1458 | return getSema().Owned(ME); |
| 1459 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1460 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1461 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1462 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1463 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1464 | getSema().DefaultFunctionArrayConversion(Base); |
| 1465 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1466 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1467 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1468 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1469 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1470 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1471 | R.resolveKind(); |
| 1472 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1473 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1474 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1475 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1476 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1477 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1478 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | /// By default, performs semantic analysis to build the new expression. |
| 1481 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1482 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1483 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1484 | Expr *LHS, Expr *RHS) { |
| 1485 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | /// By default, performs semantic analysis to build the new expression. |
| 1491 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1492 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1493 | SourceLocation QuestionLoc, |
| 1494 | Expr *LHS, |
| 1495 | SourceLocation ColonLoc, |
| 1496 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1497 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1498 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1502 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | /// By default, performs semantic analysis to build the new expression. |
| 1504 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1505 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1506 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1508 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1509 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1510 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1515 | /// By default, performs semantic analysis to build the new expression. |
| 1516 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1517 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1518 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1519 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1520 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1521 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1522 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | /// By default, performs semantic analysis to build the new expression. |
| 1528 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1529 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | SourceLocation OpLoc, |
| 1531 | SourceLocation AccessorLoc, |
| 1532 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1533 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1534 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1535 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1536 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1537 | OpLoc, /*IsArrow*/ false, |
| 1538 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1539 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1540 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1541 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1543 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1544 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1545 | /// By default, performs semantic analysis to build the new expression. |
| 1546 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1547 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1549 | SourceLocation RBraceLoc, |
| 1550 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1551 | ExprResult Result |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1552 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1553 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1554 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1555 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1556 | // Patch in the result type we were given, which may have been computed |
| 1557 | // when the initial InitListExpr was built. |
| 1558 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1559 | ILE->setType(ResultTy); |
| 1560 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1562 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1563 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1564 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | /// By default, performs semantic analysis to build the new expression. |
| 1566 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1567 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | MultiExprArg ArrayExprs, |
| 1569 | SourceLocation EqualOrColonLoc, |
| 1570 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1571 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1572 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1573 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1574 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1575 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1576 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1577 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | ArrayExprs.release(); |
| 1579 | return move(Result); |
| 1580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1584 | /// By default, builds the implicit value initialization without performing |
| 1585 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1586 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1587 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1588 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1589 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1590 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | /// By default, performs semantic analysis to build the new expression. |
| 1594 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1595 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1596 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1597 | SourceLocation RParenLoc) { |
| 1598 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1599 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1600 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1604 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1605 | /// By default, performs semantic analysis to build the new expression. |
| 1606 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1607 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | MultiExprArg SubExprs, |
| 1609 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1610 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1611 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | /// |
| 1616 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | /// rather than attempting to map the label statement itself. |
| 1618 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1619 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1620 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1621 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1623 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1624 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | /// By default, performs semantic analysis to build the new expression. |
| 1627 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1628 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1629 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1631 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | /// \brief Build a new __builtin_choose_expr expression. |
| 1635 | /// |
| 1636 | /// By default, performs semantic analysis to build the new expression. |
| 1637 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1638 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1639 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | SourceLocation RParenLoc) { |
| 1641 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1642 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | RParenLoc); |
| 1644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | /// \brief Build a new overloaded operator call expression. |
| 1647 | /// |
| 1648 | /// By default, performs semantic analysis to build the new expression. |
| 1649 | /// The semantic analysis provides the behavior of template instantiation, |
| 1650 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1653 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1654 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1656 | Expr *Callee, |
| 1657 | Expr *First, |
| 1658 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | |
| 1660 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | /// reinterpret_cast. |
| 1662 | /// |
| 1663 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1665 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1666 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1667 | Stmt::StmtClass Class, |
| 1668 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1669 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1670 | SourceLocation RAngleLoc, |
| 1671 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1672 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | SourceLocation RParenLoc) { |
| 1674 | switch (Class) { |
| 1675 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1676 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1677 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1678 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | |
| 1680 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1681 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1683 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1685 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1686 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1687 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1688 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1692 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1694 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | default: |
| 1697 | assert(false && "Invalid C++ named cast"); |
| 1698 | break; |
| 1699 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1700 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1701 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1703 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | /// \brief Build a new C++ static_cast expression. |
| 1705 | /// |
| 1706 | /// By default, performs semantic analysis to build the new expression. |
| 1707 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1708 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1709 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1710 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1711 | SourceLocation RAngleLoc, |
| 1712 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1713 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1715 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1716 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1717 | SourceRange(LAngleLoc, RAngleLoc), |
| 1718 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | /// \brief Build a new C++ dynamic_cast expression. |
| 1722 | /// |
| 1723 | /// By default, performs semantic analysis to build the new expression. |
| 1724 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1725 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1727 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | SourceLocation RAngleLoc, |
| 1729 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1730 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1731 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1732 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1733 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1734 | SourceRange(LAngleLoc, RAngleLoc), |
| 1735 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1739 | /// |
| 1740 | /// By default, performs semantic analysis to build the new expression. |
| 1741 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1742 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1743 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1744 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1745 | SourceLocation RAngleLoc, |
| 1746 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1747 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1748 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1749 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1750 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1751 | SourceRange(LAngleLoc, RAngleLoc), |
| 1752 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | /// \brief Build a new C++ const_cast expression. |
| 1756 | /// |
| 1757 | /// By default, performs semantic analysis to build the new expression. |
| 1758 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1759 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1760 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1761 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1762 | SourceLocation RAngleLoc, |
| 1763 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1764 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1765 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1766 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1767 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1768 | SourceRange(LAngleLoc, RAngleLoc), |
| 1769 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1772 | /// \brief Build a new C++ functional-style cast expression. |
| 1773 | /// |
| 1774 | /// By default, performs semantic analysis to build the new expression. |
| 1775 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1776 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1777 | SourceLocation LParenLoc, |
| 1778 | Expr *Sub, |
| 1779 | SourceLocation RParenLoc) { |
| 1780 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1781 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1782 | RParenLoc); |
| 1783 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1785 | /// \brief Build a new C++ typeid(type) expression. |
| 1786 | /// |
| 1787 | /// By default, performs semantic analysis to build the new expression. |
| 1788 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1789 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1790 | SourceLocation TypeidLoc, |
| 1791 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1792 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1793 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1794 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1797 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | /// \brief Build a new C++ typeid(expr) expression. |
| 1799 | /// |
| 1800 | /// By default, performs semantic analysis to build the new expression. |
| 1801 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1802 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1803 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1804 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1805 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1806 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1807 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1810 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1811 | /// |
| 1812 | /// By default, performs semantic analysis to build the new expression. |
| 1813 | /// Subclasses may override this routine to provide different behavior. |
| 1814 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1815 | SourceLocation TypeidLoc, |
| 1816 | TypeSourceInfo *Operand, |
| 1817 | SourceLocation RParenLoc) { |
| 1818 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1819 | RParenLoc); |
| 1820 | } |
| 1821 | |
| 1822 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1823 | /// |
| 1824 | /// By default, performs semantic analysis to build the new expression. |
| 1825 | /// Subclasses may override this routine to provide different behavior. |
| 1826 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1827 | SourceLocation TypeidLoc, |
| 1828 | Expr *Operand, |
| 1829 | SourceLocation RParenLoc) { |
| 1830 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1831 | RParenLoc); |
| 1832 | } |
| 1833 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1834 | /// \brief Build a new C++ "this" expression. |
| 1835 | /// |
| 1836 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1838 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1839 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1840 | QualType ThisType, |
| 1841 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1842 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1843 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1844 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | /// \brief Build a new C++ throw expression. |
| 1848 | /// |
| 1849 | /// By default, performs semantic analysis to build the new expression. |
| 1850 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1851 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1852 | return getSema().ActOnCXXThrow(ThrowLoc, Sub); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | /// \brief Build a new C++ default-argument expression. |
| 1856 | /// |
| 1857 | /// By default, builds a new default-argument expression, which does not |
| 1858 | /// require any semantic analysis. Subclasses may override this routine to |
| 1859 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1860 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1861 | ParmVarDecl *Param) { |
| 1862 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1863 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | /// \brief Build a new C++ zero-initialization expression. |
| 1867 | /// |
| 1868 | /// By default, performs semantic analysis to build the new expression. |
| 1869 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1870 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1871 | SourceLocation LParenLoc, |
| 1872 | SourceLocation RParenLoc) { |
| 1873 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1875 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | /// \brief Build a new C++ "new" expression. |
| 1879 | /// |
| 1880 | /// By default, performs semantic analysis to build the new expression. |
| 1881 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1882 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1883 | bool UseGlobal, |
| 1884 | SourceLocation PlacementLParen, |
| 1885 | MultiExprArg PlacementArgs, |
| 1886 | SourceLocation PlacementRParen, |
| 1887 | SourceRange TypeIdParens, |
| 1888 | QualType AllocatedType, |
| 1889 | TypeSourceInfo *AllocatedTypeInfo, |
| 1890 | Expr *ArraySize, |
| 1891 | SourceLocation ConstructorLParen, |
| 1892 | MultiExprArg ConstructorArgs, |
| 1893 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1895 | PlacementLParen, |
| 1896 | move(PlacementArgs), |
| 1897 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1898 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1899 | AllocatedType, |
| 1900 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1901 | ArraySize, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1902 | ConstructorLParen, |
| 1903 | move(ConstructorArgs), |
| 1904 | ConstructorRParen); |
| 1905 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1906 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1907 | /// \brief Build a new C++ "delete" expression. |
| 1908 | /// |
| 1909 | /// By default, performs semantic analysis to build the new expression. |
| 1910 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1911 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1912 | bool IsGlobalDelete, |
| 1913 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1914 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1915 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1916 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1917 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | /// \brief Build a new unary type trait expression. |
| 1920 | /// |
| 1921 | /// By default, performs semantic analysis to build the new expression. |
| 1922 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1923 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1924 | SourceLocation StartLoc, |
| 1925 | TypeSourceInfo *T, |
| 1926 | SourceLocation RParenLoc) { |
| 1927 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1930 | /// \brief Build a new binary type trait expression. |
| 1931 | /// |
| 1932 | /// By default, performs semantic analysis to build the new expression. |
| 1933 | /// Subclasses may override this routine to provide different behavior. |
| 1934 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1935 | SourceLocation StartLoc, |
| 1936 | TypeSourceInfo *LhsT, |
| 1937 | TypeSourceInfo *RhsT, |
| 1938 | SourceLocation RParenLoc) { |
| 1939 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1940 | } |
| 1941 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1942 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | /// 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 | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1947 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 1948 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1949 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1950 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1951 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1952 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1953 | |
| 1954 | if (TemplateArgs) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1955 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1956 | *TemplateArgs); |
| 1957 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1958 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | /// \brief Build a new template-id expression. |
| 1962 | /// |
| 1963 | /// By default, performs semantic analysis to build the new expression. |
| 1964 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1965 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1966 | LookupResult &R, |
| 1967 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1968 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1969 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | /// \brief Build a new object-construction expression. |
| 1973 | /// |
| 1974 | /// By default, performs semantic analysis to build the new expression. |
| 1975 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1976 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1977 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | CXXConstructorDecl *Constructor, |
| 1979 | bool IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1980 | MultiExprArg Args, |
| 1981 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1982 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 1983 | SourceRange ParenRange) { |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1984 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1985 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1986 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1987 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1988 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1989 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1990 | move_arg(ConvertedArgs), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1991 | RequiresZeroInit, ConstructKind, |
| 1992 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | /// \brief Build a new object-construction expression. |
| 1996 | /// |
| 1997 | /// By default, performs semantic analysis to build the new expression. |
| 1998 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1999 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2000 | SourceLocation LParenLoc, |
| 2001 | MultiExprArg Args, |
| 2002 | SourceLocation RParenLoc) { |
| 2003 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2004 | LParenLoc, |
| 2005 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2006 | RParenLoc); |
| 2007 | } |
| 2008 | |
| 2009 | /// \brief Build a new object-construction expression. |
| 2010 | /// |
| 2011 | /// By default, performs semantic analysis to build the new expression. |
| 2012 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2013 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2014 | SourceLocation LParenLoc, |
| 2015 | MultiExprArg Args, |
| 2016 | SourceLocation RParenLoc) { |
| 2017 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2018 | LParenLoc, |
| 2019 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2020 | RParenLoc); |
| 2021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2023 | /// \brief Build a new member reference expression. |
| 2024 | /// |
| 2025 | /// By default, performs semantic analysis to build the new expression. |
| 2026 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2027 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2028 | QualType BaseType, |
| 2029 | bool IsArrow, |
| 2030 | SourceLocation OperatorLoc, |
| 2031 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2032 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2033 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2034 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2035 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2036 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2037 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2038 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2039 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2040 | SS, FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2041 | MemberNameInfo, |
| 2042 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2045 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2046 | /// |
| 2047 | /// By default, performs semantic analysis to build the new expression. |
| 2048 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2049 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2050 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2051 | SourceLocation OperatorLoc, |
| 2052 | bool IsArrow, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2053 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2054 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2055 | LookupResult &R, |
| 2056 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2057 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2058 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2059 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2060 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2061 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2062 | SS, FirstQualifierInScope, |
| 2063 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2065 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2066 | /// \brief Build a new noexcept expression. |
| 2067 | /// |
| 2068 | /// By default, performs semantic analysis to build the new expression. |
| 2069 | /// Subclasses may override this routine to provide different behavior. |
| 2070 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2071 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2072 | } |
| 2073 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2074 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2075 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2076 | SourceLocation PackLoc, |
| 2077 | SourceLocation RParenLoc, |
| 2078 | unsigned Length) { |
| 2079 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2080 | OperatorLoc, Pack, PackLoc, |
| 2081 | RParenLoc, Length); |
| 2082 | } |
| 2083 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2084 | /// \brief Build a new Objective-C @encode expression. |
| 2085 | /// |
| 2086 | /// By default, performs semantic analysis to build the new expression. |
| 2087 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2088 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2089 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2090 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2091 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2092 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2093 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2095 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2096 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2097 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2098 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2099 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2100 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2101 | MultiExprArg Args, |
| 2102 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2103 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2104 | ReceiverTypeInfo->getType(), |
| 2105 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2106 | Sel, Method, LBracLoc, SelectorLoc, |
| 2107 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2111 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2112 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2113 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2114 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2115 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2116 | MultiExprArg Args, |
| 2117 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2118 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2119 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2120 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2121 | Sel, Method, LBracLoc, SelectorLoc, |
| 2122 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2125 | /// \brief Build a new Objective-C ivar reference expression. |
| 2126 | /// |
| 2127 | /// By default, performs semantic analysis to build the new expression. |
| 2128 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2129 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2130 | SourceLocation IvarLoc, |
| 2131 | bool IsArrow, bool IsFreeIvar) { |
| 2132 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2133 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2134 | Expr *Base = BaseArg; |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2135 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2136 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2137 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2138 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2139 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2140 | false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2141 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2142 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2143 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2144 | if (Result.get()) |
| 2145 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2146 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2147 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2148 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2149 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2150 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2151 | /*TemplateArgs=*/0); |
| 2152 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2153 | |
| 2154 | /// \brief Build a new Objective-C property reference expression. |
| 2155 | /// |
| 2156 | /// By default, performs semantic analysis to build the new expression. |
| 2157 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2158 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2159 | ObjCPropertyDecl *Property, |
| 2160 | SourceLocation PropertyLoc) { |
| 2161 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2162 | Expr *Base = BaseArg; |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2163 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2164 | Sema::LookupMemberName); |
| 2165 | bool IsArrow = false; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2166 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2167 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2168 | SS, 0, false); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2169 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2170 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2172 | if (Result.get()) |
| 2173 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2174 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2175 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2176 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2177 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2178 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2179 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2180 | /*TemplateArgs=*/0); |
| 2181 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2182 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2183 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2184 | /// |
| 2185 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2186 | /// Subclasses may override this routine to provide different behavior. |
| 2187 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2188 | ObjCMethodDecl *Getter, |
| 2189 | ObjCMethodDecl *Setter, |
| 2190 | SourceLocation PropertyLoc) { |
| 2191 | // Since these expressions can only be value-dependent, we do not |
| 2192 | // need to perform semantic analysis again. |
| 2193 | return Owned( |
| 2194 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2195 | VK_LValue, OK_ObjCProperty, |
| 2196 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2199 | /// \brief Build a new Objective-C "isa" expression. |
| 2200 | /// |
| 2201 | /// By default, performs semantic analysis to build the new expression. |
| 2202 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2203 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2204 | bool IsArrow) { |
| 2205 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2206 | Expr *Base = BaseArg; |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2207 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2208 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2209 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2210 | /*FIME:*/IsaLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2211 | SS, 0, false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2212 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2213 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2214 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2215 | if (Result.get()) |
| 2216 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2217 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2218 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2219 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2220 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2221 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2222 | /*TemplateArgs=*/0); |
| 2223 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2224 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2225 | /// \brief Build a new shuffle vector expression. |
| 2226 | /// |
| 2227 | /// By default, performs semantic analysis to build the new expression. |
| 2228 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2229 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2230 | MultiExprArg SubExprs, |
| 2231 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2232 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2234 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2235 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2236 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2237 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2238 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2239 | // Build a reference to the __builtin_shufflevector builtin |
| 2240 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2241 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2242 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2243 | VK_LValue, BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2244 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2245 | |
| 2246 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2247 | unsigned NumSubExprs = SubExprs.size(); |
| 2248 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2249 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 2250 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2251 | Builtin->getCallResultType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2252 | Expr::getValueKindForType(Builtin->getResultType()), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2253 | RParenLoc); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2254 | ExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2256 | // Type-check the __builtin_shufflevector expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2257 | ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2258 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2259 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2261 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2262 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2263 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2265 | /// \brief Build a new template argument pack expansion. |
| 2266 | /// |
| 2267 | /// By default, performs semantic analysis to build a new pack expansion |
| 2268 | /// for a template argument. Subclasses may override this routine to provide |
| 2269 | /// different behavior. |
| 2270 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2271 | SourceLocation EllipsisLoc, |
| 2272 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2273 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2274 | case TemplateArgument::Expression: { |
| 2275 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2276 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2277 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2278 | if (Result.isInvalid()) |
| 2279 | return TemplateArgumentLoc(); |
| 2280 | |
| 2281 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2282 | } |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2283 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2284 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2285 | return TemplateArgumentLoc(TemplateArgument( |
| 2286 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2287 | NumExpansions), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2288 | Pattern.getTemplateQualifierRange(), |
| 2289 | Pattern.getTemplateNameLoc(), |
| 2290 | EllipsisLoc); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2291 | |
| 2292 | case TemplateArgument::Null: |
| 2293 | case TemplateArgument::Integral: |
| 2294 | case TemplateArgument::Declaration: |
| 2295 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2296 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2297 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2298 | |
| 2299 | case TemplateArgument::Type: |
| 2300 | if (TypeSourceInfo *Expansion |
| 2301 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2302 | EllipsisLoc, |
| 2303 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2304 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2305 | Expansion); |
| 2306 | break; |
| 2307 | } |
| 2308 | |
| 2309 | return TemplateArgumentLoc(); |
| 2310 | } |
| 2311 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2312 | /// \brief Build a new expression pack expansion. |
| 2313 | /// |
| 2314 | /// By default, performs semantic analysis to build a new pack expansion |
| 2315 | /// for an expression. Subclasses may override this routine to provide |
| 2316 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2317 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2318 | llvm::Optional<unsigned> NumExpansions) { |
| 2319 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2322 | private: |
| 2323 | QualType TransformTypeInObjectScope(QualType T, |
| 2324 | QualType ObjectType, |
| 2325 | NamedDecl *FirstQualifierInScope, |
| 2326 | NestedNameSpecifier *Prefix); |
| 2327 | |
| 2328 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T, |
| 2329 | QualType ObjectType, |
| 2330 | NamedDecl *FirstQualifierInScope, |
| 2331 | NestedNameSpecifier *Prefix); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2332 | |
| 2333 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2334 | QualType ObjectType, |
| 2335 | NamedDecl *FirstQualifierInScope, |
| 2336 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2337 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2338 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2339 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2340 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2341 | if (!S) |
| 2342 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2343 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2344 | switch (S->getStmtClass()) { |
| 2345 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2347 | // Transform individual statement nodes |
| 2348 | #define STMT(Node, Parent) \ |
| 2349 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2350 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2351 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2352 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2353 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2354 | // Transform expressions by calling TransformExpr. |
| 2355 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2356 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2357 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2358 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2359 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2360 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2361 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2362 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2363 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2364 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2365 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2368 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2370 | |
| 2371 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2372 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2373 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2374 | if (!E) |
| 2375 | return SemaRef.Owned(E); |
| 2376 | |
| 2377 | switch (E->getStmtClass()) { |
| 2378 | case Stmt::NoStmtClass: break; |
| 2379 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2380 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2381 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2382 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2383 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2386 | return SemaRef.Owned(E); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | template<typename Derived> |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2390 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2391 | unsigned NumInputs, |
| 2392 | bool IsCall, |
| 2393 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 2394 | bool *ArgChanged) { |
| 2395 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2396 | // If requested, drop call arguments that need to be dropped. |
| 2397 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2398 | if (ArgChanged) |
| 2399 | *ArgChanged = true; |
| 2400 | |
| 2401 | break; |
| 2402 | } |
| 2403 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2404 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2405 | Expr *Pattern = Expansion->getPattern(); |
| 2406 | |
| 2407 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2408 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2409 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2410 | |
| 2411 | // Determine whether the set of unexpanded parameter packs can and should |
| 2412 | // be expanded. |
| 2413 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2414 | bool RetainExpansion = false; |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2415 | llvm::Optional<unsigned> OrigNumExpansions |
| 2416 | = Expansion->getNumExpansions(); |
| 2417 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2418 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2419 | Pattern->getSourceRange(), |
| 2420 | Unexpanded.data(), |
| 2421 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2422 | Expand, RetainExpansion, |
| 2423 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2424 | return true; |
| 2425 | |
| 2426 | if (!Expand) { |
| 2427 | // The transform has determined that we should perform a simple |
| 2428 | // transformation on the pack expansion, producing another pack |
| 2429 | // expansion. |
| 2430 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2431 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2432 | if (OutPattern.isInvalid()) |
| 2433 | return true; |
| 2434 | |
| 2435 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2436 | Expansion->getEllipsisLoc(), |
| 2437 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2438 | if (Out.isInvalid()) |
| 2439 | return true; |
| 2440 | |
| 2441 | if (ArgChanged) |
| 2442 | *ArgChanged = true; |
| 2443 | Outputs.push_back(Out.get()); |
| 2444 | continue; |
| 2445 | } |
| 2446 | |
| 2447 | // The transform has determined that we should perform an elementwise |
| 2448 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2449 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2450 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2451 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2452 | if (Out.isInvalid()) |
| 2453 | return true; |
| 2454 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2455 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2456 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2457 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2458 | if (Out.isInvalid()) |
| 2459 | return true; |
| 2460 | } |
| 2461 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2462 | if (ArgChanged) |
| 2463 | *ArgChanged = true; |
| 2464 | Outputs.push_back(Out.get()); |
| 2465 | } |
| 2466 | |
| 2467 | continue; |
| 2468 | } |
| 2469 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2470 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2471 | if (Result.isInvalid()) |
| 2472 | return true; |
| 2473 | |
| 2474 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2475 | *ArgChanged = true; |
| 2476 | |
| 2477 | Outputs.push_back(Result.get()); |
| 2478 | } |
| 2479 | |
| 2480 | return false; |
| 2481 | } |
| 2482 | |
| 2483 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2484 | NestedNameSpecifier * |
| 2485 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2486 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2487 | QualType ObjectType, |
| 2488 | NamedDecl *FirstQualifierInScope) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2489 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2490 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2491 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2492 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2493 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2494 | ObjectType, |
| 2495 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2496 | if (!Prefix) |
| 2497 | return 0; |
| 2498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2499 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2500 | switch (NNS->getKind()) { |
| 2501 | case NestedNameSpecifier::Identifier: |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2502 | if (Prefix) { |
| 2503 | // The object type and qualifier-in-scope really apply to the |
| 2504 | // leftmost entity. |
| 2505 | ObjectType = QualType(); |
| 2506 | FirstQualifierInScope = 0; |
| 2507 | } |
| 2508 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2509 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2510 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2511 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2512 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2513 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2514 | |
| 2515 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2516 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2517 | ObjectType, |
| 2518 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2519 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2520 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2521 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2522 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2523 | getDerived().TransformDecl(Range.getBegin(), |
| 2524 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2525 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2526 | Prefix == NNS->getPrefix() && |
| 2527 | NS == NNS->getAsNamespace()) |
| 2528 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2529 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2530 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2532 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 2533 | case NestedNameSpecifier::NamespaceAlias: { |
| 2534 | NamespaceAliasDecl *Alias |
| 2535 | = cast_or_null<NamespaceAliasDecl>( |
| 2536 | getDerived().TransformDecl(Range.getBegin(), |
| 2537 | NNS->getAsNamespaceAlias())); |
| 2538 | if (!getDerived().AlwaysRebuild() && |
| 2539 | Prefix == NNS->getPrefix() && |
| 2540 | Alias == NNS->getAsNamespaceAlias()) |
| 2541 | return NNS; |
| 2542 | |
| 2543 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias); |
| 2544 | } |
| 2545 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2546 | case NestedNameSpecifier::Global: |
| 2547 | // There is no meaningful transformation that one could perform on the |
| 2548 | // global scope. |
| 2549 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2550 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2551 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2552 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2553 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2554 | QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0), |
| 2555 | ObjectType, |
| 2556 | FirstQualifierInScope, |
| 2557 | Prefix); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2558 | if (T.isNull()) |
| 2559 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2560 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2561 | if (!getDerived().AlwaysRebuild() && |
| 2562 | Prefix == NNS->getPrefix() && |
| 2563 | T == QualType(NNS->getAsType(), 0)) |
| 2564 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | |
| 2566 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2567 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2568 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2569 | } |
| 2570 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2571 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2572 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2573 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2577 | NestedNameSpecifierLoc |
| 2578 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2579 | NestedNameSpecifierLoc NNS, |
| 2580 | QualType ObjectType, |
| 2581 | NamedDecl *FirstQualifierInScope) { |
| 2582 | llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 2583 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2584 | Qualifier = Qualifier.getPrefix()) |
| 2585 | Qualifiers.push_back(Qualifier); |
| 2586 | |
| 2587 | CXXScopeSpec SS; |
| 2588 | while (!Qualifiers.empty()) { |
| 2589 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2590 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2591 | |
| 2592 | switch (QNNS->getKind()) { |
| 2593 | case NestedNameSpecifier::Identifier: |
| 2594 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2595 | *QNNS->getAsIdentifier(), |
| 2596 | Q.getLocalBeginLoc(), |
| 2597 | Q.getLocalEndLoc(), |
| 2598 | ObjectType, false, SS, |
| 2599 | FirstQualifierInScope, false)) |
| 2600 | return NestedNameSpecifierLoc(); |
| 2601 | |
| 2602 | break; |
| 2603 | |
| 2604 | case NestedNameSpecifier::Namespace: { |
| 2605 | NamespaceDecl *NS |
| 2606 | = cast_or_null<NamespaceDecl>( |
| 2607 | getDerived().TransformDecl( |
| 2608 | Q.getLocalBeginLoc(), |
| 2609 | QNNS->getAsNamespace())); |
| 2610 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2611 | break; |
| 2612 | } |
| 2613 | |
| 2614 | case NestedNameSpecifier::NamespaceAlias: { |
| 2615 | NamespaceAliasDecl *Alias |
| 2616 | = cast_or_null<NamespaceAliasDecl>( |
| 2617 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2618 | QNNS->getAsNamespaceAlias())); |
| 2619 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2620 | Q.getLocalEndLoc()); |
| 2621 | break; |
| 2622 | } |
| 2623 | |
| 2624 | case NestedNameSpecifier::Global: |
| 2625 | // There is no meaningful transformation that one could perform on the |
| 2626 | // global scope. |
| 2627 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2628 | break; |
| 2629 | |
| 2630 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2631 | case NestedNameSpecifier::TypeSpec: { |
| 2632 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2633 | FirstQualifierInScope, SS); |
| 2634 | |
| 2635 | if (!TL) |
| 2636 | return NestedNameSpecifierLoc(); |
| 2637 | |
| 2638 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 2639 | (SemaRef.getLangOptions().CPlusPlus0x && |
| 2640 | TL.getType()->isEnumeralType())) { |
| 2641 | assert(!TL.getType().hasLocalQualifiers() && |
| 2642 | "Can't get cv-qualifiers here"); |
| 2643 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2644 | Q.getLocalEndLoc()); |
| 2645 | break; |
| 2646 | } |
| 2647 | |
| 2648 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2649 | << TL.getType() << SS.getRange(); |
| 2650 | return NestedNameSpecifierLoc(); |
| 2651 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2652 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2653 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2654 | // The qualifier-in-scope and object type only apply to the leftmost entity. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2655 | FirstQualifierInScope = 0; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2656 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2660 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2661 | !getDerived().AlwaysRebuild()) |
| 2662 | return NNS; |
| 2663 | |
| 2664 | // If we can re-use the source-location data from the original |
| 2665 | // nested-name-specifier, do so. |
| 2666 | if (SS.location_size() == NNS.getDataLength() && |
| 2667 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2668 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2669 | |
| 2670 | // Allocate new nested-name-specifier location information. |
| 2671 | return SS.getWithLocInContext(SemaRef.Context); |
| 2672 | } |
| 2673 | |
| 2674 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2675 | DeclarationNameInfo |
| 2676 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2677 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2678 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2679 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2680 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2681 | |
| 2682 | switch (Name.getNameKind()) { |
| 2683 | case DeclarationName::Identifier: |
| 2684 | case DeclarationName::ObjCZeroArgSelector: |
| 2685 | case DeclarationName::ObjCOneArgSelector: |
| 2686 | case DeclarationName::ObjCMultiArgSelector: |
| 2687 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2688 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2689 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2690 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2692 | case DeclarationName::CXXConstructorName: |
| 2693 | case DeclarationName::CXXDestructorName: |
| 2694 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2695 | TypeSourceInfo *NewTInfo; |
| 2696 | CanQualType NewCanTy; |
| 2697 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2698 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2699 | if (!NewTInfo) |
| 2700 | return DeclarationNameInfo(); |
| 2701 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2702 | } |
| 2703 | else { |
| 2704 | NewTInfo = 0; |
| 2705 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2706 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2707 | if (NewT.isNull()) |
| 2708 | return DeclarationNameInfo(); |
| 2709 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2712 | DeclarationName NewName |
| 2713 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2714 | NewCanTy); |
| 2715 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2716 | NewNameInfo.setName(NewName); |
| 2717 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2718 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2719 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2722 | assert(0 && "Unknown name kind."); |
| 2723 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2727 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2728 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2729 | QualType ObjectType, |
| 2730 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2731 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2732 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2733 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2734 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2735 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2736 | /*FIXME*/ SourceRange(Loc), |
| 2737 | ObjectType, |
| 2738 | FirstQualifierInScope); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2739 | if (!NNS) |
| 2740 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2742 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2743 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2744 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2745 | if (!TransTemplate) |
| 2746 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2747 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2748 | if (!getDerived().AlwaysRebuild() && |
| 2749 | NNS == QTN->getQualifier() && |
| 2750 | TransTemplate == Template) |
| 2751 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2752 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2753 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2754 | TransTemplate); |
| 2755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2756 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2757 | // These should be getting filtered out before they make it into the AST. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2758 | llvm_unreachable("overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2759 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2760 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2761 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2762 | NestedNameSpecifier *NNS = DTN->getQualifier(); |
| 2763 | if (NNS) { |
| 2764 | NNS = getDerived().TransformNestedNameSpecifier(NNS, |
| 2765 | /*FIXME:*/SourceRange(Loc), |
| 2766 | ObjectType, |
| 2767 | FirstQualifierInScope); |
| 2768 | if (!NNS) return TemplateName(); |
| 2769 | |
| 2770 | // These apply to the scope specifier, not the template. |
| 2771 | ObjectType = QualType(); |
| 2772 | FirstQualifierInScope = 0; |
| 2773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2774 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2775 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2776 | NNS == DTN->getQualifier() && |
| 2777 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2778 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2779 | |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2780 | if (DTN->isIdentifier()) { |
| 2781 | // FIXME: Bad range |
| 2782 | SourceRange QualifierRange(getDerived().getBaseLocation()); |
| 2783 | return getDerived().RebuildTemplateName(NNS, QualifierRange, |
| 2784 | *DTN->getIdentifier(), |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2785 | ObjectType, |
| 2786 | FirstQualifierInScope); |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2787 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2788 | |
| 2789 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2790 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2791 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2793 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2795 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2796 | if (!TransTemplate) |
| 2797 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2798 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2799 | if (!getDerived().AlwaysRebuild() && |
| 2800 | TransTemplate == Template) |
| 2801 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2803 | return TemplateName(TransTemplate); |
| 2804 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2805 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 2806 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2807 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2808 | TemplateTemplateParmDecl *TransParam |
| 2809 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2810 | getDerived().TransformDecl(Loc, SubstPack->getParameterPack())); |
| 2811 | if (!TransParam) |
| 2812 | return TemplateName(); |
| 2813 | |
| 2814 | if (!getDerived().AlwaysRebuild() && |
| 2815 | TransParam == SubstPack->getParameterPack()) |
| 2816 | return Name; |
| 2817 | |
| 2818 | return getDerived().RebuildTemplateName(TransParam, |
| 2819 | SubstPack->getArgumentPack()); |
| 2820 | } |
| 2821 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2822 | // These should be getting filtered out before they reach the AST. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2823 | llvm_unreachable("overloaded function decl survived to here"); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2824 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2828 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2829 | const TemplateArgument &Arg, |
| 2830 | TemplateArgumentLoc &Output) { |
| 2831 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2832 | switch (Arg.getKind()) { |
| 2833 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2834 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | |
| 2837 | case TemplateArgument::Type: |
| 2838 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2839 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2840 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2841 | break; |
| 2842 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2843 | case TemplateArgument::Template: |
| 2844 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2845 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2846 | |
| 2847 | case TemplateArgument::TemplateExpansion: |
| 2848 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc); |
| 2849 | break; |
| 2850 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2851 | case TemplateArgument::Expression: |
| 2852 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2853 | break; |
| 2854 | |
| 2855 | case TemplateArgument::Declaration: |
| 2856 | case TemplateArgument::Integral: |
| 2857 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2858 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | template<typename Derived> |
| 2864 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2865 | const TemplateArgumentLoc &Input, |
| 2866 | TemplateArgumentLoc &Output) { |
| 2867 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2868 | switch (Arg.getKind()) { |
| 2869 | case TemplateArgument::Null: |
| 2870 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2871 | Output = Input; |
| 2872 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2873 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2874 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2875 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2876 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2877 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2878 | |
| 2879 | DI = getDerived().TransformType(DI); |
| 2880 | if (!DI) return true; |
| 2881 | |
| 2882 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2883 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2884 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2885 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2886 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2887 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2888 | DeclarationName Name; |
| 2889 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2890 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2891 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2892 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2893 | if (!D) return true; |
| 2894 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2895 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2896 | if (SourceExpr) { |
| 2897 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2898 | Sema::Unevaluated); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2899 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2900 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2904 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2905 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2906 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2907 | case TemplateArgument::Template: { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2908 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2909 | TemplateName Template |
| 2910 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2911 | if (Template.isNull()) |
| 2912 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2913 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2914 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2915 | Input.getTemplateQualifierRange(), |
| 2916 | Input.getTemplateNameLoc()); |
| 2917 | return false; |
| 2918 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2919 | |
| 2920 | case TemplateArgument::TemplateExpansion: |
| 2921 | llvm_unreachable("Caller should expand pack expansions"); |
| 2922 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2923 | case TemplateArgument::Expression: { |
| 2924 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2925 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2926 | Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2927 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2928 | Expr *InputExpr = Input.getSourceExpression(); |
| 2929 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2930 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2931 | ExprResult E |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2932 | = getDerived().TransformExpr(InputExpr); |
| 2933 | if (E.isInvalid()) return true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2934 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2935 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2937 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2938 | case TemplateArgument::Pack: { |
| 2939 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2940 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2941 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2942 | AEnd = Arg.pack_end(); |
| 2943 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2944 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2945 | // FIXME: preserve source information here when we start |
| 2946 | // caring about parameter packs. |
| 2947 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2948 | TemplateArgumentLoc InputArg; |
| 2949 | TemplateArgumentLoc OutputArg; |
| 2950 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2951 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2952 | return true; |
| 2953 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2954 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2955 | } |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2956 | |
| 2957 | TemplateArgument *TransformedArgsPtr |
| 2958 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2959 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2960 | TransformedArgsPtr); |
| 2961 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2962 | TransformedArgs.size()), |
| 2963 | Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2964 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2965 | } |
| 2966 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2967 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2968 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2969 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2972 | /// \brief Iterator adaptor that invents template argument location information |
| 2973 | /// for each of the template arguments in its underlying iterator. |
| 2974 | template<typename Derived, typename InputIterator> |
| 2975 | class TemplateArgumentLocInventIterator { |
| 2976 | TreeTransform<Derived> &Self; |
| 2977 | InputIterator Iter; |
| 2978 | |
| 2979 | public: |
| 2980 | typedef TemplateArgumentLoc value_type; |
| 2981 | typedef TemplateArgumentLoc reference; |
| 2982 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2983 | difference_type; |
| 2984 | typedef std::input_iterator_tag iterator_category; |
| 2985 | |
| 2986 | class pointer { |
| 2987 | TemplateArgumentLoc Arg; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2988 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2989 | public: |
| 2990 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2991 | |
| 2992 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2993 | }; |
| 2994 | |
| 2995 | TemplateArgumentLocInventIterator() { } |
| 2996 | |
| 2997 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2998 | InputIterator Iter) |
| 2999 | : Self(Self), Iter(Iter) { } |
| 3000 | |
| 3001 | TemplateArgumentLocInventIterator &operator++() { |
| 3002 | ++Iter; |
| 3003 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3006 | TemplateArgumentLocInventIterator operator++(int) { |
| 3007 | TemplateArgumentLocInventIterator Old(*this); |
| 3008 | ++(*this); |
| 3009 | return Old; |
| 3010 | } |
| 3011 | |
| 3012 | reference operator*() const { |
| 3013 | TemplateArgumentLoc Result; |
| 3014 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3015 | return Result; |
| 3016 | } |
| 3017 | |
| 3018 | pointer operator->() const { return pointer(**this); } |
| 3019 | |
| 3020 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3021 | const TemplateArgumentLocInventIterator &Y) { |
| 3022 | return X.Iter == Y.Iter; |
| 3023 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3024 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3025 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3026 | const TemplateArgumentLocInventIterator &Y) { |
| 3027 | return X.Iter != Y.Iter; |
| 3028 | } |
| 3029 | }; |
| 3030 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3031 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3032 | template<typename InputIterator> |
| 3033 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 3034 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3035 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3036 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3037 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3038 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3039 | |
| 3040 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3041 | // Unpack argument packs, which we translate them into separate |
| 3042 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3043 | // FIXME: We could do much better if we could guarantee that the |
| 3044 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3045 | // all of the template arguments in the argument pack. |
| 3046 | typedef TemplateArgumentLocInventIterator<Derived, |
| 3047 | TemplateArgument::pack_iterator> |
| 3048 | PackLocIterator; |
| 3049 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 3050 | In.getArgument().pack_begin()), |
| 3051 | PackLocIterator(*this, |
| 3052 | In.getArgument().pack_end()), |
| 3053 | Outputs)) |
| 3054 | return true; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3055 | |
| 3056 | continue; |
| 3057 | } |
| 3058 | |
| 3059 | if (In.getArgument().isPackExpansion()) { |
| 3060 | // We have a pack expansion, for which we will be substituting into |
| 3061 | // the pattern. |
| 3062 | SourceLocation Ellipsis; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3063 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3064 | TemplateArgumentLoc Pattern |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3065 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 3066 | getSema().Context); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3067 | |
| 3068 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3069 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3070 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 3071 | |
| 3072 | // Determine whether the set of unexpanded parameter packs can and should |
| 3073 | // be expanded. |
| 3074 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3075 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3076 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3077 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3078 | Pattern.getSourceRange(), |
| 3079 | Unexpanded.data(), |
| 3080 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3081 | Expand, |
| 3082 | RetainExpansion, |
| 3083 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3084 | return true; |
| 3085 | |
| 3086 | if (!Expand) { |
| 3087 | // The transform has determined that we should perform a simple |
| 3088 | // transformation on the pack expansion, producing another pack |
| 3089 | // expansion. |
| 3090 | TemplateArgumentLoc OutPattern; |
| 3091 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3092 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3093 | return true; |
| 3094 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3095 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3096 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3097 | if (Out.getArgument().isNull()) |
| 3098 | return true; |
| 3099 | |
| 3100 | Outputs.addArgument(Out); |
| 3101 | continue; |
| 3102 | } |
| 3103 | |
| 3104 | // The transform has determined that we should perform an elementwise |
| 3105 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3106 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3107 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3108 | |
| 3109 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3110 | return true; |
| 3111 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3112 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3113 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3114 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3115 | if (Out.getArgument().isNull()) |
| 3116 | return true; |
| 3117 | } |
| 3118 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3119 | Outputs.addArgument(Out); |
| 3120 | } |
| 3121 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3122 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3123 | // forgetting the partially-substituted parameter pack. |
| 3124 | if (RetainExpansion) { |
| 3125 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3126 | |
| 3127 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3128 | return true; |
| 3129 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3130 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3131 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3132 | if (Out.getArgument().isNull()) |
| 3133 | return true; |
| 3134 | |
| 3135 | Outputs.addArgument(Out); |
| 3136 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3138 | continue; |
| 3139 | } |
| 3140 | |
| 3141 | // The simple case: |
| 3142 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3143 | return true; |
| 3144 | |
| 3145 | Outputs.addArgument(Out); |
| 3146 | } |
| 3147 | |
| 3148 | return false; |
| 3149 | |
| 3150 | } |
| 3151 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3152 | //===----------------------------------------------------------------------===// |
| 3153 | // Type transformation |
| 3154 | //===----------------------------------------------------------------------===// |
| 3155 | |
| 3156 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3157 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3158 | if (getDerived().AlreadyTransformed(T)) |
| 3159 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3160 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3161 | // Temporary workaround. All of these transformations should |
| 3162 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3163 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3164 | getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3165 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3166 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3167 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3168 | if (!NewDI) |
| 3169 | return QualType(); |
| 3170 | |
| 3171 | return NewDI->getType(); |
| 3172 | } |
| 3173 | |
| 3174 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3175 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3176 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3177 | return DI; |
| 3178 | |
| 3179 | TypeLocBuilder TLB; |
| 3180 | |
| 3181 | TypeLoc TL = DI->getTypeLoc(); |
| 3182 | TLB.reserve(TL.getFullDataSize()); |
| 3183 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3184 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3185 | if (Result.isNull()) |
| 3186 | return 0; |
| 3187 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3188 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | template<typename Derived> |
| 3192 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3193 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3194 | switch (T.getTypeLocClass()) { |
| 3195 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3196 | #define TYPELOC(CLASS, PARENT) \ |
| 3197 | case TypeLoc::CLASS: \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3198 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3199 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3202 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3203 | return QualType(); |
| 3204 | } |
| 3205 | |
| 3206 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3207 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3208 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3209 | /// types). This is the right thing for template instantiation, but |
| 3210 | /// probably not for other clients. |
| 3211 | template<typename Derived> |
| 3212 | QualType |
| 3213 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3214 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3215 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3216 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3217 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3218 | if (Result.isNull()) |
| 3219 | return QualType(); |
| 3220 | |
| 3221 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3222 | // FIXME: this is the right thing for template instantiation, but |
| 3223 | // probably not for other clients. |
| 3224 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3225 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3226 | |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3227 | if (!Quals.empty()) { |
| 3228 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3229 | TLB.push<QualifiedTypeLoc>(Result); |
| 3230 | // No location information to preserve. |
| 3231 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3232 | |
| 3233 | return Result; |
| 3234 | } |
| 3235 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3236 | /// \brief Transforms a type that was written in a scope specifier, |
| 3237 | /// given an object type, the results of unqualified lookup, and |
| 3238 | /// an already-instantiated prefix. |
| 3239 | /// |
| 3240 | /// The object type is provided iff the scope specifier qualifies the |
| 3241 | /// member of a dependent member-access expression. The prefix is |
| 3242 | /// provided iff the the scope specifier in which this appears has a |
| 3243 | /// prefix. |
| 3244 | /// |
| 3245 | /// This is private to TreeTransform. |
| 3246 | template<typename Derived> |
| 3247 | QualType |
| 3248 | TreeTransform<Derived>::TransformTypeInObjectScope(QualType T, |
| 3249 | QualType ObjectType, |
| 3250 | NamedDecl *UnqualLookup, |
| 3251 | NestedNameSpecifier *Prefix) { |
| 3252 | if (getDerived().AlreadyTransformed(T)) |
| 3253 | return T; |
| 3254 | |
| 3255 | TypeSourceInfo *TSI = |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3256 | SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation()); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3257 | |
| 3258 | TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType, |
| 3259 | UnqualLookup, Prefix); |
| 3260 | if (!TSI) return QualType(); |
| 3261 | return TSI->getType(); |
| 3262 | } |
| 3263 | |
| 3264 | template<typename Derived> |
| 3265 | TypeSourceInfo * |
| 3266 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI, |
| 3267 | QualType ObjectType, |
| 3268 | NamedDecl *UnqualLookup, |
| 3269 | NestedNameSpecifier *Prefix) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3270 | // TODO: in some cases, we might have some verification to do here. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3271 | if (ObjectType.isNull()) |
| 3272 | return getDerived().TransformType(TSI); |
| 3273 | |
| 3274 | QualType T = TSI->getType(); |
| 3275 | if (getDerived().AlreadyTransformed(T)) |
| 3276 | return TSI; |
| 3277 | |
| 3278 | TypeLocBuilder TLB; |
| 3279 | QualType Result; |
| 3280 | |
| 3281 | if (isa<TemplateSpecializationType>(T)) { |
| 3282 | TemplateSpecializationTypeLoc TL |
| 3283 | = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3284 | |
| 3285 | TemplateName Template = |
| 3286 | getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(), |
| 3287 | ObjectType, UnqualLookup); |
| 3288 | if (Template.isNull()) return 0; |
| 3289 | |
| 3290 | Result = getDerived() |
| 3291 | .TransformTemplateSpecializationType(TLB, TL, Template); |
| 3292 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3293 | DependentTemplateSpecializationTypeLoc TL |
| 3294 | = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3295 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3296 | TemplateName Template |
| 3297 | = SemaRef.Context.getDependentTemplateName( |
| 3298 | TL.getTypePtr()->getQualifier(), |
| 3299 | TL.getTypePtr()->getIdentifier()); |
| 3300 | |
| 3301 | Template = getDerived().TransformTemplateName(Template, ObjectType, |
| 3302 | UnqualLookup); |
| 3303 | if (Template.isNull()) |
| 3304 | return 0; |
| 3305 | |
| 3306 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL, |
| 3307 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3308 | } else { |
| 3309 | // Nothing special needs to be done for these. |
| 3310 | Result = getDerived().TransformType(TLB, TSI->getTypeLoc()); |
| 3311 | } |
| 3312 | |
| 3313 | if (Result.isNull()) return 0; |
| 3314 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3315 | } |
| 3316 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3317 | template<typename Derived> |
| 3318 | TypeLoc |
| 3319 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3320 | QualType ObjectType, |
| 3321 | NamedDecl *UnqualLookup, |
| 3322 | CXXScopeSpec &SS) { |
| 3323 | // FIXME: Painfully copy-paste from the above! |
| 3324 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3325 | QualType T = TL.getType(); |
| 3326 | if (getDerived().AlreadyTransformed(T)) |
| 3327 | return TL; |
| 3328 | |
| 3329 | TypeLocBuilder TLB; |
| 3330 | QualType Result; |
| 3331 | |
| 3332 | if (isa<TemplateSpecializationType>(T)) { |
| 3333 | TemplateSpecializationTypeLoc SpecTL |
| 3334 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3335 | |
| 3336 | TemplateName Template = |
| 3337 | getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(), |
| 3338 | ObjectType, UnqualLookup); |
| 3339 | if (Template.isNull()) |
| 3340 | return TypeLoc(); |
| 3341 | |
| 3342 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3343 | Template); |
| 3344 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3345 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3346 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3347 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3348 | TemplateName Template |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3349 | = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(), |
| 3350 | *SpecTL.getTypePtr()->getIdentifier(), |
| 3351 | ObjectType, UnqualLookup); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3352 | if (Template.isNull()) |
| 3353 | return TypeLoc(); |
| 3354 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3355 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3356 | SpecTL, |
| 3357 | Template); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3358 | } else { |
| 3359 | // Nothing special needs to be done for these. |
| 3360 | Result = getDerived().TransformType(TLB, TL); |
| 3361 | } |
| 3362 | |
| 3363 | if (Result.isNull()) |
| 3364 | return TypeLoc(); |
| 3365 | |
| 3366 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3367 | } |
| 3368 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3369 | template <class TyLoc> static inline |
| 3370 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3371 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3372 | NewT.setNameLoc(T.getNameLoc()); |
| 3373 | return T.getType(); |
| 3374 | } |
| 3375 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3376 | template<typename Derived> |
| 3377 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3378 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3379 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3380 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3381 | if (T.needsExtraLocalData()) |
| 3382 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3383 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3384 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3385 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3386 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3387 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3388 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3389 | // FIXME: recurse? |
| 3390 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3393 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3394 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3395 | PointerTypeLoc TL) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3396 | QualType PointeeType |
| 3397 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3398 | if (PointeeType.isNull()) |
| 3399 | return QualType(); |
| 3400 | |
| 3401 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3402 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3403 | // A dependent pointer type 'T *' has is being transformed such |
| 3404 | // that an Objective-C class type is being replaced for 'T'. The |
| 3405 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3406 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3407 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3408 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3409 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3410 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3411 | return Result; |
| 3412 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3414 | if (getDerived().AlwaysRebuild() || |
| 3415 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3416 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3417 | if (Result.isNull()) |
| 3418 | return QualType(); |
| 3419 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3420 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3421 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3422 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3423 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | |
| 3426 | template<typename Derived> |
| 3427 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3428 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3429 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3430 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3431 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3432 | if (PointeeType.isNull()) |
| 3433 | return QualType(); |
| 3434 | |
| 3435 | QualType Result = TL.getType(); |
| 3436 | if (getDerived().AlwaysRebuild() || |
| 3437 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3438 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3439 | TL.getSigilLoc()); |
| 3440 | if (Result.isNull()) |
| 3441 | return QualType(); |
| 3442 | } |
| 3443 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3444 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3445 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3446 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3449 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3450 | /// don't care whether the type itself is an l-value type or an r-value |
| 3451 | /// type; we only care if the type was *written* as an l-value type |
| 3452 | /// or an r-value type. |
| 3453 | template<typename Derived> |
| 3454 | QualType |
| 3455 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3456 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3457 | const ReferenceType *T = TL.getTypePtr(); |
| 3458 | |
| 3459 | // Note that this works with the pointee-as-written. |
| 3460 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3461 | if (PointeeType.isNull()) |
| 3462 | return QualType(); |
| 3463 | |
| 3464 | QualType Result = TL.getType(); |
| 3465 | if (getDerived().AlwaysRebuild() || |
| 3466 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3467 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3468 | T->isSpelledAsLValue(), |
| 3469 | TL.getSigilLoc()); |
| 3470 | if (Result.isNull()) |
| 3471 | return QualType(); |
| 3472 | } |
| 3473 | |
| 3474 | // r-value references can be rebuilt as l-value references. |
| 3475 | ReferenceTypeLoc NewTL; |
| 3476 | if (isa<LValueReferenceType>(Result)) |
| 3477 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3478 | else |
| 3479 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3480 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3481 | |
| 3482 | return Result; |
| 3483 | } |
| 3484 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3485 | template<typename Derived> |
| 3486 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3487 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3488 | LValueReferenceTypeLoc TL) { |
| 3489 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3492 | template<typename Derived> |
| 3493 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3494 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3495 | RValueReferenceTypeLoc TL) { |
| 3496 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3499 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3501 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3502 | MemberPointerTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3503 | const MemberPointerType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3504 | |
| 3505 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3506 | if (PointeeType.isNull()) |
| 3507 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3508 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3509 | // TODO: preserve source information for this. |
| 3510 | QualType ClassType |
| 3511 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3512 | if (ClassType.isNull()) |
| 3513 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3515 | QualType Result = TL.getType(); |
| 3516 | if (getDerived().AlwaysRebuild() || |
| 3517 | PointeeType != T->getPointeeType() || |
| 3518 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3519 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 3520 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3521 | if (Result.isNull()) |
| 3522 | return QualType(); |
| 3523 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3524 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3525 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3526 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3527 | |
| 3528 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | template<typename Derived> |
| 3532 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3533 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3534 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3535 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3536 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3537 | if (ElementType.isNull()) |
| 3538 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3540 | QualType Result = TL.getType(); |
| 3541 | if (getDerived().AlwaysRebuild() || |
| 3542 | ElementType != T->getElementType()) { |
| 3543 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3544 | T->getSizeModifier(), |
| 3545 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3546 | T->getIndexTypeCVRQualifiers(), |
| 3547 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3548 | if (Result.isNull()) |
| 3549 | return QualType(); |
| 3550 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3551 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3552 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3553 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3554 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3556 | Expr *Size = TL.getSizeExpr(); |
| 3557 | if (Size) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3558 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3559 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3560 | } |
| 3561 | NewTL.setSizeExpr(Size); |
| 3562 | |
| 3563 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3566 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3567 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3568 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3569 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3570 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3571 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3572 | if (ElementType.isNull()) |
| 3573 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3575 | QualType Result = TL.getType(); |
| 3576 | if (getDerived().AlwaysRebuild() || |
| 3577 | ElementType != T->getElementType()) { |
| 3578 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3579 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3580 | T->getIndexTypeCVRQualifiers(), |
| 3581 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3582 | if (Result.isNull()) |
| 3583 | return QualType(); |
| 3584 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3585 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3586 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3587 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3588 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3589 | NewTL.setSizeExpr(0); |
| 3590 | |
| 3591 | return Result; |
| 3592 | } |
| 3593 | |
| 3594 | template<typename Derived> |
| 3595 | QualType |
| 3596 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3597 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3598 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3599 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3600 | if (ElementType.isNull()) |
| 3601 | return QualType(); |
| 3602 | |
| 3603 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3604 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3605 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3606 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3607 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3608 | if (SizeResult.isInvalid()) |
| 3609 | return QualType(); |
| 3610 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3611 | Expr *Size = SizeResult.take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3612 | |
| 3613 | QualType Result = TL.getType(); |
| 3614 | if (getDerived().AlwaysRebuild() || |
| 3615 | ElementType != T->getElementType() || |
| 3616 | Size != T->getSizeExpr()) { |
| 3617 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3618 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3619 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3620 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3621 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3622 | if (Result.isNull()) |
| 3623 | return QualType(); |
| 3624 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3625 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3626 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3627 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3628 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3629 | NewTL.setSizeExpr(Size); |
| 3630 | |
| 3631 | return Result; |
| 3632 | } |
| 3633 | |
| 3634 | template<typename Derived> |
| 3635 | QualType |
| 3636 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3637 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3638 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3639 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3640 | if (ElementType.isNull()) |
| 3641 | return QualType(); |
| 3642 | |
| 3643 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3644 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3645 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3646 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3647 | Expr *origSize = TL.getSizeExpr(); |
| 3648 | if (!origSize) origSize = T->getSizeExpr(); |
| 3649 | |
| 3650 | ExprResult sizeResult |
| 3651 | = getDerived().TransformExpr(origSize); |
| 3652 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3653 | return QualType(); |
| 3654 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3655 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3656 | |
| 3657 | QualType Result = TL.getType(); |
| 3658 | if (getDerived().AlwaysRebuild() || |
| 3659 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3660 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3661 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3662 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3663 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3664 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3665 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3666 | if (Result.isNull()) |
| 3667 | return QualType(); |
| 3668 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3669 | |
| 3670 | // We might have any sort of array type now, but fortunately they |
| 3671 | // all have the same location layout. |
| 3672 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3673 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3674 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3675 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3676 | |
| 3677 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3679 | |
| 3680 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3681 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3682 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3683 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3684 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3685 | |
| 3686 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3687 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3688 | if (ElementType.isNull()) |
| 3689 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3691 | // Vector sizes are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3692 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3693 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3694 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3695 | if (Size.isInvalid()) |
| 3696 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3697 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3698 | QualType Result = TL.getType(); |
| 3699 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3700 | ElementType != T->getElementType() || |
| 3701 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3702 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3703 | Size.take(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3704 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3705 | if (Result.isNull()) |
| 3706 | return QualType(); |
| 3707 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3708 | |
| 3709 | // Result might be dependent or not. |
| 3710 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3711 | DependentSizedExtVectorTypeLoc NewTL |
| 3712 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3713 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3714 | } else { |
| 3715 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3716 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3717 | } |
| 3718 | |
| 3719 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3720 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | |
| 3722 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3723 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3724 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3725 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3726 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3727 | if (ElementType.isNull()) |
| 3728 | return QualType(); |
| 3729 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3730 | QualType Result = TL.getType(); |
| 3731 | if (getDerived().AlwaysRebuild() || |
| 3732 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3733 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3734 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3735 | if (Result.isNull()) |
| 3736 | return QualType(); |
| 3737 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3738 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3739 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3740 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3741 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3742 | return Result; |
| 3743 | } |
| 3744 | |
| 3745 | template<typename Derived> |
| 3746 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3747 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3748 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3749 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3750 | if (ElementType.isNull()) |
| 3751 | return QualType(); |
| 3752 | |
| 3753 | QualType Result = TL.getType(); |
| 3754 | if (getDerived().AlwaysRebuild() || |
| 3755 | ElementType != T->getElementType()) { |
| 3756 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3757 | T->getNumElements(), |
| 3758 | /*FIXME*/ SourceLocation()); |
| 3759 | if (Result.isNull()) |
| 3760 | return QualType(); |
| 3761 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3762 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3763 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3764 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3765 | |
| 3766 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
| 3769 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3770 | ParmVarDecl * |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3771 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 3772 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3773 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3774 | TypeSourceInfo *NewDI = 0; |
| 3775 | |
| 3776 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3777 | // If we're substituting into a pack expansion type and we know the |
| 3778 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3779 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3780 | |
| 3781 | TypeLocBuilder TLB; |
| 3782 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3783 | TLB.reserve(NewTL.getFullDataSize()); |
| 3784 | |
| 3785 | QualType Result = getDerived().TransformType(TLB, |
| 3786 | OldExpansionTL.getPatternLoc()); |
| 3787 | if (Result.isNull()) |
| 3788 | return 0; |
| 3789 | |
| 3790 | Result = RebuildPackExpansionType(Result, |
| 3791 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3792 | OldExpansionTL.getEllipsisLoc(), |
| 3793 | NumExpansions); |
| 3794 | if (Result.isNull()) |
| 3795 | return 0; |
| 3796 | |
| 3797 | PackExpansionTypeLoc NewExpansionTL |
| 3798 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3799 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3800 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3801 | } else |
| 3802 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3803 | if (!NewDI) |
| 3804 | return 0; |
| 3805 | |
| 3806 | if (NewDI == OldDI) |
| 3807 | return OldParm; |
| 3808 | else |
| 3809 | return ParmVarDecl::Create(SemaRef.Context, |
| 3810 | OldParm->getDeclContext(), |
| 3811 | OldParm->getLocation(), |
| 3812 | OldParm->getIdentifier(), |
| 3813 | NewDI->getType(), |
| 3814 | NewDI, |
| 3815 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 3816 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3817 | /* DefArg */ NULL); |
| 3818 | } |
| 3819 | |
| 3820 | template<typename Derived> |
| 3821 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3822 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3823 | ParmVarDecl **Params, unsigned NumParams, |
| 3824 | const QualType *ParamTypes, |
| 3825 | llvm::SmallVectorImpl<QualType> &OutParamTypes, |
| 3826 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { |
| 3827 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3828 | if (ParmVarDecl *OldParm = Params[i]) { |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3829 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame^] | 3830 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3831 | if (OldParm->isParameterPack()) { |
| 3832 | // We have a function parameter pack that may need to be expanded. |
| 3833 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3834 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3835 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3836 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3837 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3838 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3839 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame^] | 3840 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 3841 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3842 | // Determine whether we should expand the parameter packs. |
| 3843 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3844 | bool RetainExpansion = false; |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3845 | llvm::Optional<unsigned> OrigNumExpansions |
| 3846 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3847 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3848 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3849 | Pattern.getSourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3850 | Unexpanded.data(), |
| 3851 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3852 | ShouldExpand, |
| 3853 | RetainExpansion, |
| 3854 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3855 | return true; |
| 3856 | } |
| 3857 | |
| 3858 | if (ShouldExpand) { |
| 3859 | // Expand the function parameter pack into multiple, separate |
| 3860 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3861 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3862 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3863 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3864 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3865 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3866 | OrigNumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3867 | if (!NewParm) |
| 3868 | return true; |
| 3869 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3870 | OutParamTypes.push_back(NewParm->getType()); |
| 3871 | if (PVars) |
| 3872 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3873 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3874 | |
| 3875 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3876 | // forgetting the partially-substituted parameter pack. |
| 3877 | if (RetainExpansion) { |
| 3878 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3879 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3880 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3881 | OrigNumExpansions); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3882 | if (!NewParm) |
| 3883 | return true; |
| 3884 | |
| 3885 | OutParamTypes.push_back(NewParm->getType()); |
| 3886 | if (PVars) |
| 3887 | PVars->push_back(NewParm); |
| 3888 | } |
| 3889 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3890 | // We're done with the pack expansion. |
| 3891 | continue; |
| 3892 | } |
| 3893 | |
| 3894 | // We'll substitute the parameter now without expanding the pack |
| 3895 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame^] | 3896 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3897 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3898 | NumExpansions); |
| 3899 | } else { |
| 3900 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3901 | llvm::Optional<unsigned>()); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3902 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame^] | 3903 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3904 | if (!NewParm) |
| 3905 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3906 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3907 | OutParamTypes.push_back(NewParm->getType()); |
| 3908 | if (PVars) |
| 3909 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3910 | continue; |
| 3911 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3912 | |
| 3913 | // Deal with the possibility that we don't have a parameter |
| 3914 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3915 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3916 | bool IsPackExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3917 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame^] | 3918 | QualType NewType; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3919 | if (const PackExpansionType *Expansion |
| 3920 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3921 | // We have a function parameter pack that may need to be expanded. |
| 3922 | QualType Pattern = Expansion->getPattern(); |
| 3923 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3924 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3925 | |
| 3926 | // Determine whether we should expand the parameter packs. |
| 3927 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3928 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3929 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3930 | Unexpanded.data(), |
| 3931 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3932 | ShouldExpand, |
| 3933 | RetainExpansion, |
| 3934 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3935 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | if (ShouldExpand) { |
| 3939 | // Expand the function parameter pack into multiple, separate |
| 3940 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3941 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3942 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3943 | QualType NewType = getDerived().TransformType(Pattern); |
| 3944 | if (NewType.isNull()) |
| 3945 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3946 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3947 | OutParamTypes.push_back(NewType); |
| 3948 | if (PVars) |
| 3949 | PVars->push_back(0); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | // We're done with the pack expansion. |
| 3953 | continue; |
| 3954 | } |
| 3955 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3956 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3957 | // forgetting the partially-substituted parameter pack. |
| 3958 | if (RetainExpansion) { |
| 3959 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3960 | QualType NewType = getDerived().TransformType(Pattern); |
| 3961 | if (NewType.isNull()) |
| 3962 | return true; |
| 3963 | |
| 3964 | OutParamTypes.push_back(NewType); |
| 3965 | if (PVars) |
| 3966 | PVars->push_back(0); |
| 3967 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3969 | // We'll substitute the parameter now without expanding the pack |
| 3970 | // expansion. |
| 3971 | OldType = Expansion->getPattern(); |
| 3972 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame^] | 3973 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3974 | NewType = getDerived().TransformType(OldType); |
| 3975 | } else { |
| 3976 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3979 | if (NewType.isNull()) |
| 3980 | return true; |
| 3981 | |
| 3982 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3983 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3984 | NumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3985 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3986 | OutParamTypes.push_back(NewType); |
| 3987 | if (PVars) |
| 3988 | PVars->push_back(0); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | return false; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3992 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3993 | |
| 3994 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3995 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3996 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3997 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3998 | // Transform the parameters and return type. |
| 3999 | // |
| 4000 | // We instantiate in source order, with the return type first followed by |
| 4001 | // the parameters, because users tend to expect this (even if they shouldn't |
| 4002 | // rely on it!). |
| 4003 | // |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4004 | // When the function has a trailing return type, we instantiate the |
| 4005 | // parameters before the return type, since the return type can then refer |
| 4006 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4007 | // |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4008 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4009 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4010 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4011 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4012 | QualType ResultType; |
| 4013 | |
| 4014 | if (TL.getTrailingReturn()) { |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4015 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4016 | TL.getParmArray(), |
| 4017 | TL.getNumArgs(), |
| 4018 | TL.getTypePtr()->arg_type_begin(), |
| 4019 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4020 | return QualType(); |
| 4021 | |
| 4022 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4023 | if (ResultType.isNull()) |
| 4024 | return QualType(); |
| 4025 | } |
| 4026 | else { |
| 4027 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4028 | if (ResultType.isNull()) |
| 4029 | return QualType(); |
| 4030 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4031 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4032 | TL.getParmArray(), |
| 4033 | TL.getNumArgs(), |
| 4034 | TL.getTypePtr()->arg_type_begin(), |
| 4035 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4036 | return QualType(); |
| 4037 | } |
| 4038 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4039 | QualType Result = TL.getType(); |
| 4040 | if (getDerived().AlwaysRebuild() || |
| 4041 | ResultType != T->getResultType() || |
Douglas Gregor | 9f627df | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4042 | T->getNumArgs() != ParamTypes.size() || |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4043 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 4044 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 4045 | ParamTypes.data(), |
| 4046 | ParamTypes.size(), |
| 4047 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4048 | T->getTypeQuals(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4049 | T->getRefQualifier(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4050 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4051 | if (Result.isNull()) |
| 4052 | return QualType(); |
| 4053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4055 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 4056 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4057 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4058 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4059 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4060 | NewTL.setArg(i, ParamDecls[i]); |
| 4061 | |
| 4062 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4063 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4064 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4065 | template<typename Derived> |
| 4066 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4067 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4068 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4069 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4070 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4071 | if (ResultType.isNull()) |
| 4072 | return QualType(); |
| 4073 | |
| 4074 | QualType Result = TL.getType(); |
| 4075 | if (getDerived().AlwaysRebuild() || |
| 4076 | ResultType != T->getResultType()) |
| 4077 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4078 | |
| 4079 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 4080 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4081 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4082 | NewTL.setTrailingReturn(false); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4083 | |
| 4084 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4085 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4086 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4087 | template<typename Derived> QualType |
| 4088 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4089 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4090 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4091 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4092 | if (!D) |
| 4093 | return QualType(); |
| 4094 | |
| 4095 | QualType Result = TL.getType(); |
| 4096 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4097 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4098 | if (Result.isNull()) |
| 4099 | return QualType(); |
| 4100 | } |
| 4101 | |
| 4102 | // We might get an arbitrary type spec type back. We should at |
| 4103 | // least always get a type spec type, though. |
| 4104 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4105 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4106 | |
| 4107 | return Result; |
| 4108 | } |
| 4109 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4110 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4111 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4112 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4113 | const TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4114 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4115 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4116 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4117 | if (!Typedef) |
| 4118 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4120 | QualType Result = TL.getType(); |
| 4121 | if (getDerived().AlwaysRebuild() || |
| 4122 | Typedef != T->getDecl()) { |
| 4123 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4124 | if (Result.isNull()) |
| 4125 | return QualType(); |
| 4126 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4127 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4128 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4129 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4130 | |
| 4131 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4132 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4134 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4135 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4136 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4137 | // typeof expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4138 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4139 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4140 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4141 | if (E.isInvalid()) |
| 4142 | return QualType(); |
| 4143 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4144 | QualType Result = TL.getType(); |
| 4145 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4146 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4147 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4148 | if (Result.isNull()) |
| 4149 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4150 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4151 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4153 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4154 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4155 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4156 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4157 | |
| 4158 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
| 4161 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4162 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4163 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4164 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4165 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4166 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4167 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4169 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4170 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4171 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4172 | if (Result.isNull()) |
| 4173 | return QualType(); |
| 4174 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4176 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4177 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4178 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4179 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4180 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4181 | |
| 4182 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | |
| 4185 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4186 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4187 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4188 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4189 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4190 | // decltype expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4191 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4192 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4193 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4194 | if (E.isInvalid()) |
| 4195 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4197 | QualType Result = TL.getType(); |
| 4198 | if (getDerived().AlwaysRebuild() || |
| 4199 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4200 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4201 | if (Result.isNull()) |
| 4202 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4203 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4204 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4206 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4207 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4208 | |
| 4209 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4213 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4214 | AutoTypeLoc TL) { |
| 4215 | const AutoType *T = TL.getTypePtr(); |
| 4216 | QualType OldDeduced = T->getDeducedType(); |
| 4217 | QualType NewDeduced; |
| 4218 | if (!OldDeduced.isNull()) { |
| 4219 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4220 | if (NewDeduced.isNull()) |
| 4221 | return QualType(); |
| 4222 | } |
| 4223 | |
| 4224 | QualType Result = TL.getType(); |
| 4225 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4226 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4227 | if (Result.isNull()) |
| 4228 | return QualType(); |
| 4229 | } |
| 4230 | |
| 4231 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4232 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4233 | |
| 4234 | return Result; |
| 4235 | } |
| 4236 | |
| 4237 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4238 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4239 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4240 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4241 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4242 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4243 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4244 | if (!Record) |
| 4245 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4247 | QualType Result = TL.getType(); |
| 4248 | if (getDerived().AlwaysRebuild() || |
| 4249 | Record != T->getDecl()) { |
| 4250 | Result = getDerived().RebuildRecordType(Record); |
| 4251 | if (Result.isNull()) |
| 4252 | return QualType(); |
| 4253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4255 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4256 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4257 | |
| 4258 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4260 | |
| 4261 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4262 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4263 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4264 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4265 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4266 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4267 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4268 | if (!Enum) |
| 4269 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4271 | QualType Result = TL.getType(); |
| 4272 | if (getDerived().AlwaysRebuild() || |
| 4273 | Enum != T->getDecl()) { |
| 4274 | Result = getDerived().RebuildEnumType(Enum); |
| 4275 | if (Result.isNull()) |
| 4276 | return QualType(); |
| 4277 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4278 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4279 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4280 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4281 | |
| 4282 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4283 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4284 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4285 | template<typename Derived> |
| 4286 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4287 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4288 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4289 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4290 | TL.getTypePtr()->getDecl()); |
| 4291 | if (!D) return QualType(); |
| 4292 | |
| 4293 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4294 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4295 | return T; |
| 4296 | } |
| 4297 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4298 | template<typename Derived> |
| 4299 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4300 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4301 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4302 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4305 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4306 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4307 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4308 | SubstTemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4309 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4313 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4314 | TypeLocBuilder &TLB, |
| 4315 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4316 | return TransformTypeSpecType(TLB, TL); |
| 4317 | } |
| 4318 | |
| 4319 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4320 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4321 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4322 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4323 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4324 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4325 | TemplateName Template |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4326 | = getDerived().TransformTemplateName(T->getTemplateName()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4327 | if (Template.isNull()) |
| 4328 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4330 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4331 | } |
| 4332 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4333 | namespace { |
| 4334 | /// \brief Simple iterator that traverses the template arguments in a |
| 4335 | /// container that provides a \c getArgLoc() member function. |
| 4336 | /// |
| 4337 | /// This iterator is intended to be used with the iterator form of |
| 4338 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4339 | template<typename ArgLocContainer> |
| 4340 | class TemplateArgumentLocContainerIterator { |
| 4341 | ArgLocContainer *Container; |
| 4342 | unsigned Index; |
| 4343 | |
| 4344 | public: |
| 4345 | typedef TemplateArgumentLoc value_type; |
| 4346 | typedef TemplateArgumentLoc reference; |
| 4347 | typedef int difference_type; |
| 4348 | typedef std::input_iterator_tag iterator_category; |
| 4349 | |
| 4350 | class pointer { |
| 4351 | TemplateArgumentLoc Arg; |
| 4352 | |
| 4353 | public: |
| 4354 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4355 | |
| 4356 | const TemplateArgumentLoc *operator->() const { |
| 4357 | return &Arg; |
| 4358 | } |
| 4359 | }; |
| 4360 | |
| 4361 | |
| 4362 | TemplateArgumentLocContainerIterator() {} |
| 4363 | |
| 4364 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4365 | unsigned Index) |
| 4366 | : Container(&Container), Index(Index) { } |
| 4367 | |
| 4368 | TemplateArgumentLocContainerIterator &operator++() { |
| 4369 | ++Index; |
| 4370 | return *this; |
| 4371 | } |
| 4372 | |
| 4373 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4374 | TemplateArgumentLocContainerIterator Old(*this); |
| 4375 | ++(*this); |
| 4376 | return Old; |
| 4377 | } |
| 4378 | |
| 4379 | TemplateArgumentLoc operator*() const { |
| 4380 | return Container->getArgLoc(Index); |
| 4381 | } |
| 4382 | |
| 4383 | pointer operator->() const { |
| 4384 | return pointer(Container->getArgLoc(Index)); |
| 4385 | } |
| 4386 | |
| 4387 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4388 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4389 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4390 | } |
| 4391 | |
| 4392 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4393 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4394 | return !(X == Y); |
| 4395 | } |
| 4396 | }; |
| 4397 | } |
| 4398 | |
| 4399 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4400 | template <typename Derived> |
| 4401 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4402 | TypeLocBuilder &TLB, |
| 4403 | TemplateSpecializationTypeLoc TL, |
| 4404 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4405 | TemplateArgumentListInfo NewTemplateArgs; |
| 4406 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4407 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4408 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4409 | ArgIterator; |
| 4410 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4411 | ArgIterator(TL, TL.getNumArgs()), |
| 4412 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4413 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4415 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4416 | |
| 4417 | QualType Result = |
| 4418 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4419 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4420 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4421 | |
| 4422 | if (!Result.isNull()) { |
| 4423 | TemplateSpecializationTypeLoc NewTL |
| 4424 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4425 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4426 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4427 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4428 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4429 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4430 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4431 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4432 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4433 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4435 | template <typename Derived> |
| 4436 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4437 | TypeLocBuilder &TLB, |
| 4438 | DependentTemplateSpecializationTypeLoc TL, |
| 4439 | TemplateName Template) { |
| 4440 | TemplateArgumentListInfo NewTemplateArgs; |
| 4441 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4442 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4443 | typedef TemplateArgumentLocContainerIterator< |
| 4444 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4445 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4446 | ArgIterator(TL, TL.getNumArgs()), |
| 4447 | NewTemplateArgs)) |
| 4448 | return QualType(); |
| 4449 | |
| 4450 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4451 | |
| 4452 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4453 | QualType Result |
| 4454 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4455 | TL.getTypePtr()->getKeyword(), |
| 4456 | DTN->getQualifier(), |
| 4457 | DTN->getIdentifier(), |
| 4458 | NewTemplateArgs); |
| 4459 | |
| 4460 | DependentTemplateSpecializationTypeLoc NewTL |
| 4461 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4462 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4463 | |
| 4464 | // FIXME: Poor nested-name-specifier source-location information. |
| 4465 | CXXScopeSpec SS; |
| 4466 | SS.MakeTrivial(SemaRef.Context, |
| 4467 | DTN->getQualifier(), TL.getQualifierLoc().getSourceRange()); |
| 4468 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4469 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4470 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4471 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4472 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4473 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4474 | return Result; |
| 4475 | } |
| 4476 | |
| 4477 | QualType Result |
| 4478 | = getDerived().RebuildTemplateSpecializationType(Template, |
| 4479 | TL.getNameLoc(), |
| 4480 | NewTemplateArgs); |
| 4481 | |
| 4482 | if (!Result.isNull()) { |
| 4483 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4484 | TemplateSpecializationTypeLoc NewTL |
| 4485 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4486 | NewTL.setTemplateNameLoc(TL.getNameLoc()); |
| 4487 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4488 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4489 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4490 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4491 | } |
| 4492 | |
| 4493 | return Result; |
| 4494 | } |
| 4495 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4497 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4498 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4499 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4500 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4502 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4503 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4504 | if (TL.getQualifierLoc()) { |
| 4505 | QualifierLoc |
| 4506 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4507 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4508 | return QualType(); |
| 4509 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4511 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4512 | if (NamedT.isNull()) |
| 4513 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4514 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4515 | QualType Result = TL.getType(); |
| 4516 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4517 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4518 | NamedT != T->getNamedType()) { |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4519 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4520 | T->getKeyword(), |
| 4521 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4522 | if (Result.isNull()) |
| 4523 | return QualType(); |
| 4524 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4525 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4526 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4527 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4528 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4529 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4531 | |
| 4532 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4533 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4534 | TypeLocBuilder &TLB, |
| 4535 | AttributedTypeLoc TL) { |
| 4536 | const AttributedType *oldType = TL.getTypePtr(); |
| 4537 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4538 | if (modifiedType.isNull()) |
| 4539 | return QualType(); |
| 4540 | |
| 4541 | QualType result = TL.getType(); |
| 4542 | |
| 4543 | // FIXME: dependent operand expressions? |
| 4544 | if (getDerived().AlwaysRebuild() || |
| 4545 | modifiedType != oldType->getModifiedType()) { |
| 4546 | // TODO: this is really lame; we should really be rebuilding the |
| 4547 | // equivalent type from first principles. |
| 4548 | QualType equivalentType |
| 4549 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4550 | if (equivalentType.isNull()) |
| 4551 | return QualType(); |
| 4552 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4553 | modifiedType, |
| 4554 | equivalentType); |
| 4555 | } |
| 4556 | |
| 4557 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4558 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4559 | if (TL.hasAttrOperand()) |
| 4560 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4561 | if (TL.hasAttrExprOperand()) |
| 4562 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4563 | else if (TL.hasAttrEnumOperand()) |
| 4564 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4565 | |
| 4566 | return result; |
| 4567 | } |
| 4568 | |
| 4569 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4570 | QualType |
| 4571 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4572 | ParenTypeLoc TL) { |
| 4573 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4574 | if (Inner.isNull()) |
| 4575 | return QualType(); |
| 4576 | |
| 4577 | QualType Result = TL.getType(); |
| 4578 | if (getDerived().AlwaysRebuild() || |
| 4579 | Inner != TL.getInnerLoc().getType()) { |
| 4580 | Result = getDerived().RebuildParenType(Inner); |
| 4581 | if (Result.isNull()) |
| 4582 | return QualType(); |
| 4583 | } |
| 4584 | |
| 4585 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4586 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4587 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4588 | return Result; |
| 4589 | } |
| 4590 | |
| 4591 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4592 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4593 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4594 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4596 | NestedNameSpecifierLoc QualifierLoc |
| 4597 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4598 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4599 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4600 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4601 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4602 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4603 | TL.getKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4604 | QualifierLoc, |
| 4605 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4606 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4607 | if (Result.isNull()) |
| 4608 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4609 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4610 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4611 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4612 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4613 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4614 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4615 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4616 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4617 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4618 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4619 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4620 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4621 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4622 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4623 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4624 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4625 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4626 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4627 | QualType TreeTransform<Derived>:: |
| 4628 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4629 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4630 | NestedNameSpecifierLoc QualifierLoc; |
| 4631 | if (TL.getQualifierLoc()) { |
| 4632 | QualifierLoc |
| 4633 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4634 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4635 | return QualType(); |
| 4636 | } |
| 4637 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4638 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4639 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | template<typename Derived> |
| 4643 | QualType TreeTransform<Derived>:: |
| 4644 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4645 | DependentTemplateSpecializationTypeLoc TL, |
| 4646 | NestedNameSpecifier *NNS) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4647 | // FIXME: This routine needs to go away. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4648 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4649 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4650 | TemplateArgumentListInfo NewTemplateArgs; |
| 4651 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4652 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4653 | |
| 4654 | // FIXME: Nested-name-specifier source location info! |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4655 | typedef TemplateArgumentLocContainerIterator< |
| 4656 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4657 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4658 | ArgIterator(TL, TL.getNumArgs()), |
| 4659 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4660 | return QualType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4661 | |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4662 | QualType Result |
| 4663 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4664 | NNS, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4665 | TL.getQualifierLoc().getSourceRange(), |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4666 | T->getIdentifier(), |
| 4667 | TL.getNameLoc(), |
| 4668 | NewTemplateArgs); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4669 | if (Result.isNull()) |
| 4670 | return QualType(); |
| 4671 | |
| 4672 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4673 | QualType NamedT = ElabT->getNamedType(); |
| 4674 | |
| 4675 | // Copy information relevant to the template specialization. |
| 4676 | TemplateSpecializationTypeLoc NamedTL |
| 4677 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4678 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4679 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4680 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4681 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4682 | |
| 4683 | // Copy information relevant to the elaborated type. |
| 4684 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4685 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4686 | |
| 4687 | // FIXME: DependentTemplateSpecializationType needs better source-location |
| 4688 | // info. |
| 4689 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4690 | Builder.MakeTrivial(SemaRef.Context, |
| 4691 | NNS, TL.getQualifierLoc().getSourceRange()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4692 | NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4693 | } else { |
Douglas Gregor | ffa2039 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 4694 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4695 | TLB.pushFullCopy(NewTL); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4696 | } |
| 4697 | return Result; |
| 4698 | } |
| 4699 | |
| 4700 | template<typename Derived> |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4701 | QualType TreeTransform<Derived>:: |
| 4702 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4703 | DependentTemplateSpecializationTypeLoc TL, |
| 4704 | NestedNameSpecifierLoc QualifierLoc) { |
| 4705 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 4706 | |
| 4707 | TemplateArgumentListInfo NewTemplateArgs; |
| 4708 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4709 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4710 | |
| 4711 | typedef TemplateArgumentLocContainerIterator< |
| 4712 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4713 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4714 | ArgIterator(TL, TL.getNumArgs()), |
| 4715 | NewTemplateArgs)) |
| 4716 | return QualType(); |
| 4717 | |
| 4718 | QualType Result |
| 4719 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4720 | QualifierLoc, |
| 4721 | T->getIdentifier(), |
| 4722 | TL.getNameLoc(), |
| 4723 | NewTemplateArgs); |
| 4724 | if (Result.isNull()) |
| 4725 | return QualType(); |
| 4726 | |
| 4727 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4728 | QualType NamedT = ElabT->getNamedType(); |
| 4729 | |
| 4730 | // Copy information relevant to the template specialization. |
| 4731 | TemplateSpecializationTypeLoc NamedTL |
| 4732 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4733 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4734 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4735 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4736 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4737 | |
| 4738 | // Copy information relevant to the elaborated type. |
| 4739 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4740 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4741 | NewTL.setQualifierLoc(QualifierLoc); |
| 4742 | } else { |
| 4743 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4744 | TLB.pushFullCopy(NewTL); |
| 4745 | } |
| 4746 | return Result; |
| 4747 | } |
| 4748 | |
| 4749 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4750 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4751 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4752 | QualType Pattern |
| 4753 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4754 | if (Pattern.isNull()) |
| 4755 | return QualType(); |
| 4756 | |
| 4757 | QualType Result = TL.getType(); |
| 4758 | if (getDerived().AlwaysRebuild() || |
| 4759 | Pattern != TL.getPatternLoc().getType()) { |
| 4760 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4761 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4762 | TL.getEllipsisLoc(), |
| 4763 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4764 | if (Result.isNull()) |
| 4765 | return QualType(); |
| 4766 | } |
| 4767 | |
| 4768 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4769 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4770 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4774 | QualType |
| 4775 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4776 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4777 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4778 | TLB.pushFullCopy(TL); |
| 4779 | return TL.getType(); |
| 4780 | } |
| 4781 | |
| 4782 | template<typename Derived> |
| 4783 | QualType |
| 4784 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4785 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4786 | // ObjCObjectType is never dependent. |
| 4787 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4788 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4789 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | |
| 4791 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4792 | QualType |
| 4793 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4794 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4795 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4796 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4797 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4800 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4801 | // Statement transformation |
| 4802 | //===----------------------------------------------------------------------===// |
| 4803 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4804 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4805 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4806 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4810 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4811 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4812 | return getDerived().TransformCompoundStmt(S, false); |
| 4813 | } |
| 4814 | |
| 4815 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4816 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4818 | bool IsStmtExpr) { |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4819 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4820 | bool SubStmtChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4821 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4822 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4823 | B != BEnd; ++B) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4824 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4825 | if (Result.isInvalid()) { |
| 4826 | // Immediately fail if this was a DeclStmt, since it's very |
| 4827 | // likely that this will cause problems for future statements. |
| 4828 | if (isa<DeclStmt>(*B)) |
| 4829 | return StmtError(); |
| 4830 | |
| 4831 | // Otherwise, just keep processing substatements and fail later. |
| 4832 | SubStmtInvalid = true; |
| 4833 | continue; |
| 4834 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4835 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4836 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4837 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4839 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4840 | if (SubStmtInvalid) |
| 4841 | return StmtError(); |
| 4842 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4843 | if (!getDerived().AlwaysRebuild() && |
| 4844 | !SubStmtChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4845 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4846 | |
| 4847 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4848 | move_arg(Statements), |
| 4849 | S->getRBracLoc(), |
| 4850 | IsStmtExpr); |
| 4851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4852 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4853 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4854 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4855 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4856 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4857 | { |
| 4858 | // The case value expressions are not potentially evaluated. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4859 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4861 | // Transform the left-hand case value. |
| 4862 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4863 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4864 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4866 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4867 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4868 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4869 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4871 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4872 | // Build the case statement. |
| 4873 | // Case statements are always rebuilt so that they will attached to their |
| 4874 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4875 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4876 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4877 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4878 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4879 | S->getColonLoc()); |
| 4880 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4881 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4882 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4883 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4884 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4885 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4886 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4887 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4888 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4889 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4890 | } |
| 4891 | |
| 4892 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4893 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4894 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4895 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4896 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4897 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4898 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4900 | // Default statements are always rebuilt |
| 4901 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4902 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4903 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4905 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4906 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4907 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4908 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4909 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4910 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4911 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4912 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 4913 | S->getDecl()); |
| 4914 | if (!LD) |
| 4915 | return StmtError(); |
| 4916 | |
| 4917 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4918 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 4919 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4920 | cast<LabelDecl>(LD), SourceLocation(), |
| 4921 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4922 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4923 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4924 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4925 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4926 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4927 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4928 | ExprResult Cond; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4929 | VarDecl *ConditionVar = 0; |
| 4930 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4931 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4932 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4933 | getDerived().TransformDefinition( |
| 4934 | S->getConditionVariable()->getLocation(), |
| 4935 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4936 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4937 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4938 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4939 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4941 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4942 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4943 | |
| 4944 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4945 | if (S->getCond()) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4946 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 4947 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4948 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4949 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4950 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4951 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4952 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4953 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4954 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4955 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4956 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4957 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4958 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4959 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4960 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4961 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4962 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4963 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4964 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4965 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4966 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4967 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4969 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4970 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4971 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4972 | Then.get() == S->getThen() && |
| 4973 | Else.get() == S->getElse()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4974 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4975 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4976 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 4977 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4978 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4982 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4983 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4984 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4985 | ExprResult Cond; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4986 | VarDecl *ConditionVar = 0; |
| 4987 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4988 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4989 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4990 | getDerived().TransformDefinition( |
| 4991 | S->getConditionVariable()->getLocation(), |
| 4992 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4993 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4994 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4995 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4996 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4997 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4998 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4999 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5000 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5001 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5002 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5003 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5004 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5005 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5006 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5007 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5008 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5009 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5010 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5011 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5012 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5013 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5014 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5015 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5016 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5017 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5018 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5019 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5020 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5022 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5023 | ExprResult Cond; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5024 | VarDecl *ConditionVar = 0; |
| 5025 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5026 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5027 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5028 | getDerived().TransformDefinition( |
| 5029 | S->getConditionVariable()->getLocation(), |
| 5030 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5031 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5032 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5033 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5034 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5035 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5036 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5037 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5038 | |
| 5039 | if (S->getCond()) { |
| 5040 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5041 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 5042 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5043 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5044 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5045 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5046 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5048 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5049 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5050 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5051 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5052 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5053 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5054 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5055 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5056 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5057 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5058 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5059 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5060 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5061 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5062 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5063 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5064 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5065 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5067 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5068 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5069 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5070 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5071 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5072 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5073 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5074 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5075 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5076 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5077 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5078 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5079 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5080 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5081 | if (!getDerived().AlwaysRebuild() && |
| 5082 | Cond.get() == S->getCond() && |
| 5083 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5084 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5085 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5086 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5087 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5088 | S->getRParenLoc()); |
| 5089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5091 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5092 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5093 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5094 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5095 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5096 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5097 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5099 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5100 | ExprResult Cond; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5101 | VarDecl *ConditionVar = 0; |
| 5102 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5103 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5104 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5105 | getDerived().TransformDefinition( |
| 5106 | S->getConditionVariable()->getLocation(), |
| 5107 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5108 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5109 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5110 | } else { |
| 5111 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5112 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5113 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5114 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5115 | |
| 5116 | if (S->getCond()) { |
| 5117 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5118 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 5119 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5120 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5121 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5122 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5123 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5124 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5126 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5127 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5128 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5129 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5131 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5132 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5133 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5134 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5135 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5136 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5137 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5138 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5139 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5140 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5141 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5142 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5143 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5144 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5145 | if (!getDerived().AlwaysRebuild() && |
| 5146 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5147 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5148 | Inc.get() == S->getInc() && |
| 5149 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5150 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5151 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5152 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5153 | Init.get(), FullCond, ConditionVar, |
| 5154 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5158 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5159 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5160 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5161 | S->getLabel()); |
| 5162 | if (!LD) |
| 5163 | return StmtError(); |
| 5164 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5165 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5166 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5167 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
| 5170 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5171 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5173 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5174 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5175 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5177 | if (!getDerived().AlwaysRebuild() && |
| 5178 | Target.get() == S->getTarget()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5179 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5180 | |
| 5181 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5182 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5186 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5188 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5189 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5191 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5192 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5194 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5196 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5197 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5198 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5200 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5201 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5202 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5203 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5204 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5205 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5206 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5209 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5210 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5211 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5212 | bool DeclChanged = false; |
| 5213 | llvm::SmallVector<Decl *, 4> Decls; |
| 5214 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5215 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5216 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5217 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5218 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5219 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5221 | if (Transformed != *D) |
| 5222 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5224 | Decls.push_back(Transformed); |
| 5225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5226 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5227 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5228 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5229 | |
| 5230 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5231 | S->getStartLoc(), S->getEndLoc()); |
| 5232 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5233 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5234 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5235 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5236 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5237 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5238 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5239 | ASTOwningVector<Expr*> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5240 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5241 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5242 | ExprResult AsmString; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5243 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5244 | |
| 5245 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5246 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5247 | // Go through the outputs. |
| 5248 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5249 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5250 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5251 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5252 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5253 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5254 | // Transform the output expr. |
| 5255 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5256 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5257 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5258 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5259 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5260 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5261 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5262 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5263 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5264 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5265 | // Go through the inputs. |
| 5266 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5267 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5268 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5269 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5270 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5271 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5272 | // Transform the input expr. |
| 5273 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5274 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5275 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5276 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5277 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5278 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5279 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5280 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5281 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5282 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5283 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5284 | return SemaRef.Owned(S); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5285 | |
| 5286 | // Go through the clobbers. |
| 5287 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5288 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5289 | |
| 5290 | // No need to transform the asm string literal. |
| 5291 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5292 | |
| 5293 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5294 | S->isSimple(), |
| 5295 | S->isVolatile(), |
| 5296 | S->getNumOutputs(), |
| 5297 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5298 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5299 | move_arg(Constraints), |
| 5300 | move_arg(Exprs), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5301 | AsmString.get(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5302 | move_arg(Clobbers), |
| 5303 | S->getRParenLoc(), |
| 5304 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | |
| 5308 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5309 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5311 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5312 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5313 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5314 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5315 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5316 | // Transform the @catch statements (if present). |
| 5317 | bool AnyCatchChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5318 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5319 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5320 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5321 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5322 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5323 | if (Catch.get() != S->getCatchStmt(I)) |
| 5324 | AnyCatchChanged = true; |
| 5325 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5326 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5327 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5328 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5329 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5330 | if (S->getFinallyStmt()) { |
| 5331 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5332 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5333 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | // If nothing changed, just retain this statement. |
| 5337 | if (!getDerived().AlwaysRebuild() && |
| 5338 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5339 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5340 | Finally.get() == S->getFinallyStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5341 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5342 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5343 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5344 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5345 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5346 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5347 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5348 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5349 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5351 | // Transform the @catch parameter, if there is one. |
| 5352 | VarDecl *Var = 0; |
| 5353 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5354 | TypeSourceInfo *TSInfo = 0; |
| 5355 | if (FromVar->getTypeSourceInfo()) { |
| 5356 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5357 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5358 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5359 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5361 | QualType T; |
| 5362 | if (TSInfo) |
| 5363 | T = TSInfo->getType(); |
| 5364 | else { |
| 5365 | T = getDerived().TransformType(FromVar->getType()); |
| 5366 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5367 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5368 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5369 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5370 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5371 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5372 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5373 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5374 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5375 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5376 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5377 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5378 | |
| 5379 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5380 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5381 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5383 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5384 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5385 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5386 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5387 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5388 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5389 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5390 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5391 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5392 | // If nothing changed, just retain this statement. |
| 5393 | if (!getDerived().AlwaysRebuild() && |
| 5394 | Body.get() == S->getFinallyBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5395 | return SemaRef.Owned(S); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5396 | |
| 5397 | // Build a new statement. |
| 5398 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5399 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5400 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5402 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5403 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5404 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5405 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5406 | if (S->getThrowExpr()) { |
| 5407 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5408 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5409 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5410 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5411 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5412 | if (!getDerived().AlwaysRebuild() && |
| 5413 | Operand.get() == S->getThrowExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5414 | return getSema().Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5415 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5416 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5417 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5419 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5420 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5421 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5422 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5423 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5424 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5425 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5426 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5427 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5428 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5429 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5430 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5431 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5432 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5433 | // If nothing change, just retain the current statement. |
| 5434 | if (!getDerived().AlwaysRebuild() && |
| 5435 | Object.get() == S->getSynchExpr() && |
| 5436 | Body.get() == S->getSynchBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5437 | return SemaRef.Owned(S); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5438 | |
| 5439 | // Build a new statement. |
| 5440 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5441 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5445 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5446 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5447 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5448 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5449 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5450 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5451 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5452 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5453 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5454 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5455 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5456 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5457 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5458 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5459 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5460 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5461 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5462 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5463 | // If nothing changed, just retain this statement. |
| 5464 | if (!getDerived().AlwaysRebuild() && |
| 5465 | Element.get() == S->getElement() && |
| 5466 | Collection.get() == S->getCollection() && |
| 5467 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5468 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5469 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5470 | // Build a new statement. |
| 5471 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5472 | /*FIXME:*/S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5473 | Element.get(), |
| 5474 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5475 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5476 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5477 | } |
| 5478 | |
| 5479 | |
| 5480 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5481 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5482 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5483 | // Transform the exception declaration, if any. |
| 5484 | VarDecl *Var = 0; |
| 5485 | if (S->getExceptionDecl()) { |
| 5486 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5487 | TypeSourceInfo *T = getDerived().TransformType( |
| 5488 | ExceptionDecl->getTypeSourceInfo()); |
| 5489 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5490 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5491 | |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5492 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5493 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5494 | ExceptionDecl->getLocation()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5495 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5496 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5498 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5499 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5500 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5501 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5502 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5503 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5504 | if (!getDerived().AlwaysRebuild() && |
| 5505 | !Var && |
| 5506 | Handler.get() == S->getHandlerBlock()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5507 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5508 | |
| 5509 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5510 | Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5511 | Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5512 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5513 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5514 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5515 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5516 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5517 | // Transform the try block itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5518 | StmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5519 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5520 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5521 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5522 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5523 | // Transform the handlers. |
| 5524 | bool HandlerChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5525 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5526 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5527 | StmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5528 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5529 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5530 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5531 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5532 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5533 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5535 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5536 | if (!getDerived().AlwaysRebuild() && |
| 5537 | TryBlock.get() == S->getTryBlock() && |
| 5538 | !HandlerChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5539 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5540 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5541 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5544 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5545 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5546 | // Expression transformation |
| 5547 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5549 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5550 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5551 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5552 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
| 5554 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5555 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5556 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5557 | NestedNameSpecifierLoc QualifierLoc; |
| 5558 | if (E->getQualifierLoc()) { |
| 5559 | QualifierLoc |
| 5560 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5561 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5562 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5563 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5564 | |
| 5565 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5566 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5567 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5569 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5570 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5571 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5572 | if (NameInfo.getName()) { |
| 5573 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5574 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5575 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5576 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5577 | |
| 5578 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5579 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5580 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5581 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5582 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5583 | |
| 5584 | // Mark it referenced in the new context regardless. |
| 5585 | // FIXME: this is a bit instantiation-specific. |
| 5586 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5587 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5588 | return SemaRef.Owned(E); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5589 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5590 | |
| 5591 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5592 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5593 | TemplateArgs = &TransArgs; |
| 5594 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5595 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5596 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5597 | E->getNumTemplateArgs(), |
| 5598 | TransArgs)) |
| 5599 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5600 | } |
| 5601 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5602 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 5603 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5604 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5605 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5607 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5608 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5609 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5612 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5613 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5614 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5615 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5617 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5618 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5619 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5620 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5621 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5623 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5624 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5625 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5626 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5627 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5628 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5629 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5630 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5631 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5632 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5633 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | } |
| 5635 | |
| 5636 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5637 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5638 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5639 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5640 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5641 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5642 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5643 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5644 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5645 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5646 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5647 | E->getRParen()); |
| 5648 | } |
| 5649 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5650 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5651 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5652 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5653 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5655 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5657 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5658 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5660 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5661 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5662 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5665 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5666 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5667 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5668 | // Transform the type. |
| 5669 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5670 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5671 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5672 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5673 | // Transform all of the components into components similar to what the |
| 5674 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5675 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5676 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5677 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5678 | // template code that we don't care. |
| 5679 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5680 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5681 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 5682 | llvm::SmallVector<Component, 4> Components; |
| 5683 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5684 | const Node &ON = E->getComponent(I); |
| 5685 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5686 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5687 | Comp.LocStart = ON.getRange().getBegin(); |
| 5688 | Comp.LocEnd = ON.getRange().getEnd(); |
| 5689 | switch (ON.getKind()) { |
| 5690 | case Node::Array: { |
| 5691 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5692 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5693 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5694 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5695 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5696 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5697 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5698 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5699 | break; |
| 5700 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5701 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5702 | case Node::Field: |
| 5703 | case Node::Identifier: |
| 5704 | Comp.isBrackets = false; |
| 5705 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5706 | if (!Comp.U.IdentInfo) |
| 5707 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5708 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5709 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5710 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5711 | case Node::Base: |
| 5712 | // Will be recomputed during the rebuild. |
| 5713 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5714 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5715 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5716 | Components.push_back(Comp); |
| 5717 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5718 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5719 | // If nothing changed, retain the existing expression. |
| 5720 | if (!getDerived().AlwaysRebuild() && |
| 5721 | Type == E->getTypeSourceInfo() && |
| 5722 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5723 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5724 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5725 | // Build a new offsetof expression. |
| 5726 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5727 | Components.data(), Components.size(), |
| 5728 | E->getRParenLoc()); |
| 5729 | } |
| 5730 | |
| 5731 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5732 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5733 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5734 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5735 | "opaque value expression requires transformation"); |
| 5736 | return SemaRef.Owned(E); |
| 5737 | } |
| 5738 | |
| 5739 | template<typename Derived> |
| 5740 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5741 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5742 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5743 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5744 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5745 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5746 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5747 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5748 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5749 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5750 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5751 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5752 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5753 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5754 | E->getSourceRange()); |
| 5755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5756 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5757 | ExprResult SubExpr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5758 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5759 | // C++0x [expr.sizeof]p1: |
| 5760 | // The operand is either an expression, which is an unevaluated operand |
| 5761 | // [...] |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5762 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5764 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5765 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5766 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5768 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5769 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5771 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5772 | return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5773 | E->isSizeOf(), |
| 5774 | E->getSourceRange()); |
| 5775 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5776 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5777 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5778 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5779 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5780 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5781 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5782 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5783 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5784 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5785 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5786 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5787 | |
| 5788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5789 | if (!getDerived().AlwaysRebuild() && |
| 5790 | LHS.get() == E->getLHS() && |
| 5791 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5792 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5793 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5794 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5795 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5796 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5797 | E->getRBracketLoc()); |
| 5798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5799 | |
| 5800 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5801 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5802 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5803 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5804 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5805 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5806 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5807 | |
| 5808 | // Transform arguments. |
| 5809 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5810 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5811 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5812 | &ArgChanged)) |
| 5813 | return ExprError(); |
| 5814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5815 | if (!getDerived().AlwaysRebuild() && |
| 5816 | Callee.get() == E->getCallee() && |
| 5817 | !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5818 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5819 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5820 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5821 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5822 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5823 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5824 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5825 | E->getRParenLoc()); |
| 5826 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5827 | |
| 5828 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5829 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5830 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5831 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5832 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5833 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5834 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5835 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5836 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5837 | QualifierLoc |
| 5838 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5839 | |
| 5840 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5841 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5843 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 5844 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5845 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 5846 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5847 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5848 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5849 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5850 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 5851 | if (FoundDecl == E->getMemberDecl()) { |
| 5852 | FoundDecl = Member; |
| 5853 | } else { |
| 5854 | FoundDecl = cast_or_null<NamedDecl>( |
| 5855 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 5856 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5857 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5858 | } |
| 5859 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5860 | if (!getDerived().AlwaysRebuild() && |
| 5861 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5862 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5863 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5864 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5865 | !E->hasExplicitTemplateArgs()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5866 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5867 | // Mark it referenced in the new context regardless. |
| 5868 | // FIXME: this is a bit instantiation-specific. |
| 5869 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5870 | return SemaRef.Owned(E); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5871 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5872 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5873 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5874 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5875 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5876 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5877 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5878 | E->getNumTemplateArgs(), |
| 5879 | TransArgs)) |
| 5880 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5881 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5882 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5883 | // FIXME: Bogus source location for the operator |
| 5884 | SourceLocation FakeOperatorLoc |
| 5885 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 5886 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5887 | // FIXME: to do this check properly, we will need to preserve the |
| 5888 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5889 | // base (and therefore couldn't do the check) and a |
| 5890 | // nested-name-qualifier (and therefore could do the lookup). |
| 5891 | NamedDecl *FirstQualifierInScope = 0; |
| 5892 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5893 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5894 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5895 | QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5896 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5897 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5898 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5899 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5900 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5901 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5902 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5903 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5904 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5905 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5906 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5907 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5908 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5909 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5910 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5911 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5912 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5913 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5914 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5915 | if (!getDerived().AlwaysRebuild() && |
| 5916 | LHS.get() == E->getLHS() && |
| 5917 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5918 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5920 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5921 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5924 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5925 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5926 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5927 | CompoundAssignOperator *E) { |
| 5928 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5929 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5930 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5931 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 5932 | ExprResult TreeTransform<Derived>:: |
| 5933 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 5934 | // Just rebuild the common and RHS expressions and see whether we |
| 5935 | // get any changes. |
| 5936 | |
| 5937 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 5938 | if (commonExpr.isInvalid()) |
| 5939 | return ExprError(); |
| 5940 | |
| 5941 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 5942 | if (rhs.isInvalid()) |
| 5943 | return ExprError(); |
| 5944 | |
| 5945 | if (!getDerived().AlwaysRebuild() && |
| 5946 | commonExpr.get() == e->getCommon() && |
| 5947 | rhs.get() == e->getFalseExpr()) |
| 5948 | return SemaRef.Owned(e); |
| 5949 | |
| 5950 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 5951 | e->getQuestionLoc(), |
| 5952 | 0, |
| 5953 | e->getColonLoc(), |
| 5954 | rhs.get()); |
| 5955 | } |
| 5956 | |
| 5957 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5958 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5959 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5960 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5961 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5962 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5963 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5964 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5965 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5966 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5967 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5968 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5969 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5970 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5971 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5972 | if (!getDerived().AlwaysRebuild() && |
| 5973 | Cond.get() == E->getCond() && |
| 5974 | LHS.get() == E->getLHS() && |
| 5975 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5976 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5977 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5978 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5979 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5980 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5981 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5982 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5983 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5984 | |
| 5985 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5986 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5987 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5988 | // Implicit casts are eliminated during transformation, since they |
| 5989 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5990 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5993 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5994 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5995 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5996 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5997 | if (!Type) |
| 5998 | return ExprError(); |
| 5999 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6000 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6001 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6002 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6003 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6004 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6005 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6006 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6007 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6008 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6009 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6010 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6011 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6012 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6013 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6016 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6017 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6018 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6019 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6020 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6021 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6022 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6024 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6025 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6026 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6027 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6028 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6029 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6030 | Init.get() == E->getInitializer()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6031 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6032 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6033 | // Note: the expression type doesn't necessarily match the |
| 6034 | // type-as-written, but that's okay, because it should always be |
| 6035 | // derivable from the initializer. |
| 6036 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6037 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6038 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6039 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6040 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6042 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6043 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6044 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6045 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6046 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6047 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6048 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6049 | if (!getDerived().AlwaysRebuild() && |
| 6050 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6051 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6052 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6053 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6054 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6055 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6056 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6057 | E->getAccessorLoc(), |
| 6058 | E->getAccessor()); |
| 6059 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6060 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6061 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6062 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6063 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6064 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6065 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6066 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6067 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 6068 | Inits, &InitChanged)) |
| 6069 | return ExprError(); |
| 6070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6071 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6072 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6073 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6074 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6075 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6077 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6078 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6079 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6080 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6081 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6083 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6084 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6085 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6086 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6087 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6088 | // transform the designators. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6089 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6090 | bool ExprChanged = false; |
| 6091 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6092 | DEnd = E->designators_end(); |
| 6093 | D != DEnd; ++D) { |
| 6094 | if (D->isFieldDesignator()) { |
| 6095 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6096 | D->getDotLoc(), |
| 6097 | D->getFieldLoc())); |
| 6098 | continue; |
| 6099 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6100 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6101 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6102 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6103 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6104 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6105 | |
| 6106 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6107 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6109 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6110 | ArrayExprs.push_back(Index.release()); |
| 6111 | continue; |
| 6112 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6113 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6114 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6115 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6116 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6117 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6118 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6119 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6120 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6121 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6122 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6123 | |
| 6124 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6125 | End.get(), |
| 6126 | D->getLBracketLoc(), |
| 6127 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6128 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6129 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6130 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6132 | ArrayExprs.push_back(Start.release()); |
| 6133 | ArrayExprs.push_back(End.release()); |
| 6134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6136 | if (!getDerived().AlwaysRebuild() && |
| 6137 | Init.get() == E->getInit() && |
| 6138 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6139 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6141 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6142 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6143 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6145 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6146 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6147 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6148 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6149 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6150 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6151 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6152 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6153 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6154 | QualType T = getDerived().TransformType(E->getType()); |
| 6155 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6156 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6158 | if (!getDerived().AlwaysRebuild() && |
| 6159 | T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6160 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6162 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6165 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6166 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6167 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6168 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6169 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6170 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6171 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6172 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6173 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6174 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6176 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6177 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6178 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6179 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6180 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6181 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6182 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6183 | } |
| 6184 | |
| 6185 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6186 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6187 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6188 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6189 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6190 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6191 | &ArgumentChanged)) |
| 6192 | return ExprError(); |
| 6193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6194 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6195 | move_arg(Inits), |
| 6196 | E->getRParenLoc()); |
| 6197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6198 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6199 | /// \brief Transform an address-of-label expression. |
| 6200 | /// |
| 6201 | /// By default, the transformation of an address-of-label expression always |
| 6202 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6203 | /// the corresponding label statement by semantic analysis. |
| 6204 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6205 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6206 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6207 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6208 | E->getLabel()); |
| 6209 | if (!LD) |
| 6210 | return ExprError(); |
| 6211 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6212 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6213 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6214 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6215 | |
| 6216 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6217 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6218 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6219 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6220 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 6221 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6222 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6223 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6224 | if (!getDerived().AlwaysRebuild() && |
| 6225 | SubStmt.get() == E->getSubStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6226 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6227 | |
| 6228 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6229 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6230 | E->getRParenLoc()); |
| 6231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6232 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6233 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6234 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6235 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6236 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6237 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6238 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6239 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6240 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6241 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6242 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6243 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6244 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6245 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6246 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6247 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6248 | if (!getDerived().AlwaysRebuild() && |
| 6249 | Cond.get() == E->getCond() && |
| 6250 | LHS.get() == E->getLHS() && |
| 6251 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6252 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6254 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6255 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6256 | E->getRParenLoc()); |
| 6257 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6259 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6260 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6261 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6262 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6266 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6267 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6268 | switch (E->getOperator()) { |
| 6269 | case OO_New: |
| 6270 | case OO_Delete: |
| 6271 | case OO_Array_New: |
| 6272 | case OO_Array_Delete: |
| 6273 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6274 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6275 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6276 | case OO_Call: { |
| 6277 | // This is a call to an object's operator(). |
| 6278 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6279 | |
| 6280 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6281 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6282 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6283 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6284 | |
| 6285 | // FIXME: Poor location information |
| 6286 | SourceLocation FakeLParenLoc |
| 6287 | = SemaRef.PP.getLocForEndOfToken( |
| 6288 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6289 | |
| 6290 | // Transform the call arguments. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6291 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6292 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6293 | Args)) |
| 6294 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6295 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6296 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6297 | move_arg(Args), |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6298 | E->getLocEnd()); |
| 6299 | } |
| 6300 | |
| 6301 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6302 | case OO_##Name: |
| 6303 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6304 | #include "clang/Basic/OperatorKinds.def" |
| 6305 | case OO_Subscript: |
| 6306 | // Handled below. |
| 6307 | break; |
| 6308 | |
| 6309 | case OO_Conditional: |
| 6310 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6311 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6312 | |
| 6313 | case OO_None: |
| 6314 | case NUM_OVERLOADED_OPERATORS: |
| 6315 | llvm_unreachable("not an overloaded operator?"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6316 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6317 | } |
| 6318 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6319 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6320 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6321 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6322 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6323 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6324 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6325 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6326 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6327 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6328 | if (E->getNumArgs() == 2) { |
| 6329 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6330 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6331 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6333 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6334 | if (!getDerived().AlwaysRebuild() && |
| 6335 | Callee.get() == E->getCallee() && |
| 6336 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6337 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6338 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6339 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6340 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6341 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6342 | Callee.get(), |
| 6343 | First.get(), |
| 6344 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6345 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6346 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6347 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6348 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6349 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6350 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6352 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6353 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6354 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6355 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6356 | // Transform the callee. |
| 6357 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6358 | if (Callee.isInvalid()) |
| 6359 | return ExprError(); |
| 6360 | |
| 6361 | // Transform exec config. |
| 6362 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6363 | if (EC.isInvalid()) |
| 6364 | return ExprError(); |
| 6365 | |
| 6366 | // Transform arguments. |
| 6367 | bool ArgChanged = false; |
| 6368 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6369 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6370 | &ArgChanged)) |
| 6371 | return ExprError(); |
| 6372 | |
| 6373 | if (!getDerived().AlwaysRebuild() && |
| 6374 | Callee.get() == E->getCallee() && |
| 6375 | !ArgChanged) |
| 6376 | return SemaRef.Owned(E); |
| 6377 | |
| 6378 | // FIXME: Wrong source location information for the '('. |
| 6379 | SourceLocation FakeLParenLoc |
| 6380 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6381 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6382 | move_arg(Args), |
| 6383 | E->getRParenLoc(), EC.get()); |
| 6384 | } |
| 6385 | |
| 6386 | template<typename Derived> |
| 6387 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6388 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6389 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6390 | if (!Type) |
| 6391 | return ExprError(); |
| 6392 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6393 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6394 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6395 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6396 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6397 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6398 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6399 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6400 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6401 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6402 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6403 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6404 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6405 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6406 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6407 | SourceLocation FakeRParenLoc |
| 6408 | = SemaRef.PP.getLocForEndOfToken( |
| 6409 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6410 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6411 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6412 | FakeLAngleLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6413 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6414 | FakeRAngleLoc, |
| 6415 | FakeRAngleLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6416 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6417 | FakeRParenLoc); |
| 6418 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6419 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6420 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6421 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6422 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6423 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6425 | |
| 6426 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6427 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6428 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6429 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6430 | } |
| 6431 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6432 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6433 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6434 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6435 | CXXReinterpretCastExpr *E) { |
| 6436 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6438 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6439 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6440 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6441 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6442 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6443 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6444 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6445 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6446 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6447 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6448 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6449 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6450 | if (!Type) |
| 6451 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6452 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6453 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6454 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6455 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6456 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6458 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6459 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6460 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6461 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6462 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6463 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6464 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6465 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6466 | E->getRParenLoc()); |
| 6467 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6468 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6470 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6471 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6472 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6473 | TypeSourceInfo *TInfo |
| 6474 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6475 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6476 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6477 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6478 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6479 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6480 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6482 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6483 | E->getLocStart(), |
| 6484 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6485 | E->getLocEnd()); |
| 6486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6487 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6488 | // We don't know whether the expression is potentially evaluated until |
| 6489 | // after we perform semantic analysis, so the expression is potentially |
| 6490 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6491 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6492 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6494 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6495 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6496 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6497 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6498 | if (!getDerived().AlwaysRebuild() && |
| 6499 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6500 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6501 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6502 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6503 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6504 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6505 | E->getLocEnd()); |
| 6506 | } |
| 6507 | |
| 6508 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6509 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6510 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6511 | if (E->isTypeOperand()) { |
| 6512 | TypeSourceInfo *TInfo |
| 6513 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6514 | if (!TInfo) |
| 6515 | return ExprError(); |
| 6516 | |
| 6517 | if (!getDerived().AlwaysRebuild() && |
| 6518 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6519 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6520 | |
| 6521 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6522 | E->getLocStart(), |
| 6523 | TInfo, |
| 6524 | E->getLocEnd()); |
| 6525 | } |
| 6526 | |
| 6527 | // We don't know whether the expression is potentially evaluated until |
| 6528 | // after we perform semantic analysis, so the expression is potentially |
| 6529 | // potentially evaluated. |
| 6530 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6531 | |
| 6532 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6533 | if (SubExpr.isInvalid()) |
| 6534 | return ExprError(); |
| 6535 | |
| 6536 | if (!getDerived().AlwaysRebuild() && |
| 6537 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6538 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6539 | |
| 6540 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6541 | E->getLocStart(), |
| 6542 | SubExpr.get(), |
| 6543 | E->getLocEnd()); |
| 6544 | } |
| 6545 | |
| 6546 | template<typename Derived> |
| 6547 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6548 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6549 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6550 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6551 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6552 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6553 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6554 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6555 | CXXNullPtrLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6556 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6557 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6558 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6559 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6560 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6561 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6562 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
| 6563 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); |
| 6564 | QualType T = MD->getThisType(getSema().Context); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6565 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6566 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6567 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6568 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6569 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6570 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6571 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6572 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6573 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6574 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6575 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6576 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6577 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6579 | if (!getDerived().AlwaysRebuild() && |
| 6580 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6581 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6582 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6583 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6585 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6586 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6587 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6588 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6589 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6590 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6591 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6592 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6593 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6594 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6595 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6596 | Param == E->getParam()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6597 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6598 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6599 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6601 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6602 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6603 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6604 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6605 | CXXScalarValueInitExpr *E) { |
| 6606 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6607 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6608 | return ExprError(); |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6609 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6610 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6611 | T == E->getTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6612 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6613 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6614 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6615 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6616 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6619 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6620 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6621 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6622 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6623 | TypeSourceInfo *AllocTypeInfo |
| 6624 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6625 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6626 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6627 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6628 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6629 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6630 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6631 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6632 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6633 | // Transform the placement arguments (if any). |
| 6634 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6635 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6636 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6637 | E->getNumPlacementArgs(), true, |
| 6638 | PlacementArgs, &ArgumentChanged)) |
| 6639 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6640 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6641 | // transform the constructor arguments (if any). |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6642 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6643 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6644 | ConstructorArgs, &ArgumentChanged)) |
| 6645 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6646 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6647 | // Transform constructor, new operator, and delete operator. |
| 6648 | CXXConstructorDecl *Constructor = 0; |
| 6649 | if (E->getConstructor()) { |
| 6650 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6651 | getDerived().TransformDecl(E->getLocStart(), |
| 6652 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6653 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6654 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | FunctionDecl *OperatorNew = 0; |
| 6658 | if (E->getOperatorNew()) { |
| 6659 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6660 | getDerived().TransformDecl(E->getLocStart(), |
| 6661 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6662 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6663 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6664 | } |
| 6665 | |
| 6666 | FunctionDecl *OperatorDelete = 0; |
| 6667 | if (E->getOperatorDelete()) { |
| 6668 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6669 | getDerived().TransformDecl(E->getLocStart(), |
| 6670 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6671 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6672 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6673 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6675 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6676 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6677 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6678 | Constructor == E->getConstructor() && |
| 6679 | OperatorNew == E->getOperatorNew() && |
| 6680 | OperatorDelete == E->getOperatorDelete() && |
| 6681 | !ArgumentChanged) { |
| 6682 | // Mark any declarations we need as referenced. |
| 6683 | // FIXME: instantiation-specific. |
| 6684 | if (Constructor) |
| 6685 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6686 | if (OperatorNew) |
| 6687 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6688 | if (OperatorDelete) |
| 6689 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6690 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6692 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6693 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6694 | if (!ArraySize.get()) { |
| 6695 | // If no array size was specified, but the new expression was |
| 6696 | // instantiated with an array type (e.g., "new T" where T is |
| 6697 | // instantiated with "int[4]"), extract the outer bound from the |
| 6698 | // array type as our array size. We do this with constant and |
| 6699 | // dependently-sized array types. |
| 6700 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6701 | if (!ArrayT) { |
| 6702 | // Do nothing |
| 6703 | } else if (const ConstantArrayType *ConsArrayT |
| 6704 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6705 | ArraySize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6706 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6707 | ConsArrayT->getSize(), |
| 6708 | SemaRef.Context.getSizeType(), |
| 6709 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6710 | AllocType = ConsArrayT->getElementType(); |
| 6711 | } else if (const DependentSizedArrayType *DepArrayT |
| 6712 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6713 | if (DepArrayT->getSizeExpr()) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6714 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6715 | AllocType = DepArrayT->getElementType(); |
| 6716 | } |
| 6717 | } |
| 6718 | } |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6719 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6720 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6721 | E->isGlobalNew(), |
| 6722 | /*FIXME:*/E->getLocStart(), |
| 6723 | move_arg(PlacementArgs), |
| 6724 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6725 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6726 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6727 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6728 | ArraySize.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6729 | /*FIXME:*/E->getLocStart(), |
| 6730 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6731 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6733 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6734 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6735 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6736 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6737 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6738 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6739 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6740 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6741 | // Transform the delete operator, if known. |
| 6742 | FunctionDecl *OperatorDelete = 0; |
| 6743 | if (E->getOperatorDelete()) { |
| 6744 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6745 | getDerived().TransformDecl(E->getLocStart(), |
| 6746 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6747 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6748 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6749 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6751 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6752 | Operand.get() == E->getArgument() && |
| 6753 | OperatorDelete == E->getOperatorDelete()) { |
| 6754 | // Mark any declarations we need as referenced. |
| 6755 | // FIXME: instantiation-specific. |
| 6756 | if (OperatorDelete) |
| 6757 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 6758 | |
| 6759 | if (!E->getArgument()->isTypeDependent()) { |
| 6760 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 6761 | E->getDestroyedType()); |
| 6762 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 6763 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 6764 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 6765 | SemaRef.LookupDestructor(Record)); |
| 6766 | } |
| 6767 | } |
| 6768 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6769 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6771 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6772 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 6773 | E->isGlobalDelete(), |
| 6774 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6775 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6777 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6778 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6779 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6780 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6781 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6782 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6783 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6784 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6785 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6786 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6787 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6788 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6789 | E->getOperatorLoc(), |
| 6790 | E->isArrow()? tok::arrow : tok::period, |
| 6791 | ObjectTypePtr, |
| 6792 | MayBePseudoDestructor); |
| 6793 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6794 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6795 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6796 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6797 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 6798 | if (QualifierLoc) { |
| 6799 | QualifierLoc |
| 6800 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 6801 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6802 | return ExprError(); |
| 6803 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6804 | CXXScopeSpec SS; |
| 6805 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6806 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6807 | PseudoDestructorTypeStorage Destroyed; |
| 6808 | if (E->getDestroyedTypeInfo()) { |
| 6809 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6810 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6811 | ObjectType, 0, |
| 6812 | QualifierLoc.getNestedNameSpecifier()); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6813 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6814 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6815 | Destroyed = DestroyedTypeInfo; |
| 6816 | } else if (ObjectType->isDependentType()) { |
| 6817 | // We aren't likely to be able to resolve the identifier down to a type |
| 6818 | // now anyway, so just retain the identifier. |
| 6819 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 6820 | E->getDestroyedTypeLoc()); |
| 6821 | } else { |
| 6822 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6823 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6824 | *E->getDestroyedTypeIdentifier(), |
| 6825 | E->getDestroyedTypeLoc(), |
| 6826 | /*Scope=*/0, |
| 6827 | SS, ObjectTypePtr, |
| 6828 | false); |
| 6829 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6830 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6831 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6832 | Destroyed |
| 6833 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 6834 | E->getDestroyedTypeLoc()); |
| 6835 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6836 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6837 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 6838 | if (E->getScopeTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6839 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6840 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6841 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6842 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6843 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6844 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6845 | E->getOperatorLoc(), |
| 6846 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6847 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6848 | ScopeTypeInfo, |
| 6849 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6850 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6851 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6852 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6853 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6854 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6855 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6856 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6857 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6858 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 6859 | |
| 6860 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 6861 | Sema::LookupOrdinaryName); |
| 6862 | |
| 6863 | // Transform all the decls. |
| 6864 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 6865 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6866 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6867 | getDerived().TransformDecl(Old->getNameLoc(), |
| 6868 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6869 | if (!InstD) { |
| 6870 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6871 | // This can happen because of dependent hiding. |
| 6872 | if (isa<UsingShadowDecl>(*I)) |
| 6873 | continue; |
| 6874 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6875 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6876 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6877 | |
| 6878 | // Expand using declarations. |
| 6879 | if (isa<UsingDecl>(InstD)) { |
| 6880 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6881 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6882 | E = UD->shadow_end(); I != E; ++I) |
| 6883 | R.addDecl(*I); |
| 6884 | continue; |
| 6885 | } |
| 6886 | |
| 6887 | R.addDecl(InstD); |
| 6888 | } |
| 6889 | |
| 6890 | // Resolve a kind, but don't do any further analysis. If it's |
| 6891 | // ambiguous, the callee needs to deal with it. |
| 6892 | R.resolveKind(); |
| 6893 | |
| 6894 | // Rebuild the nested-name qualifier, if present. |
| 6895 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6896 | if (Old->getQualifierLoc()) { |
| 6897 | NestedNameSpecifierLoc QualifierLoc |
| 6898 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 6899 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6900 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6901 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6902 | SS.Adopt(QualifierLoc); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6903 | } |
| 6904 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6905 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6906 | CXXRecordDecl *NamingClass |
| 6907 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 6908 | Old->getNameLoc(), |
| 6909 | Old->getNamingClass())); |
| 6910 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6911 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6912 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6913 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6914 | } |
| 6915 | |
| 6916 | // If we have no template arguments, it's a normal declaration name. |
| 6917 | if (!Old->hasExplicitTemplateArgs()) |
| 6918 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 6919 | |
| 6920 | // If we have template arguments, rebuild them, then rebuild the |
| 6921 | // templateid expression. |
| 6922 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6923 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6924 | Old->getNumTemplateArgs(), |
| 6925 | TransArgs)) |
| 6926 | return ExprError(); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6927 | |
| 6928 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 6929 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6930 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6931 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6932 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6933 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6934 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6935 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 6936 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6937 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6939 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6940 | T == E->getQueriedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6941 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6942 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6943 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6944 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6945 | T, |
| 6946 | E->getLocEnd()); |
| 6947 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6948 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6949 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6950 | ExprResult |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 6951 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 6952 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 6953 | if (!LhsT) |
| 6954 | return ExprError(); |
| 6955 | |
| 6956 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 6957 | if (!RhsT) |
| 6958 | return ExprError(); |
| 6959 | |
| 6960 | if (!getDerived().AlwaysRebuild() && |
| 6961 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 6962 | return SemaRef.Owned(E); |
| 6963 | |
| 6964 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 6965 | E->getLocStart(), |
| 6966 | LhsT, RhsT, |
| 6967 | E->getLocEnd()); |
| 6968 | } |
| 6969 | |
| 6970 | template<typename Derived> |
| 6971 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6973 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6974 | NestedNameSpecifierLoc QualifierLoc |
| 6975 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6976 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6977 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6978 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6979 | // TODO: If this is a conversion-function-id, verify that the |
| 6980 | // destination type name (if present) resolves the same way after |
| 6981 | // instantiation as it did in the local scope. |
| 6982 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6983 | DeclarationNameInfo NameInfo |
| 6984 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 6985 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6986 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6987 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6988 | if (!E->hasExplicitTemplateArgs()) { |
| 6989 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6990 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6991 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 6992 | // if name has not changed, DNLoc has not changed either. |
| 6993 | NameInfo.getName() == E->getDeclName()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6994 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6995 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6996 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6997 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6998 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6999 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7000 | |
| 7001 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7002 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7003 | E->getNumTemplateArgs(), |
| 7004 | TransArgs)) |
| 7005 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7006 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7007 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7008 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7009 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7013 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7014 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7015 | // CXXConstructExprs are always implicit, so when we have a |
| 7016 | // 1-argument construction we just transform that argument. |
| 7017 | if (E->getNumArgs() == 1 || |
| 7018 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 7019 | return getDerived().TransformExpr(E->getArg(0)); |
| 7020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7021 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7022 | |
| 7023 | QualType T = getDerived().TransformType(E->getType()); |
| 7024 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7025 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7026 | |
| 7027 | CXXConstructorDecl *Constructor |
| 7028 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7029 | getDerived().TransformDecl(E->getLocStart(), |
| 7030 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7031 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7032 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7034 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7035 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7036 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7037 | &ArgumentChanged)) |
| 7038 | return ExprError(); |
| 7039 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7040 | if (!getDerived().AlwaysRebuild() && |
| 7041 | T == E->getType() && |
| 7042 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7043 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7044 | // Mark the constructor as referenced. |
| 7045 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7046 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7047 | return SemaRef.Owned(E); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7049 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7050 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7051 | Constructor, E->isElidable(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7052 | move_arg(Args), |
| 7053 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7054 | E->getConstructionKind(), |
| 7055 | E->getParenRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7056 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7057 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7058 | /// \brief Transform a C++ temporary-binding expression. |
| 7059 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7060 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7061 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7062 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7063 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7064 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7065 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7067 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7068 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7069 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7070 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7071 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7072 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7073 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7074 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7075 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7076 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7078 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7079 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7080 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7081 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7082 | CXXTemporaryObjectExpr *E) { |
| 7083 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7084 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7085 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7086 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7087 | CXXConstructorDecl *Constructor |
| 7088 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7089 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7090 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7091 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7092 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7093 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7094 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7095 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7096 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7097 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7098 | &ArgumentChanged)) |
| 7099 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7100 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7101 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7102 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7103 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7104 | !ArgumentChanged) { |
| 7105 | // FIXME: Instantiation-specific |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7106 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7107 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7108 | } |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7109 | |
| 7110 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7111 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7112 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7113 | E->getLocEnd()); |
| 7114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7115 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7116 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7117 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7118 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7119 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7120 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7121 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7122 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7124 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7125 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7126 | Args.reserve(E->arg_size()); |
| 7127 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 7128 | &ArgumentChanged)) |
| 7129 | return ExprError(); |
| 7130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7131 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7132 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7133 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7134 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7136 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7137 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7138 | E->getLParenLoc(), |
| 7139 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7140 | E->getRParenLoc()); |
| 7141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7142 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7143 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7144 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7145 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7146 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7147 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7148 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7149 | Expr *OldBase; |
| 7150 | QualType BaseType; |
| 7151 | QualType ObjectType; |
| 7152 | if (!E->isImplicitAccess()) { |
| 7153 | OldBase = E->getBase(); |
| 7154 | Base = getDerived().TransformExpr(OldBase); |
| 7155 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7156 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7157 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7158 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7159 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7160 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7161 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7162 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7163 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7164 | ObjectTy, |
| 7165 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7166 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7167 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7168 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7169 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7170 | BaseType = ((Expr*) Base.get())->getType(); |
| 7171 | } else { |
| 7172 | OldBase = 0; |
| 7173 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 7174 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 7175 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7176 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7177 | // Transform the first part of the nested-name-specifier that qualifies |
| 7178 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7179 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7180 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7181 | E->getFirstQualifierFoundInScope(), |
| 7182 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7183 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7184 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7185 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7186 | QualifierLoc |
| 7187 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 7188 | ObjectType, |
| 7189 | FirstQualifierInScope); |
| 7190 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7191 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7193 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7194 | // TODO: If this is a conversion-function-id, verify that the |
| 7195 | // destination type name (if present) resolves the same way after |
| 7196 | // instantiation as it did in the local scope. |
| 7197 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7198 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7199 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7200 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7201 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7202 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7203 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7204 | // This is a reference to a member without an explicitly-specified |
| 7205 | // template argument list. Optimize for this common case. |
| 7206 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7207 | Base.get() == OldBase && |
| 7208 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7209 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7210 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7211 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7212 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7213 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7214 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7215 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7216 | E->isArrow(), |
| 7217 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7218 | QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7219 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7220 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7221 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7222 | } |
| 7223 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7224 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7225 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7226 | E->getNumTemplateArgs(), |
| 7227 | TransArgs)) |
| 7228 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7229 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7230 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7231 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7232 | E->isArrow(), |
| 7233 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7234 | QualifierLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7235 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7236 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7237 | &TransArgs); |
| 7238 | } |
| 7239 | |
| 7240 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7241 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7242 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7243 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7244 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7245 | QualType BaseType; |
| 7246 | if (!Old->isImplicitAccess()) { |
| 7247 | Base = getDerived().TransformExpr(Old->getBase()); |
| 7248 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7249 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7250 | BaseType = ((Expr*) Base.get())->getType(); |
| 7251 | } else { |
| 7252 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 7253 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7254 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7255 | NestedNameSpecifierLoc QualifierLoc; |
| 7256 | if (Old->getQualifierLoc()) { |
| 7257 | QualifierLoc |
| 7258 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7259 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7260 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7263 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7264 | Sema::LookupOrdinaryName); |
| 7265 | |
| 7266 | // Transform all the decls. |
| 7267 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 7268 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7269 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7270 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 7271 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7272 | if (!InstD) { |
| 7273 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7274 | // This can happen because of dependent hiding. |
| 7275 | if (isa<UsingShadowDecl>(*I)) |
| 7276 | continue; |
| 7277 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7278 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7279 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7280 | |
| 7281 | // Expand using declarations. |
| 7282 | if (isa<UsingDecl>(InstD)) { |
| 7283 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7284 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7285 | E = UD->shadow_end(); I != E; ++I) |
| 7286 | R.addDecl(*I); |
| 7287 | continue; |
| 7288 | } |
| 7289 | |
| 7290 | R.addDecl(InstD); |
| 7291 | } |
| 7292 | |
| 7293 | R.resolveKind(); |
| 7294 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7295 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 7296 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7297 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7298 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7299 | Old->getMemberLoc(), |
| 7300 | Old->getNamingClass())); |
| 7301 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7302 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7303 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7304 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7305 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7306 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7307 | TemplateArgumentListInfo TransArgs; |
| 7308 | if (Old->hasExplicitTemplateArgs()) { |
| 7309 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 7310 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7311 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7312 | Old->getNumTemplateArgs(), |
| 7313 | TransArgs)) |
| 7314 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7315 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7316 | |
| 7317 | // FIXME: to do this check properly, we will need to preserve the |
| 7318 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7319 | // base (and therefore couldn't do the check) and a |
| 7320 | // nested-name-qualifier (and therefore could do the lookup). |
| 7321 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7322 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7323 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7324 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7325 | Old->getOperatorLoc(), |
| 7326 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7327 | QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7328 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7329 | R, |
| 7330 | (Old->hasExplicitTemplateArgs() |
| 7331 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7335 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7336 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 7337 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 7338 | if (SubExpr.isInvalid()) |
| 7339 | return ExprError(); |
| 7340 | |
| 7341 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7342 | return SemaRef.Owned(E); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7343 | |
| 7344 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 7345 | } |
| 7346 | |
| 7347 | template<typename Derived> |
| 7348 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7349 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 7350 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 7351 | if (Pattern.isInvalid()) |
| 7352 | return ExprError(); |
| 7353 | |
| 7354 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 7355 | return SemaRef.Owned(E); |
| 7356 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 7357 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 7358 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7359 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7360 | |
| 7361 | template<typename Derived> |
| 7362 | ExprResult |
| 7363 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7364 | // If E is not value-dependent, then nothing will change when we transform it. |
| 7365 | // Note: This is an instantiation-centric view. |
| 7366 | if (!E->isValueDependent()) |
| 7367 | return SemaRef.Owned(E); |
| 7368 | |
| 7369 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 7370 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 7371 | // so |
| 7372 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 7373 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7374 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7375 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7376 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 7377 | &Unexpanded, 1, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7378 | ShouldExpand, RetainExpansion, |
| 7379 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7380 | return ExprError(); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7381 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7382 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7383 | return SemaRef.Owned(E); |
| 7384 | |
| 7385 | // We now know the length of the parameter pack, so build a new expression |
| 7386 | // that stores that length. |
| 7387 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 7388 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7389 | *NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7390 | } |
| 7391 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7392 | template<typename Derived> |
| 7393 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 7394 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 7395 | SubstNonTypeTemplateParmPackExpr *E) { |
| 7396 | // Default behavior is to do nothing with this transformation. |
| 7397 | return SemaRef.Owned(E); |
| 7398 | } |
| 7399 | |
| 7400 | template<typename Derived> |
| 7401 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7402 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7403 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7404 | } |
| 7405 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7406 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7407 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7408 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7409 | TypeSourceInfo *EncodedTypeInfo |
| 7410 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 7411 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7412 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7413 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7414 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7415 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7416 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7417 | |
| 7418 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7419 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7420 | E->getRParenLoc()); |
| 7421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7423 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7424 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7425 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7426 | // Transform arguments. |
| 7427 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7428 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7429 | Args.reserve(E->getNumArgs()); |
| 7430 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 7431 | &ArgChanged)) |
| 7432 | return ExprError(); |
| 7433 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7434 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 7435 | // Class message: transform the receiver type. |
| 7436 | TypeSourceInfo *ReceiverTypeInfo |
| 7437 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 7438 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7439 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7440 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7441 | // If nothing changed, just retain the existing message send. |
| 7442 | if (!getDerived().AlwaysRebuild() && |
| 7443 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7444 | return SemaRef.Owned(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7445 | |
| 7446 | // Build a new class message send. |
| 7447 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7448 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7449 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7450 | E->getMethodDecl(), |
| 7451 | E->getLeftLoc(), |
| 7452 | move_arg(Args), |
| 7453 | E->getRightLoc()); |
| 7454 | } |
| 7455 | |
| 7456 | // Instance message: transform the receiver |
| 7457 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7458 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7459 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7460 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7461 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7462 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7463 | |
| 7464 | // If nothing changed, just retain the existing message send. |
| 7465 | if (!getDerived().AlwaysRebuild() && |
| 7466 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7467 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7468 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7469 | // Build a new instance message send. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7470 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7471 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7472 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7473 | E->getMethodDecl(), |
| 7474 | E->getLeftLoc(), |
| 7475 | move_arg(Args), |
| 7476 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7477 | } |
| 7478 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7479 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7480 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7481 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7482 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7483 | } |
| 7484 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7485 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7486 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7487 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7488 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7489 | } |
| 7490 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7491 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7492 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7493 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7494 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7495 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7496 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7497 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7498 | |
| 7499 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7500 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7501 | // If nothing changed, just retain the existing expression. |
| 7502 | if (!getDerived().AlwaysRebuild() && |
| 7503 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7504 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7505 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7506 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7507 | E->getLocation(), |
| 7508 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7509 | } |
| 7510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7511 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7512 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7513 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7514 | // 'super' and types never change. Property never changes. Just |
| 7515 | // retain the existing expression. |
| 7516 | if (!E->isObjectReceiver()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7517 | return SemaRef.Owned(E); |
Fariborz Jahanian | 681c075 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7518 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7519 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7520 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7521 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7522 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7523 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7524 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7525 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7526 | // If nothing changed, just retain the existing expression. |
| 7527 | if (!getDerived().AlwaysRebuild() && |
| 7528 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7529 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7530 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7531 | if (E->isExplicitProperty()) |
| 7532 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7533 | E->getExplicitProperty(), |
| 7534 | E->getLocation()); |
| 7535 | |
| 7536 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7537 | E->getType(), |
| 7538 | E->getImplicitPropertyGetter(), |
| 7539 | E->getImplicitPropertySetter(), |
| 7540 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7541 | } |
| 7542 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7543 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7544 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7545 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7546 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7547 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7548 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7549 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7550 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7551 | // If nothing changed, just retain the existing expression. |
| 7552 | if (!getDerived().AlwaysRebuild() && |
| 7553 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7554 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7555 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7556 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7557 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7558 | } |
| 7559 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7560 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7561 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7562 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7563 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7564 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7565 | SubExprs.reserve(E->getNumSubExprs()); |
| 7566 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7567 | SubExprs, &ArgumentChanged)) |
| 7568 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7569 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7570 | if (!getDerived().AlwaysRebuild() && |
| 7571 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7572 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7573 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7574 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7575 | move_arg(SubExprs), |
| 7576 | E->getRParenLoc()); |
| 7577 | } |
| 7578 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7579 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7580 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7581 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7582 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7583 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7584 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7585 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7586 | |
| 7587 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 7588 | llvm::SmallVector<ParmVarDecl*, 4> params; |
| 7589 | llvm::SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7590 | |
| 7591 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7592 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7593 | oldBlock->param_begin(), |
| 7594 | oldBlock->param_size(), |
| 7595 | 0, paramTypes, ¶ms)) |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7596 | return true; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7597 | |
| 7598 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7599 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7600 | if (!exprResultType.isNull()) { |
| 7601 | if (!exprResultType->isDependentType()) |
| 7602 | blockScope->ReturnType = exprResultType; |
| 7603 | else if (exprResultType != getSema().Context.DependentTy) |
| 7604 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7605 | } |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7606 | |
| 7607 | // If the return type has not been determined yet, leave it as a dependent |
| 7608 | // type; it'll get set when we process the body. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7609 | if (blockScope->ReturnType.isNull()) |
| 7610 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7611 | |
| 7612 | // Don't allow returning a objc interface by value. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7613 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7614 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7615 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7616 | << 0 << blockScope->ReturnType; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7617 | return ExprError(); |
| 7618 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7619 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7620 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7621 | blockScope->ReturnType, |
| 7622 | paramTypes.data(), |
| 7623 | paramTypes.size(), |
| 7624 | oldBlock->isVariadic(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7625 | 0, RQ_None, |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7626 | exprFunctionType->getExtInfo()); |
| 7627 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7628 | |
| 7629 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7630 | if (!params.empty()) |
| 7631 | blockScope->TheDecl->setParams(params.data(), params.size()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7632 | |
| 7633 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7634 | // dependent type (DependentTy); clear out the return type setting so |
| 7635 | // we will deduce the return type when type-checking the block's body. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7636 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7637 | blockScope->ReturnType = QualType(); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7638 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7639 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7640 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7641 | if (body.isInvalid()) |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7642 | return ExprError(); |
| 7643 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7644 | #ifndef NDEBUG |
| 7645 | // In builds with assertions, make sure that we captured everything we |
| 7646 | // captured before. |
| 7647 | |
| 7648 | if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); |
| 7649 | |
| 7650 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 7651 | e = oldBlock->capture_end(); i != e; ++i) { |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7652 | VarDecl *oldCapture = i->getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7653 | |
| 7654 | // Ignore parameter packs. |
| 7655 | if (isa<ParmVarDecl>(oldCapture) && |
| 7656 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 7657 | continue; |
| 7658 | |
| 7659 | VarDecl *newCapture = |
| 7660 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 7661 | oldCapture)); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7662 | assert(blockScope->CaptureMap.count(newCapture)); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7663 | } |
| 7664 | #endif |
| 7665 | |
| 7666 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 7667 | /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7668 | } |
| 7669 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7670 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7671 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7672 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7673 | ValueDecl *ND |
| 7674 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7675 | E->getDecl())); |
| 7676 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7677 | return ExprError(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7678 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7679 | if (!getDerived().AlwaysRebuild() && |
| 7680 | ND == E->getDecl()) { |
| 7681 | // Mark it referenced in the new context regardless. |
| 7682 | // FIXME: this is a bit instantiation-specific. |
| 7683 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 7684 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7685 | return SemaRef.Owned(E); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7686 | } |
| 7687 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7688 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7689 | return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7690 | ND, NameInfo, 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7692 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7693 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7694 | // Type reconstruction |
| 7695 | //===----------------------------------------------------------------------===// |
| 7696 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7697 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7698 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 7699 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7700 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7701 | getDerived().getBaseEntity()); |
| 7702 | } |
| 7703 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7704 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7705 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 7706 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7707 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7708 | getDerived().getBaseEntity()); |
| 7709 | } |
| 7710 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7711 | template<typename Derived> |
| 7712 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7713 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 7714 | bool WrittenAsLValue, |
| 7715 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7716 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7717 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7721 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7722 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 7723 | QualType ClassType, |
| 7724 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7725 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7726 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7727 | } |
| 7728 | |
| 7729 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7730 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7731 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 7732 | ArrayType::ArraySizeModifier SizeMod, |
| 7733 | const llvm::APInt *Size, |
| 7734 | Expr *SizeExpr, |
| 7735 | unsigned IndexTypeQuals, |
| 7736 | SourceRange BracketsRange) { |
| 7737 | if (SizeExpr || !Size) |
| 7738 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 7739 | IndexTypeQuals, BracketsRange, |
| 7740 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7741 | |
| 7742 | QualType Types[] = { |
| 7743 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 7744 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 7745 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7746 | }; |
| 7747 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 7748 | QualType SizeType; |
| 7749 | for (unsigned I = 0; I != NumTypes; ++I) |
| 7750 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 7751 | SizeType = Types[I]; |
| 7752 | break; |
| 7753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7754 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7755 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 7756 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7757 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7758 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7759 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7761 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7762 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7763 | QualType |
| 7764 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7765 | ArrayType::ArraySizeModifier SizeMod, |
| 7766 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7767 | unsigned IndexTypeQuals, |
| 7768 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7769 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7770 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7771 | } |
| 7772 | |
| 7773 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7774 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7775 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7776 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7777 | unsigned IndexTypeQuals, |
| 7778 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7779 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7780 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7781 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7782 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7783 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7784 | QualType |
| 7785 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7786 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7787 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7788 | unsigned IndexTypeQuals, |
| 7789 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7790 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7791 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7792 | IndexTypeQuals, BracketsRange); |
| 7793 | } |
| 7794 | |
| 7795 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7796 | QualType |
| 7797 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7798 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7799 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7800 | unsigned IndexTypeQuals, |
| 7801 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7802 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7803 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7804 | IndexTypeQuals, BracketsRange); |
| 7805 | } |
| 7806 | |
| 7807 | template<typename Derived> |
| 7808 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7809 | unsigned NumElements, |
| 7810 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7811 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7812 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7813 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7814 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7815 | template<typename Derived> |
| 7816 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 7817 | unsigned NumElements, |
| 7818 | SourceLocation AttributeLoc) { |
| 7819 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 7820 | NumElements, true); |
| 7821 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7822 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 7823 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7824 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7826 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7827 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7828 | QualType |
| 7829 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7830 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7831 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7832 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7834 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7835 | template<typename Derived> |
| 7836 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7837 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7838 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7839 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7840 | unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7841 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7842 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7843 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7844 | Quals, RefQualifier, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7845 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7846 | getDerived().getBaseEntity(), |
| 7847 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7849 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7850 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 7851 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 7852 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 7853 | } |
| 7854 | |
| 7855 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7856 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 7857 | assert(D && "no decl found"); |
| 7858 | if (D->isInvalidDecl()) return QualType(); |
| 7859 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7860 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7861 | TypeDecl *Ty; |
| 7862 | if (isa<UsingDecl>(D)) { |
| 7863 | UsingDecl *Using = cast<UsingDecl>(D); |
| 7864 | assert(Using->isTypeName() && |
| 7865 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 7866 | |
| 7867 | // A valid resolved using typename decl points to exactly one type decl. |
| 7868 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 7869 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7870 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7871 | } else { |
| 7872 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 7873 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 7874 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 7875 | } |
| 7876 | |
| 7877 | return SemaRef.Context.getTypeDeclType(Ty); |
| 7878 | } |
| 7879 | |
| 7880 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7881 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 7882 | SourceLocation Loc) { |
| 7883 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7884 | } |
| 7885 | |
| 7886 | template<typename Derived> |
| 7887 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 7888 | return SemaRef.Context.getTypeOfType(Underlying); |
| 7889 | } |
| 7890 | |
| 7891 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7892 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 7893 | SourceLocation Loc) { |
| 7894 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7895 | } |
| 7896 | |
| 7897 | template<typename Derived> |
| 7898 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 7899 | TemplateName Template, |
| 7900 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7901 | const TemplateArgumentListInfo &TemplateArgs) { |
| 7902 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7903 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7904 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7905 | template<typename Derived> |
| 7906 | NestedNameSpecifier * |
| 7907 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7908 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7909 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7910 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7911 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7912 | CXXScopeSpec SS; |
| 7913 | // FIXME: The source location information is all wrong. |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7914 | SS.MakeTrivial(SemaRef.Context, Prefix, Range); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 7915 | if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(), |
| 7916 | /*FIXME:*/Range.getEnd(), |
| 7917 | ObjectType, false, |
| 7918 | SS, FirstQualifierInScope, |
| 7919 | false)) |
| 7920 | return 0; |
| 7921 | |
| 7922 | return SS.getScopeRep(); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7923 | } |
| 7924 | |
| 7925 | template<typename Derived> |
| 7926 | NestedNameSpecifier * |
| 7927 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7928 | SourceRange Range, |
| 7929 | NamespaceDecl *NS) { |
| 7930 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 7931 | } |
| 7932 | |
| 7933 | template<typename Derived> |
| 7934 | NestedNameSpecifier * |
| 7935 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7936 | SourceRange Range, |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 7937 | NamespaceAliasDecl *Alias) { |
| 7938 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias); |
| 7939 | } |
| 7940 | |
| 7941 | template<typename Derived> |
| 7942 | NestedNameSpecifier * |
| 7943 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7944 | SourceRange Range, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7945 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 7946 | QualType T) { |
| 7947 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7948 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 7949 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7950 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 7951 | T.getTypePtr()); |
| 7952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7953 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7954 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 7955 | return 0; |
| 7956 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7957 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7958 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7959 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7960 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7961 | bool TemplateKW, |
| 7962 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7963 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7964 | Template); |
| 7965 | } |
| 7966 | |
| 7967 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7968 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7969 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 7970 | SourceRange QualifierRange, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7971 | const IdentifierInfo &II, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7972 | QualType ObjectType, |
| 7973 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7974 | CXXScopeSpec SS; |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7975 | SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 7976 | UnqualifiedId Name; |
| 7977 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7978 | Sema::TemplateTy Template; |
| 7979 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 7980 | /*FIXME:*/getDerived().getBaseLocation(), |
| 7981 | SS, |
| 7982 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7983 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7984 | /*EnteringContext=*/false, |
| 7985 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7986 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7989 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7990 | TemplateName |
| 7991 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7992 | OverloadedOperatorKind Operator, |
| 7993 | QualType ObjectType) { |
| 7994 | CXXScopeSpec SS; |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7995 | SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7996 | UnqualifiedId Name; |
| 7997 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 7998 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 7999 | Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8000 | Sema::TemplateTy Template; |
| 8001 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8002 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8003 | SS, |
| 8004 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8005 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8006 | /*EnteringContext=*/false, |
| 8007 | Template); |
| 8008 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8009 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8010 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8011 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8012 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8013 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 8014 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8015 | Expr *OrigCallee, |
| 8016 | Expr *First, |
| 8017 | Expr *Second) { |
| 8018 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 8019 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8021 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8022 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8023 | if (!First->getType()->isOverloadableType() && |
| 8024 | !Second->getType()->isOverloadableType()) |
| 8025 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 8026 | Callee->getLocStart(), |
| 8027 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 8028 | } else if (Op == OO_Arrow) { |
| 8029 | // -> is never a builtin operation. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8030 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 8031 | } else if (Second == 0 || isPostIncDec) { |
| 8032 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8033 | // The argument is not of overloadable type, so try to create a |
| 8034 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8035 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8036 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8037 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8038 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8039 | } |
| 8040 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8041 | if (!First->getType()->isOverloadableType() && |
| 8042 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8043 | // Neither of the arguments is an overloadable type, so try to |
| 8044 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8045 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8046 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8047 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8048 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8049 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8051 | return move(Result); |
| 8052 | } |
| 8053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8054 | |
| 8055 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8056 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8057 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8058 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8059 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8060 | assert(ULE->requiresADL()); |
| 8061 | |
| 8062 | // FIXME: Do we have to check |
| 8063 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8064 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8065 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8066 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8067 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8068 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8069 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8070 | Expr *Args[2] = { First, Second }; |
| 8071 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8072 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8073 | // Create the overloaded operator invocation for unary operators. |
| 8074 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8075 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8076 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8077 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8078 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8079 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8080 | if (Op == OO_Subscript) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8081 | return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8082 | OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8083 | First, |
| 8084 | Second); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8086 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8087 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8088 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8089 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 8090 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8091 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8092 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8093 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8095 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8096 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8097 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8098 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8099 | SourceLocation OperatorLoc, |
| 8100 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8101 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8102 | TypeSourceInfo *ScopeType, |
| 8103 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8104 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8105 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8106 | QualType BaseType = Base->getType(); |
| 8107 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8108 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8109 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 8110 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 8111 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8112 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8113 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8114 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8115 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8116 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8117 | /*FIXME?*/true); |
| 8118 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8119 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8120 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8121 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 8122 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 8123 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 8124 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 8125 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8126 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8127 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8128 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8129 | OperatorLoc, isArrow, |
| 8130 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8131 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8132 | /*TemplateArgs*/ 0); |
| 8133 | } |
| 8134 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8135 | } // end namespace clang |
| 8136 | |
| 8137 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |