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" |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
| 27 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 28 | #include "clang/AST/Stmt.h" |
| 29 | #include "clang/AST/StmtCXX.h" |
| 30 | #include "clang/AST/StmtObjC.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/Designator.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 33 | #include "clang/Lex/Preprocessor.h" |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/ArrayRef.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 451d1b1 | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 36 | #include "TypeLocBuilder.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | |
| 39 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 40 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 42 | /// \brief A semantic tree transformation that allows one to transform one |
| 43 | /// abstract syntax tree into another. |
| 44 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 46 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 47 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 48 | /// instantiation is implemented as a tree transformation where the |
| 49 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 50 | /// template arguments for their corresponding template parameters; a similar |
| 51 | /// transformation is performed for non-type template parameters and |
| 52 | /// template template parameters. |
| 53 | /// |
| 54 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 56 | /// override any of the transformation or rebuild operators by providing an |
| 57 | /// operation with the same signature as the default implementation. The |
| 58 | /// overridding function should not be virtual. |
| 59 | /// |
| 60 | /// Semantic tree transformations are split into two stages, either of which |
| 61 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 62 | /// or the parts of an AST node using the various transformation functions, |
| 63 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 64 | /// node of the appropriate kind from the pieces. The default transformation |
| 65 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 66 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 67 | /// were changed by the transformation, invokes the rebuild operation to create |
| 68 | /// a new AST node. |
| 69 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 71 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 72 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 73 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 74 | /// new implementations. |
| 75 | /// |
| 76 | /// For more fine-grained transformations, subclasses can replace any of the |
| 77 | /// \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] | 78 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 82 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 83 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 84 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 85 | /// be able to use more efficient rebuild steps. |
| 86 | /// |
| 87 | /// 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] | 88 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 89 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 90 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 91 | /// default locations and entity names used for type-checking |
| 92 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 93 | template<typename Derived> |
| 94 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 95 | /// \brief Private RAII object that helps us forget and then re-remember |
| 96 | /// the template argument corresponding to a partially-substituted parameter |
| 97 | /// pack. |
| 98 | class ForgetPartiallySubstitutedPackRAII { |
| 99 | Derived &Self; |
| 100 | TemplateArgument Old; |
| 101 | |
| 102 | public: |
| 103 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 104 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 105 | } |
| 106 | |
| 107 | ~ForgetPartiallySubstitutedPackRAII() { |
| 108 | Self.RememberPartiallySubstitutedPack(Old); |
| 109 | } |
| 110 | }; |
| 111 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 112 | protected: |
| 113 | Sema &SemaRef; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 114 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 116 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 117 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 119 | /// \brief Retrieves a reference to the derived class. |
| 120 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 121 | |
| 122 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | const Derived &getDerived() const { |
| 124 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 125 | } |
| 126 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 127 | static inline ExprResult Owned(Expr *E) { return E; } |
| 128 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 131 | /// this tree transform. |
| 132 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 134 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 135 | /// if none of the children have changed. |
| 136 | /// |
| 137 | /// Subclasses may override this function to specify when the transformation |
| 138 | /// should rebuild all AST nodes. |
| 139 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 140 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 141 | /// \brief Returns the location of the entity being transformed, if that |
| 142 | /// information was not available elsewhere in the AST. |
| 143 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 144 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 145 | /// provide an alternative implementation that provides better location |
| 146 | /// information. |
| 147 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 149 | /// \brief Returns the name of the entity being transformed, if that |
| 150 | /// information was not available elsewhere in the AST. |
| 151 | /// |
| 152 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 153 | /// implementation with a more precise name. |
| 154 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 155 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 156 | /// \brief Sets the "base" location and entity when that |
| 157 | /// information is known based on another transformation. |
| 158 | /// |
| 159 | /// By default, the source location and entity are ignored. Subclasses can |
| 160 | /// override this function to provide a customized implementation. |
| 161 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 163 | /// \brief RAII object that temporarily sets the base location and entity |
| 164 | /// used for reporting diagnostics in types. |
| 165 | class TemporaryBase { |
| 166 | TreeTransform &Self; |
| 167 | SourceLocation OldLocation; |
| 168 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 170 | public: |
| 171 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 173 | OldLocation = Self.getDerived().getBaseLocation(); |
| 174 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 175 | |
| 176 | if (Location.isValid()) |
| 177 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 180 | ~TemporaryBase() { |
| 181 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 182 | } |
| 183 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | |
| 185 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 186 | /// transformed. |
| 187 | /// |
| 188 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | /// 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] | 190 | /// not change. For example, template instantiation need not traverse |
| 191 | /// non-dependent types. |
| 192 | bool AlreadyTransformed(QualType T) { |
| 193 | return T.isNull(); |
| 194 | } |
| 195 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 196 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 197 | /// because it is a default argument. |
| 198 | /// |
| 199 | /// Subclasses can provide an alternative implementation of this routine to |
| 200 | /// determine which kinds of call arguments get dropped. By default, |
| 201 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 202 | bool DropCallArgument(Expr *E) { |
| 203 | return E->isDefaultArgument(); |
| 204 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 205 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 206 | /// \brief Determine whether we should expand a pack expansion with the |
| 207 | /// given set of parameter packs into separate arguments by repeatedly |
| 208 | /// transforming the pattern. |
| 209 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 210 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 211 | /// Subclasses can override this routine to provide different behavior. |
| 212 | /// |
| 213 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 214 | /// pack expansion. |
| 215 | /// |
| 216 | /// \param PatternRange The source range that covers the entire pattern of |
| 217 | /// the pack expansion. |
| 218 | /// |
| 219 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 220 | /// pattern. |
| 221 | /// |
| 222 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 223 | /// \p Unexpanded. |
| 224 | /// |
| 225 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 226 | /// expand the corresponding pack expansions into separate arguments. When |
| 227 | /// set, \c NumExpansions must also be set. |
| 228 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 229 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 230 | /// pack expansion after all of the expanded arguments. This is used |
| 231 | /// when extending explicitly-specified template argument packs per |
| 232 | /// C++0x [temp.arg.explicit]p9. |
| 233 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 234 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 235 | /// the expanded form of the corresponding pack expansion. This is both an |
| 236 | /// input and an output parameter, which can be set by the caller if the |
| 237 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 238 | /// and will be set by the callee when the number of expansions is known. |
| 239 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 240 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 241 | /// |
| 242 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 243 | /// are to be instantiated with arguments of different lengths), false |
| 244 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 245 | /// must be set. |
| 246 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 247 | SourceRange PatternRange, |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 248 | llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 249 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 250 | bool &RetainExpansion, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 251 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | ShouldExpand = false; |
| 253 | return false; |
| 254 | } |
| 255 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 256 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 257 | /// when performing an instantiation that must preserve the parameter pack |
| 258 | /// use. |
| 259 | /// |
| 260 | /// This routine is meant to be overridden by the template instantiator. |
| 261 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 262 | return TemplateArgument(); |
| 263 | } |
| 264 | |
| 265 | /// \brief "Remember" the partially-substituted pack template argument |
| 266 | /// after performing an instantiation that must preserve the parameter pack |
| 267 | /// use. |
| 268 | /// |
| 269 | /// This routine is meant to be overridden by the template instantiator. |
| 270 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 271 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 272 | /// \brief Note to the derived class when a function parameter pack is |
| 273 | /// being expanded. |
| 274 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 275 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 276 | /// \brief Transforms the given type into another type. |
| 277 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 278 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 279 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 280 | /// function. This is expensive, but we don't mind, because |
| 281 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 282 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// |
| 284 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 285 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 287 | /// \brief Transforms the given type-with-location into a new |
| 288 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 290 | /// By default, this routine transforms a type by delegating to the |
| 291 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 292 | /// may override this function (to take over all type |
| 293 | /// transformations) or some set of the TransformXXXType functions |
| 294 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 295 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 296 | |
| 297 | /// \brief Transform the given type-with-location into a new |
| 298 | /// type, collecting location information in the given builder |
| 299 | /// as necessary. |
| 300 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 301 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 303 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 304 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 306 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 307 | /// statement or the TransformExpr() function to transform an expression. |
| 308 | /// Subclasses may override this function to transform statements using some |
| 309 | /// other mechanism. |
| 310 | /// |
| 311 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 312 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 314 | /// \brief Transform the given expression. |
| 315 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 316 | /// By default, this routine transforms an expression by delegating to the |
| 317 | /// appropriate TransformXXXExpr function to build a new expression. |
| 318 | /// Subclasses may override this function to transform expressions using some |
| 319 | /// other mechanism. |
| 320 | /// |
| 321 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 322 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 324 | /// \brief Transform the given list of expressions. |
| 325 | /// |
| 326 | /// This routine transforms a list of expressions by invoking |
| 327 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 328 | /// support for variadic templates by expanding any pack expansions (if the |
| 329 | /// derived class permits such expansion) along the way. When pack expansions |
| 330 | /// are present, the number of outputs may not equal the number of inputs. |
| 331 | /// |
| 332 | /// \param Inputs The set of expressions to be transformed. |
| 333 | /// |
| 334 | /// \param NumInputs The number of expressions in \c Inputs. |
| 335 | /// |
| 336 | /// \param IsCall If \c true, then this transform is being performed on |
| 337 | /// function-call arguments, and any arguments that should be dropped, will |
| 338 | /// be. |
| 339 | /// |
| 340 | /// \param Outputs The transformed input expressions will be added to this |
| 341 | /// vector. |
| 342 | /// |
| 343 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 344 | /// due to transformation. |
| 345 | /// |
| 346 | /// \returns true if an error occurred, false otherwise. |
| 347 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 348 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 349 | bool *ArgChanged = 0); |
| 350 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 351 | /// \brief Transform the given declaration, which is referenced from a type |
| 352 | /// or expression. |
| 353 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 354 | /// By default, acts as the identity function on declarations. Subclasses |
| 355 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 356 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 357 | |
| 358 | /// \brief Transform the definition of the given declaration. |
| 359 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 361 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 362 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 363 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 366 | /// \brief Transform the given declaration, which was the first part of a |
| 367 | /// nested-name-specifier in a member access expression. |
| 368 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 369 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 370 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 371 | /// the \c T in \c x->T::member |
| 372 | /// |
| 373 | /// By default, invokes TransformDecl() to transform the declaration. |
| 374 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 375 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 376 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 377 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 378 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 379 | /// \brief Transform the given nested-name-specifier with source-location |
| 380 | /// information. |
| 381 | /// |
| 382 | /// By default, transforms all of the types and declarations within the |
| 383 | /// nested-name-specifier. Subclasses may override this function to provide |
| 384 | /// alternate behavior. |
| 385 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 386 | NestedNameSpecifierLoc NNS, |
| 387 | QualType ObjectType = QualType(), |
| 388 | NamedDecl *FirstQualifierInScope = 0); |
| 389 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 390 | /// \brief Transform the given declaration name. |
| 391 | /// |
| 392 | /// By default, transforms the types of conversion function, constructor, |
| 393 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 394 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 395 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 396 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 397 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 399 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 401 | /// \param SS The nested-name-specifier that qualifies the template |
| 402 | /// name. This nested-name-specifier must already have been transformed. |
| 403 | /// |
| 404 | /// \param Name The template name to transform. |
| 405 | /// |
| 406 | /// \param NameLoc The source location of the template name. |
| 407 | /// |
| 408 | /// \param ObjectType If we're translating a template name within a member |
| 409 | /// access expression, this is the type of the object whose member template |
| 410 | /// is being referenced. |
| 411 | /// |
| 412 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 413 | /// also refers to a name within the current (lexical) scope, this is the |
| 414 | /// declaration it refers to. |
| 415 | /// |
| 416 | /// By default, transforms the template name by transforming the declarations |
| 417 | /// and nested-name-specifiers that occur within the template name. |
| 418 | /// Subclasses may override this function to provide alternate behavior. |
| 419 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 420 | TemplateName Name, |
| 421 | SourceLocation NameLoc, |
| 422 | QualType ObjectType = QualType(), |
| 423 | NamedDecl *FirstQualifierInScope = 0); |
| 424 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | /// \brief Transform the given template argument. |
| 426 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | /// By default, this operation transforms the type, expression, or |
| 428 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 429 | /// new template argument from the transformed result. Subclasses may |
| 430 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 431 | /// |
| 432 | /// Returns true if there was an error. |
| 433 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 434 | TemplateArgumentLoc &Output); |
| 435 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 436 | /// \brief Transform the given set of template arguments. |
| 437 | /// |
| 438 | /// By default, this operation transforms all of the template arguments |
| 439 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 440 | /// the transformed arguments to the output list. |
| 441 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 442 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 443 | /// a convenience function. Subclasses that wish to override this behavior |
| 444 | /// should override the iterator-based member template version. |
| 445 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 446 | /// \param Inputs The set of template arguments to be transformed. |
| 447 | /// |
| 448 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 449 | /// |
| 450 | /// \param Outputs The set of transformed template arguments output by this |
| 451 | /// routine. |
| 452 | /// |
| 453 | /// Returns true if an error occurred. |
| 454 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 455 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 456 | TemplateArgumentListInfo &Outputs) { |
| 457 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 458 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 459 | |
| 460 | /// \brief Transform the given set of template arguments. |
| 461 | /// |
| 462 | /// By default, this operation transforms all of the template arguments |
| 463 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 464 | /// the transformed arguments to the output list. |
| 465 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 466 | /// \param First An iterator to the first template argument. |
| 467 | /// |
| 468 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 469 | /// |
| 470 | /// \param Outputs The set of transformed template arguments output by this |
| 471 | /// routine. |
| 472 | /// |
| 473 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 474 | template<typename InputIterator> |
| 475 | bool TransformTemplateArguments(InputIterator First, |
| 476 | InputIterator Last, |
| 477 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 478 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 479 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 480 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 481 | TemplateArgumentLoc &ArgLoc); |
| 482 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 483 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 484 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 485 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 486 | getDerived().getBaseLocation()); |
| 487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 489 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 490 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 491 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 492 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 494 | StmtResult |
| 495 | TransformSEHHandler(Stmt *Handler); |
| 496 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 497 | QualType |
| 498 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 499 | TemplateSpecializationTypeLoc TL, |
| 500 | TemplateName Template); |
| 501 | |
| 502 | QualType |
| 503 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 504 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 505 | TemplateName Template, |
| 506 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 507 | |
| 508 | QualType |
| 509 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 510 | DependentTemplateSpecializationTypeLoc TL, |
| 511 | NestedNameSpecifierLoc QualifierLoc); |
| 512 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 513 | /// \brief Transforms the parameters of a function type into the |
| 514 | /// given vectors. |
| 515 | /// |
| 516 | /// The result vectors should be kept in sync; null entries in the |
| 517 | /// variables vector are acceptable. |
| 518 | /// |
| 519 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 520 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 521 | ParmVarDecl **Params, unsigned NumParams, |
| 522 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 523 | SmallVectorImpl<QualType> &PTypes, |
| 524 | SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 525 | |
| 526 | /// \brief Transforms a single function-type parameter. Return null |
| 527 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 528 | /// |
| 529 | /// \param indexAdjustment - A number to add to the parameter's |
| 530 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 531 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 532 | int indexAdjustment, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 533 | llvm::Optional<unsigned> NumExpansions); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 534 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 535 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 536 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 537 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 538 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 540 | #define STMT(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 541 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 542 | #define EXPR(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 543 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 544 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 545 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 547 | /// \brief Build a new pointer type given its pointee type. |
| 548 | /// |
| 549 | /// By default, performs semantic analysis when building the pointer type. |
| 550 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 551 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 552 | |
| 553 | /// \brief Build a new block pointer type given its pointee type. |
| 554 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 556 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 557 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 558 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 559 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 561 | /// By default, performs semantic analysis when building the |
| 562 | /// reference type. Subclasses may override this routine to provide |
| 563 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 564 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 565 | /// \param LValue whether the type was written with an lvalue sigil |
| 566 | /// or an rvalue sigil. |
| 567 | QualType RebuildReferenceType(QualType ReferentType, |
| 568 | bool LValue, |
| 569 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 571 | /// \brief Build a new member pointer type given the pointee type and the |
| 572 | /// class type it refers into. |
| 573 | /// |
| 574 | /// By default, performs semantic analysis when building the member pointer |
| 575 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 576 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 577 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 579 | /// \brief Build a new array type given the element type, size |
| 580 | /// modifier, size of the array (if known), size expression, and index type |
| 581 | /// qualifiers. |
| 582 | /// |
| 583 | /// By default, performs semantic analysis when building the array type. |
| 584 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 586 | QualType RebuildArrayType(QualType ElementType, |
| 587 | ArrayType::ArraySizeModifier SizeMod, |
| 588 | const llvm::APInt *Size, |
| 589 | Expr *SizeExpr, |
| 590 | unsigned IndexTypeQuals, |
| 591 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 592 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 593 | /// \brief Build a new constant array type given the element type, size |
| 594 | /// modifier, (known) size of the array, 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 RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 599 | ArrayType::ArraySizeModifier SizeMod, |
| 600 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 601 | unsigned IndexTypeQuals, |
| 602 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 604 | /// \brief Build a new incomplete array type given the element type, size |
| 605 | /// modifier, and index type qualifiers. |
| 606 | /// |
| 607 | /// By default, performs semantic analysis when building the array type. |
| 608 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 610 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 611 | unsigned IndexTypeQuals, |
| 612 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 613 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | /// \brief Build a new variable-length 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 RebuildVariableArrayType(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 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 626 | /// size modifier, size expression, and index type qualifiers. |
| 627 | /// |
| 628 | /// By default, performs semantic analysis when building the array type. |
| 629 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 631 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 632 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 633 | unsigned IndexTypeQuals, |
| 634 | SourceRange BracketsRange); |
| 635 | |
| 636 | /// \brief Build a new vector type given the element type and |
| 637 | /// number of elements. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the vector type. |
| 640 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 641 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 642 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | /// \brief Build a new extended vector type given the element type and |
| 645 | /// number of elements. |
| 646 | /// |
| 647 | /// By default, performs semantic analysis when building the vector type. |
| 648 | /// Subclasses may override this routine to provide different behavior. |
| 649 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 650 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | |
| 652 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 653 | /// given the element type and number of elements. |
| 654 | /// |
| 655 | /// By default, performs semantic analysis when building the vector type. |
| 656 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 658 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 659 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 661 | /// \brief Build a new function type. |
| 662 | /// |
| 663 | /// By default, performs semantic analysis when building the function type. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
| 665 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 667 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 668 | bool Variadic, unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 669 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 670 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 672 | /// \brief Build a new unprototyped function type. |
| 673 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 674 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 675 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 676 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 677 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 678 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 679 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 680 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 681 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 682 | } |
| 683 | |
| 684 | /// \brief Build a new class/struct/union type. |
| 685 | QualType RebuildRecordType(RecordDecl *Record) { |
| 686 | return SemaRef.Context.getTypeDeclType(Record); |
| 687 | } |
| 688 | |
| 689 | /// \brief Build a new Enum type. |
| 690 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 691 | return SemaRef.Context.getTypeDeclType(Enum); |
| 692 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 693 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | /// |
| 696 | /// By default, performs semantic analysis when building the typeof 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 RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 699 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 701 | /// |
| 702 | /// By default, builds a new TypeOfType with the given underlying type. |
| 703 | QualType RebuildTypeOfType(QualType Underlying); |
| 704 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 705 | /// \brief Build a new unary transform type. |
| 706 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 707 | UnaryTransformType::UTTKind UKind, |
| 708 | SourceLocation Loc); |
| 709 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 711 | /// |
| 712 | /// By default, performs semantic analysis when building the decltype type. |
| 713 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 714 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 716 | /// \brief Build a new C++0x auto type. |
| 717 | /// |
| 718 | /// By default, builds a new AutoType with the given deduced type. |
| 719 | QualType RebuildAutoType(QualType Deduced) { |
| 720 | return SemaRef.Context.getAutoType(Deduced); |
| 721 | } |
| 722 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 723 | /// \brief Build a new template specialization type. |
| 724 | /// |
| 725 | /// By default, performs semantic analysis when building the template |
| 726 | /// specialization type. Subclasses may override this routine to provide |
| 727 | /// different behavior. |
| 728 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 729 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 730 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 732 | /// \brief Build a new parenthesized type. |
| 733 | /// |
| 734 | /// By default, builds a new ParenType type from the inner type. |
| 735 | /// Subclasses may override this routine to provide different behavior. |
| 736 | QualType RebuildParenType(QualType InnerType) { |
| 737 | return SemaRef.Context.getParenType(InnerType); |
| 738 | } |
| 739 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 740 | /// \brief Build a new qualified name type. |
| 741 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 742 | /// By default, builds a new ElaboratedType type from the keyword, |
| 743 | /// the nested-name-specifier and the named type. |
| 744 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 745 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 746 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 747 | NestedNameSpecifierLoc QualifierLoc, |
| 748 | QualType Named) { |
| 749 | return SemaRef.Context.getElaboratedType(Keyword, |
| 750 | QualifierLoc.getNestedNameSpecifier(), |
| 751 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 753 | |
| 754 | /// \brief Build a new typename type that refers to a template-id. |
| 755 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 756 | /// By default, builds a new DependentNameType type from the |
| 757 | /// nested-name-specifier and the given type. Subclasses may override |
| 758 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 759 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 760 | ElaboratedTypeKeyword Keyword, |
| 761 | NestedNameSpecifierLoc QualifierLoc, |
| 762 | const IdentifierInfo *Name, |
| 763 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 764 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 765 | // Rebuild the template name. |
| 766 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 767 | CXXScopeSpec SS; |
| 768 | SS.Adopt(QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 769 | TemplateName InstName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 770 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 771 | |
| 772 | if (InstName.isNull()) |
| 773 | return QualType(); |
| 774 | |
| 775 | // If it's still dependent, make a dependent specialization. |
| 776 | if (InstName.getAsDependentTemplateName()) |
| 777 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 778 | QualifierLoc.getNestedNameSpecifier(), |
| 779 | Name, |
| 780 | Args); |
| 781 | |
| 782 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 783 | // specialization. |
| 784 | QualType T = |
| 785 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 786 | if (T.isNull()) return QualType(); |
| 787 | |
| 788 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 789 | return T; |
| 790 | |
| 791 | return SemaRef.Context.getElaboratedType(Keyword, |
| 792 | QualifierLoc.getNestedNameSpecifier(), |
| 793 | T); |
| 794 | } |
| 795 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 796 | /// \brief Build a new typename type that refers to an identifier. |
| 797 | /// |
| 798 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 799 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 800 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 801 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 802 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 803 | NestedNameSpecifierLoc QualifierLoc, |
| 804 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 805 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 806 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 807 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 808 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 809 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 810 | // If the name is still dependent, just build a new dependent name type. |
| 811 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 812 | return SemaRef.Context.getDependentNameType(Keyword, |
| 813 | QualifierLoc.getNestedNameSpecifier(), |
| 814 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 817 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 818 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 819 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 820 | |
| 821 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 822 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 823 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 824 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 825 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 826 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 827 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 828 | if (!DC) |
| 829 | return QualType(); |
| 830 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 831 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 832 | return QualType(); |
| 833 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 834 | TagDecl *Tag = 0; |
| 835 | SemaRef.LookupQualifiedName(Result, DC); |
| 836 | switch (Result.getResultKind()) { |
| 837 | case LookupResult::NotFound: |
| 838 | case LookupResult::NotFoundInCurrentInstantiation: |
| 839 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 840 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 841 | case LookupResult::Found: |
| 842 | Tag = Result.getAsSingle<TagDecl>(); |
| 843 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 844 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 845 | case LookupResult::FoundOverloaded: |
| 846 | case LookupResult::FoundUnresolvedValue: |
| 847 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 848 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 849 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 850 | case LookupResult::Ambiguous: |
| 851 | // Let the LookupResult structure handle ambiguities. |
| 852 | return QualType(); |
| 853 | } |
| 854 | |
| 855 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 856 | // Check where the name exists but isn't a tag type and use that to emit |
| 857 | // better diagnostics. |
| 858 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 859 | SemaRef.LookupQualifiedName(Result, DC); |
| 860 | switch (Result.getResultKind()) { |
| 861 | case LookupResult::Found: |
| 862 | case LookupResult::FoundOverloaded: |
| 863 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 864 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 865 | unsigned Kind = 0; |
| 866 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 867 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 868 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 869 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 870 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 871 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 872 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 873 | default: |
| 874 | // FIXME: Would be nice to highlight just the source range. |
| 875 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 876 | << Kind << Id << DC; |
| 877 | break; |
| 878 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 879 | return QualType(); |
| 880 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 881 | |
Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 882 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 883 | IdLoc, *Id)) { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 884 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 885 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 886 | return QualType(); |
| 887 | } |
| 888 | |
| 889 | // Build the elaborated-type-specifier type. |
| 890 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 891 | return SemaRef.Context.getElaboratedType(Keyword, |
| 892 | QualifierLoc.getNestedNameSpecifier(), |
| 893 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 896 | /// \brief Build a new pack expansion type. |
| 897 | /// |
| 898 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 899 | /// Subclasses may override this routine to provide different behavior. |
| 900 | QualType RebuildPackExpansionType(QualType Pattern, |
| 901 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 902 | SourceLocation EllipsisLoc, |
| 903 | llvm::Optional<unsigned> NumExpansions) { |
| 904 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 905 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 908 | /// \brief Build a new template name given a nested name specifier, a flag |
| 909 | /// indicating whether the "template" keyword was provided, and the template |
| 910 | /// that the template name refers to. |
| 911 | /// |
| 912 | /// By default, builds the new template name directly. Subclasses may override |
| 913 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 914 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 915 | bool TemplateKW, |
| 916 | TemplateDecl *Template); |
| 917 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 918 | /// \brief Build a new template name given a nested name specifier and the |
| 919 | /// name that is referred to as a template. |
| 920 | /// |
| 921 | /// By default, performs semantic analysis to determine whether the name can |
| 922 | /// be resolved to a specific template, then builds the appropriate kind of |
| 923 | /// template name. Subclasses may override this routine to provide different |
| 924 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 925 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 926 | const IdentifierInfo &Name, |
| 927 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 928 | QualType ObjectType, |
| 929 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 931 | /// \brief Build a new template name given a nested name specifier and the |
| 932 | /// overloaded operator name that is referred to as a template. |
| 933 | /// |
| 934 | /// By default, performs semantic analysis to determine whether the name can |
| 935 | /// be resolved to a specific template, then builds the appropriate kind of |
| 936 | /// template name. Subclasses may override this routine to provide different |
| 937 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 938 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 939 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 940 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 941 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 942 | |
| 943 | /// \brief Build a new template name given a template template parameter pack |
| 944 | /// and the |
| 945 | /// |
| 946 | /// By default, performs semantic analysis to determine whether the name can |
| 947 | /// be resolved to a specific template, then builds the appropriate kind of |
| 948 | /// template name. Subclasses may override this routine to provide different |
| 949 | /// behavior. |
| 950 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 951 | const TemplateArgument &ArgPack) { |
| 952 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 953 | } |
| 954 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 955 | /// \brief Build a new compound statement. |
| 956 | /// |
| 957 | /// By default, performs semantic analysis to build the new statement. |
| 958 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 959 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 960 | MultiStmtArg Statements, |
| 961 | SourceLocation RBraceLoc, |
| 962 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 963 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 964 | IsStmtExpr); |
| 965 | } |
| 966 | |
| 967 | /// \brief Build a new case statement. |
| 968 | /// |
| 969 | /// By default, performs semantic analysis to build the new statement. |
| 970 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 971 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 972 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 973 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 974 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 975 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 976 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 977 | ColonLoc); |
| 978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 979 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 980 | /// \brief Attach the body to a new case statement. |
| 981 | /// |
| 982 | /// By default, performs semantic analysis to build the new statement. |
| 983 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 984 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 985 | getSema().ActOnCaseStmtBody(S, Body); |
| 986 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 989 | /// \brief Build a new default statement. |
| 990 | /// |
| 991 | /// By default, performs semantic analysis to build the new statement. |
| 992 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 993 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 994 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 995 | Stmt *SubStmt) { |
| 996 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 997 | /*CurScope=*/0); |
| 998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 999 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1000 | /// \brief Build a new label statement. |
| 1001 | /// |
| 1002 | /// By default, performs semantic analysis to build the new statement. |
| 1003 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1004 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1005 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1006 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1007 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1009 | /// \brief Build a new "if" statement. |
| 1010 | /// |
| 1011 | /// By default, performs semantic analysis to build the new statement. |
| 1012 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1013 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1014 | VarDecl *CondVar, Stmt *Then, |
| 1015 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1016 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1017 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1018 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1019 | /// \brief Start building a new switch statement. |
| 1020 | /// |
| 1021 | /// By default, performs semantic analysis to build the new statement. |
| 1022 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1023 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1024 | Expr *Cond, VarDecl *CondVar) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1025 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1026 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1029 | /// \brief Attach the body to the switch 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 RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1034 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1035 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /// \brief Build a new while statement. |
| 1039 | /// |
| 1040 | /// By default, performs semantic analysis to build the new statement. |
| 1041 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1042 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1043 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1044 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1047 | /// \brief Build a new do-while statement. |
| 1048 | /// |
| 1049 | /// By default, performs semantic analysis to build the new statement. |
| 1050 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1051 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1052 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1053 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1054 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1055 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /// \brief Build a new for statement. |
| 1059 | /// |
| 1060 | /// By default, performs semantic analysis to build the new statement. |
| 1061 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1062 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1063 | Stmt *Init, Sema::FullExprArg Cond, |
| 1064 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1065 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1066 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1067 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1070 | /// \brief Build a new goto statement. |
| 1071 | /// |
| 1072 | /// By default, performs semantic analysis to build the new statement. |
| 1073 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1074 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1075 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1076 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /// \brief Build a new indirect goto statement. |
| 1080 | /// |
| 1081 | /// By default, performs semantic analysis to build the new statement. |
| 1082 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1083 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1084 | SourceLocation StarLoc, |
| 1085 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1086 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1087 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | /// \brief Build a new return statement. |
| 1090 | /// |
| 1091 | /// By default, performs semantic analysis to build the new statement. |
| 1092 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1093 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1094 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1095 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1097 | /// \brief Build a new declaration statement. |
| 1098 | /// |
| 1099 | /// By default, performs semantic analysis to build the new statement. |
| 1100 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1101 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1103 | SourceLocation EndLoc) { |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1104 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1105 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1106 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1108 | /// \brief Build a new inline asm statement. |
| 1109 | /// |
| 1110 | /// By default, performs semantic analysis to build the new statement. |
| 1111 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1112 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1113 | bool IsSimple, |
| 1114 | bool IsVolatile, |
| 1115 | unsigned NumOutputs, |
| 1116 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1117 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1118 | MultiExprArg Constraints, |
| 1119 | MultiExprArg Exprs, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1120 | Expr *AsmString, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1121 | MultiExprArg Clobbers, |
| 1122 | SourceLocation RParenLoc, |
| 1123 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1124 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1125 | NumInputs, Names, move(Constraints), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1126 | Exprs, AsmString, Clobbers, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1127 | RParenLoc, MSAsm); |
| 1128 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1129 | |
| 1130 | /// \brief Build a new Objective-C @try statement. |
| 1131 | /// |
| 1132 | /// By default, performs semantic analysis to build the new statement. |
| 1133 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1134 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1135 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1136 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1137 | Stmt *Finally) { |
| 1138 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1139 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1142 | /// \brief Rebuild an Objective-C exception declaration. |
| 1143 | /// |
| 1144 | /// By default, performs semantic analysis to build the new declaration. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
| 1146 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1147 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1148 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1149 | ExceptionDecl->getInnerLocStart(), |
| 1150 | ExceptionDecl->getLocation(), |
| 1151 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1152 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1154 | /// \brief Build a new Objective-C @catch statement. |
| 1155 | /// |
| 1156 | /// By default, performs semantic analysis to build the new statement. |
| 1157 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1158 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1159 | SourceLocation RParenLoc, |
| 1160 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1161 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1162 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1163 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1164 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1165 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1166 | /// \brief Build a new Objective-C @finally statement. |
| 1167 | /// |
| 1168 | /// By default, performs semantic analysis to build the new statement. |
| 1169 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1170 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1171 | Stmt *Body) { |
| 1172 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1173 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1174 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1175 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1176 | /// |
| 1177 | /// By default, performs semantic analysis to build the new statement. |
| 1178 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1179 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1180 | Expr *Operand) { |
| 1181 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1182 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1183 | |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1184 | /// \brief Rebuild the operand to an Objective-C @synchronized statement. |
| 1185 | /// |
| 1186 | /// By default, performs semantic analysis to build the new statement. |
| 1187 | /// Subclasses may override this routine to provide different behavior. |
| 1188 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1189 | Expr *object) { |
| 1190 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1191 | } |
| 1192 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1193 | /// \brief Build a new Objective-C @synchronized statement. |
| 1194 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1195 | /// By default, performs semantic analysis to build the new statement. |
| 1196 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1197 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1198 | Expr *Object, Stmt *Body) { |
| 1199 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1200 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1201 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1202 | /// \brief Build a new Objective-C @autoreleasepool statement. |
| 1203 | /// |
| 1204 | /// By default, performs semantic analysis to build the new statement. |
| 1205 | /// Subclasses may override this routine to provide different behavior. |
| 1206 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1207 | Stmt *Body) { |
| 1208 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1209 | } |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1210 | |
| 1211 | /// \brief Build the collection operand to a new Objective-C fast |
| 1212 | /// enumeration statement. |
| 1213 | /// |
| 1214 | /// By default, performs semantic analysis to build the new statement. |
| 1215 | /// Subclasses may override this routine to provide different behavior. |
| 1216 | ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc, |
| 1217 | Expr *collection) { |
| 1218 | return getSema().ActOnObjCForCollectionOperand(forLoc, collection); |
| 1219 | } |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1221 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1222 | /// |
| 1223 | /// By default, performs semantic analysis to build the new statement. |
| 1224 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1225 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1226 | SourceLocation LParenLoc, |
| 1227 | Stmt *Element, |
| 1228 | Expr *Collection, |
| 1229 | SourceLocation RParenLoc, |
| 1230 | Stmt *Body) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1231 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1232 | Element, |
| 1233 | Collection, |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1234 | RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1235 | Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1236 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1238 | /// \brief Build a new C++ exception declaration. |
| 1239 | /// |
| 1240 | /// By default, performs semantic analysis to build the new decaration. |
| 1241 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1242 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1243 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1244 | SourceLocation StartLoc, |
| 1245 | SourceLocation IdLoc, |
| 1246 | IdentifierInfo *Id) { |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1247 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1248 | StartLoc, IdLoc, Id); |
| 1249 | if (Var) |
| 1250 | getSema().CurContext->addDecl(Var); |
| 1251 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | /// \brief Build a new C++ catch statement. |
| 1255 | /// |
| 1256 | /// By default, performs semantic analysis to build the new statement. |
| 1257 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1258 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1259 | VarDecl *ExceptionDecl, |
| 1260 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1261 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1262 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1265 | /// \brief Build a new C++ try statement. |
| 1266 | /// |
| 1267 | /// By default, performs semantic analysis to build the new statement. |
| 1268 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1269 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1270 | Stmt *TryBlock, |
| 1271 | MultiStmtArg Handlers) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1272 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1274 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1275 | /// \brief Build a new C++0x range-based for statement. |
| 1276 | /// |
| 1277 | /// By default, performs semantic analysis to build the new statement. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
| 1279 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1280 | SourceLocation ColonLoc, |
| 1281 | Stmt *Range, Stmt *BeginEnd, |
| 1282 | Expr *Cond, Expr *Inc, |
| 1283 | Stmt *LoopVar, |
| 1284 | SourceLocation RParenLoc) { |
| 1285 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
| 1286 | Cond, Inc, LoopVar, RParenLoc); |
| 1287 | } |
| 1288 | |
| 1289 | /// \brief Attach body to a C++0x range-based for statement. |
| 1290 | /// |
| 1291 | /// By default, performs semantic analysis to finish the new statement. |
| 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1294 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1295 | } |
| 1296 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1297 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1298 | SourceLocation TryLoc, |
| 1299 | Stmt *TryBlock, |
| 1300 | Stmt *Handler) { |
| 1301 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1302 | } |
| 1303 | |
| 1304 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1305 | Expr *FilterExpr, |
| 1306 | Stmt *Block) { |
| 1307 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1308 | } |
| 1309 | |
| 1310 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1311 | Stmt *Block) { |
| 1312 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1313 | } |
| 1314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | /// \brief Build a new expression that references a declaration. |
| 1316 | /// |
| 1317 | /// By default, performs semantic analysis to build the new expression. |
| 1318 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1319 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1320 | LookupResult &R, |
| 1321 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1322 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | /// \brief Build a new expression that references a declaration. |
| 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new expression. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1330 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1331 | ValueDecl *VD, |
| 1332 | const DeclarationNameInfo &NameInfo, |
| 1333 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1334 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1335 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1336 | |
| 1337 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1338 | |
| 1339 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | /// By default, performs semantic analysis to build the new expression. |
| 1345 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1346 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1348 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1351 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1353 | /// By default, performs semantic analysis to build the new expression. |
| 1354 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1355 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1356 | SourceLocation OperatorLoc, |
| 1357 | bool isArrow, |
| 1358 | CXXScopeSpec &SS, |
| 1359 | TypeSourceInfo *ScopeType, |
| 1360 | SourceLocation CCLoc, |
| 1361 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1362 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1363 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1364 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1365 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1369 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1370 | Expr *SubExpr) { |
| 1371 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1374 | /// \brief Build a new builtin offsetof expression. |
| 1375 | /// |
| 1376 | /// By default, performs semantic analysis to build the new expression. |
| 1377 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1378 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1379 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1380 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1381 | unsigned NumComponents, |
| 1382 | SourceLocation RParenLoc) { |
| 1383 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1384 | NumComponents, RParenLoc); |
| 1385 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1386 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1387 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
| 1388 | /// type 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. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1392 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1393 | SourceLocation OpLoc, |
| 1394 | UnaryExprOrTypeTrait ExprKind, |
| 1395 | SourceRange R) { |
| 1396 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1399 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1400 | /// expression argument. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1403 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1404 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1405 | UnaryExprOrTypeTrait ExprKind, |
| 1406 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1407 | ExprResult Result |
Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 1408 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1410 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | return move(Result); |
| 1413 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | /// \brief Build a new array subscript 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 RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1420 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1421 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1422 | SourceLocation RBracketLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1423 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1424 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | RBracketLoc); |
| 1426 | } |
| 1427 | |
| 1428 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | /// By default, performs semantic analysis to build the new expression. |
| 1431 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1432 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1433 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1434 | SourceLocation RParenLoc, |
| 1435 | Expr *ExecConfig = 0) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1436 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1437 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1441 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1442 | /// By default, performs semantic analysis to build the new expression. |
| 1443 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1444 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1445 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1446 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1447 | const DeclarationNameInfo &MemberNameInfo, |
| 1448 | ValueDecl *Member, |
| 1449 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1450 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1451 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1452 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1453 | // We have a reference to an unnamed field. This is always the |
| 1454 | // base of an anonymous struct/union member access, i.e. the |
| 1455 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1456 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1457 | assert(Member->getType()->isRecordType() && |
| 1458 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1459 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1460 | ExprResult BaseResult = |
| 1461 | getSema().PerformObjectMemberConversion(Base, |
| 1462 | QualifierLoc.getNestedNameSpecifier(), |
| 1463 | FoundDecl, Member); |
| 1464 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1465 | return ExprError(); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1466 | Base = BaseResult.take(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1467 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1468 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1469 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1470 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1471 | cast<FieldDecl>(Member)->getType(), |
| 1472 | VK, OK_Ordinary); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1473 | return getSema().Owned(ME); |
| 1474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1475 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1476 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1477 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1478 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1479 | ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base); |
| 1480 | if (BaseResult.isInvalid()) |
| 1481 | return ExprError(); |
| 1482 | Base = BaseResult.take(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1483 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1484 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1485 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1486 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1487 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1488 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1489 | R.resolveKind(); |
| 1490 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1491 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1492 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1493 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1494 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | /// By default, performs semantic analysis to build the new expression. |
| 1499 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1500 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1501 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1502 | Expr *LHS, Expr *RHS) { |
| 1503 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1507 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1508 | /// By default, performs semantic analysis to build the new expression. |
| 1509 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1510 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1511 | SourceLocation QuestionLoc, |
| 1512 | Expr *LHS, |
| 1513 | SourceLocation ColonLoc, |
| 1514 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1515 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1516 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1519 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1520 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | /// By default, performs semantic analysis to build the new expression. |
| 1522 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1523 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1524 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1526 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1527 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1528 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1530 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1532 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | /// By default, performs semantic analysis to build the new expression. |
| 1534 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1535 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1536 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1538 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1539 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1540 | Init); |
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 extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | SourceLocation OpLoc, |
| 1549 | SourceLocation AccessorLoc, |
| 1550 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1551 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1552 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1553 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1554 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1555 | OpLoc, /*IsArrow*/ false, |
| 1556 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1557 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1558 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | /// \brief Build a new initializer list expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1565 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 1566 | MultiExprArg Inits, |
| 1567 | SourceLocation RBraceLoc, |
| 1568 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1569 | ExprResult Result |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1570 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1571 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1572 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1573 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1574 | // Patch in the result type we were given, which may have been computed |
| 1575 | // when the initial InitListExpr was built. |
| 1576 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1577 | ILE->setType(ResultTy); |
| 1578 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1580 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1581 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | /// By default, performs semantic analysis to build the new expression. |
| 1584 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1585 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1586 | MultiExprArg ArrayExprs, |
| 1587 | SourceLocation EqualOrColonLoc, |
| 1588 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1589 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1590 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1592 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1594 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1595 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1596 | ArrayExprs.release(); |
| 1597 | return move(Result); |
| 1598 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1602 | /// By default, builds the implicit value initialization without performing |
| 1603 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1604 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1605 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1607 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1608 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1609 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | /// By default, performs semantic analysis to build the new expression. |
| 1612 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1613 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1614 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1615 | SourceLocation RParenLoc) { |
| 1616 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1617 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1618 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1622 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1623 | /// By default, performs semantic analysis to build the new expression. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1625 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | MultiExprArg SubExprs, |
| 1627 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1628 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1629 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1632 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | /// |
| 1634 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | /// rather than attempting to map the label statement itself. |
| 1636 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1637 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1638 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1639 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1642 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | /// By default, performs semantic analysis to build the new expression. |
| 1645 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1646 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1647 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1649 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | /// \brief Build a new __builtin_choose_expr expression. |
| 1653 | /// |
| 1654 | /// By default, performs semantic analysis to build the new expression. |
| 1655 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1656 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1657 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | SourceLocation RParenLoc) { |
| 1659 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1660 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | RParenLoc); |
| 1662 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1663 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1664 | /// \brief Build a new generic selection expression. |
| 1665 | /// |
| 1666 | /// By default, performs semantic analysis to build the new expression. |
| 1667 | /// Subclasses may override this routine to provide different behavior. |
| 1668 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1669 | SourceLocation DefaultLoc, |
| 1670 | SourceLocation RParenLoc, |
| 1671 | Expr *ControllingExpr, |
| 1672 | TypeSourceInfo **Types, |
| 1673 | Expr **Exprs, |
| 1674 | unsigned NumAssocs) { |
| 1675 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 1676 | ControllingExpr, Types, Exprs, |
| 1677 | NumAssocs); |
| 1678 | } |
| 1679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1680 | /// \brief Build a new overloaded operator call expression. |
| 1681 | /// |
| 1682 | /// By default, performs semantic analysis to build the new expression. |
| 1683 | /// The semantic analysis provides the behavior of template instantiation, |
| 1684 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1687 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1688 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1690 | Expr *Callee, |
| 1691 | Expr *First, |
| 1692 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
| 1694 | /// \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] | 1695 | /// reinterpret_cast. |
| 1696 | /// |
| 1697 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1698 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1699 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1700 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | Stmt::StmtClass Class, |
| 1702 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1703 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | SourceLocation RAngleLoc, |
| 1705 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1706 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1707 | SourceLocation RParenLoc) { |
| 1708 | switch (Class) { |
| 1709 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1710 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1712 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1713 | |
| 1714 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1715 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1717 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1719 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1720 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1722 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1724 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1725 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1726 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1728 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | default: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1731 | llvm_unreachable("Invalid C++ named cast"); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1734 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1737 | /// \brief Build a new C++ static_cast expression. |
| 1738 | /// |
| 1739 | /// By default, performs semantic analysis to build the new expression. |
| 1740 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1741 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1743 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | SourceLocation RAngleLoc, |
| 1745 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1746 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1747 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1748 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1749 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1750 | SourceRange(LAngleLoc, RAngleLoc), |
| 1751 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | /// \brief Build a new C++ dynamic_cast expression. |
| 1755 | /// |
| 1756 | /// By default, performs semantic analysis to build the new expression. |
| 1757 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1758 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1760 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1761 | SourceLocation RAngleLoc, |
| 1762 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1763 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1765 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1766 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1767 | SourceRange(LAngleLoc, RAngleLoc), |
| 1768 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1772 | /// |
| 1773 | /// By default, performs semantic analysis to build the new expression. |
| 1774 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1775 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1776 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1777 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1778 | SourceLocation RAngleLoc, |
| 1779 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1780 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1782 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1783 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1784 | SourceRange(LAngleLoc, RAngleLoc), |
| 1785 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /// \brief Build a new C++ const_cast expression. |
| 1789 | /// |
| 1790 | /// By default, performs semantic analysis to build the new expression. |
| 1791 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1792 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1793 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1794 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | SourceLocation RAngleLoc, |
| 1796 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1797 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1798 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1799 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1800 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1801 | SourceRange(LAngleLoc, RAngleLoc), |
| 1802 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1805 | /// \brief Build a new C++ functional-style cast expression. |
| 1806 | /// |
| 1807 | /// By default, performs semantic analysis to build the new expression. |
| 1808 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1809 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1810 | SourceLocation LParenLoc, |
| 1811 | Expr *Sub, |
| 1812 | SourceLocation RParenLoc) { |
| 1813 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1814 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1815 | RParenLoc); |
| 1816 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1817 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1818 | /// \brief Build a new C++ typeid(type) expression. |
| 1819 | /// |
| 1820 | /// By default, performs semantic analysis to build the new expression. |
| 1821 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1822 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1823 | SourceLocation TypeidLoc, |
| 1824 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1825 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1826 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1827 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1828 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1831 | /// \brief Build a new C++ typeid(expr) expression. |
| 1832 | /// |
| 1833 | /// By default, performs semantic analysis to build the new expression. |
| 1834 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1835 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1836 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1837 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1838 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1839 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1840 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1843 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1844 | /// |
| 1845 | /// By default, performs semantic analysis to build the new expression. |
| 1846 | /// Subclasses may override this routine to provide different behavior. |
| 1847 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1848 | SourceLocation TypeidLoc, |
| 1849 | TypeSourceInfo *Operand, |
| 1850 | SourceLocation RParenLoc) { |
| 1851 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1852 | RParenLoc); |
| 1853 | } |
| 1854 | |
| 1855 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1856 | /// |
| 1857 | /// By default, performs semantic analysis to build the new expression. |
| 1858 | /// Subclasses may override this routine to provide different behavior. |
| 1859 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1860 | SourceLocation TypeidLoc, |
| 1861 | Expr *Operand, |
| 1862 | SourceLocation RParenLoc) { |
| 1863 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1864 | RParenLoc); |
| 1865 | } |
| 1866 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1867 | /// \brief Build a new C++ "this" expression. |
| 1868 | /// |
| 1869 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1871 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1872 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1873 | QualType ThisType, |
| 1874 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1875 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1876 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1877 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | /// \brief Build a new C++ throw expression. |
| 1881 | /// |
| 1882 | /// By default, performs semantic analysis to build the new expression. |
| 1883 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1884 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 1885 | bool IsThrownVariableInScope) { |
| 1886 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | /// \brief Build a new C++ default-argument expression. |
| 1890 | /// |
| 1891 | /// By default, builds a new default-argument expression, which does not |
| 1892 | /// require any semantic analysis. Subclasses may override this routine to |
| 1893 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1894 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1895 | ParmVarDecl *Param) { |
| 1896 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1897 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | /// \brief Build a new C++ zero-initialization expression. |
| 1901 | /// |
| 1902 | /// By default, performs semantic analysis to build the new expression. |
| 1903 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1904 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1905 | SourceLocation LParenLoc, |
| 1906 | SourceLocation RParenLoc) { |
| 1907 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1909 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1910 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1912 | /// \brief Build a new C++ "new" expression. |
| 1913 | /// |
| 1914 | /// By default, performs semantic analysis to build the new expression. |
| 1915 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1916 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1917 | bool UseGlobal, |
| 1918 | SourceLocation PlacementLParen, |
| 1919 | MultiExprArg PlacementArgs, |
| 1920 | SourceLocation PlacementRParen, |
| 1921 | SourceRange TypeIdParens, |
| 1922 | QualType AllocatedType, |
| 1923 | TypeSourceInfo *AllocatedTypeInfo, |
| 1924 | Expr *ArraySize, |
| 1925 | SourceLocation ConstructorLParen, |
| 1926 | MultiExprArg ConstructorArgs, |
| 1927 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1928 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1929 | PlacementLParen, |
| 1930 | move(PlacementArgs), |
| 1931 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1932 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1933 | AllocatedType, |
| 1934 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1935 | ArraySize, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1936 | ConstructorLParen, |
| 1937 | move(ConstructorArgs), |
| 1938 | ConstructorRParen); |
| 1939 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | /// \brief Build a new C++ "delete" expression. |
| 1942 | /// |
| 1943 | /// By default, performs semantic analysis to build the new expression. |
| 1944 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1945 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1946 | bool IsGlobalDelete, |
| 1947 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1948 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1950 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1951 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1952 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1953 | /// \brief Build a new unary type trait expression. |
| 1954 | /// |
| 1955 | /// By default, performs semantic analysis to build the new expression. |
| 1956 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1957 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1958 | SourceLocation StartLoc, |
| 1959 | TypeSourceInfo *T, |
| 1960 | SourceLocation RParenLoc) { |
| 1961 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1964 | /// \brief Build a new binary type trait expression. |
| 1965 | /// |
| 1966 | /// By default, performs semantic analysis to build the new expression. |
| 1967 | /// Subclasses may override this routine to provide different behavior. |
| 1968 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1969 | SourceLocation StartLoc, |
| 1970 | TypeSourceInfo *LhsT, |
| 1971 | TypeSourceInfo *RhsT, |
| 1972 | SourceLocation RParenLoc) { |
| 1973 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1974 | } |
| 1975 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 1976 | /// \brief Build a new array type trait expression. |
| 1977 | /// |
| 1978 | /// By default, performs semantic analysis to build the new expression. |
| 1979 | /// Subclasses may override this routine to provide different behavior. |
| 1980 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 1981 | SourceLocation StartLoc, |
| 1982 | TypeSourceInfo *TSInfo, |
| 1983 | Expr *DimExpr, |
| 1984 | SourceLocation RParenLoc) { |
| 1985 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 1986 | } |
| 1987 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 1988 | /// \brief Build a new expression trait expression. |
| 1989 | /// |
| 1990 | /// By default, performs semantic analysis to build the new expression. |
| 1991 | /// Subclasses may override this routine to provide different behavior. |
| 1992 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 1993 | SourceLocation StartLoc, |
| 1994 | Expr *Queried, |
| 1995 | SourceLocation RParenLoc) { |
| 1996 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 1997 | } |
| 1998 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2000 | /// expression. |
| 2001 | /// |
| 2002 | /// By default, performs semantic analysis to build the new expression. |
| 2003 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2004 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2005 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2006 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2007 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2008 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2009 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2010 | |
| 2011 | if (TemplateArgs) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2012 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2013 | *TemplateArgs); |
| 2014 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2015 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | /// \brief Build a new template-id expression. |
| 2019 | /// |
| 2020 | /// By default, performs semantic analysis to build the new expression. |
| 2021 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2022 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2023 | LookupResult &R, |
| 2024 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2025 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2026 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | /// \brief Build a new object-construction expression. |
| 2030 | /// |
| 2031 | /// By default, performs semantic analysis to build the new expression. |
| 2032 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2033 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2034 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2035 | CXXConstructorDecl *Constructor, |
| 2036 | bool IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 2037 | MultiExprArg Args, |
| 2038 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2039 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 2040 | SourceRange ParenRange) { |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 2041 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2042 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2043 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2044 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2045 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2046 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 2047 | move_arg(ConvertedArgs), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2048 | RequiresZeroInit, ConstructKind, |
| 2049 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | /// \brief Build a new object-construction expression. |
| 2053 | /// |
| 2054 | /// By default, performs semantic analysis to build the new expression. |
| 2055 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2056 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2057 | SourceLocation LParenLoc, |
| 2058 | MultiExprArg Args, |
| 2059 | SourceLocation RParenLoc) { |
| 2060 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2061 | LParenLoc, |
| 2062 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2063 | RParenLoc); |
| 2064 | } |
| 2065 | |
| 2066 | /// \brief Build a new object-construction expression. |
| 2067 | /// |
| 2068 | /// By default, performs semantic analysis to build the new expression. |
| 2069 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2070 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2071 | SourceLocation LParenLoc, |
| 2072 | MultiExprArg Args, |
| 2073 | SourceLocation RParenLoc) { |
| 2074 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2075 | LParenLoc, |
| 2076 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2077 | RParenLoc); |
| 2078 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2079 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2080 | /// \brief Build a new member reference expression. |
| 2081 | /// |
| 2082 | /// By default, performs semantic analysis to build the new expression. |
| 2083 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2084 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2085 | QualType BaseType, |
| 2086 | bool IsArrow, |
| 2087 | SourceLocation OperatorLoc, |
| 2088 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2089 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2090 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2091 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2092 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2093 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2095 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2096 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2097 | SS, FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2098 | MemberNameInfo, |
| 2099 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2102 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2103 | /// |
| 2104 | /// By default, performs semantic analysis to build the new expression. |
| 2105 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2106 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2107 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2108 | SourceLocation OperatorLoc, |
| 2109 | bool IsArrow, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2110 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2111 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2112 | LookupResult &R, |
| 2113 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2114 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2115 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2116 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2117 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2118 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2119 | SS, FirstQualifierInScope, |
| 2120 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2121 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2122 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2123 | /// \brief Build a new noexcept expression. |
| 2124 | /// |
| 2125 | /// By default, performs semantic analysis to build the new expression. |
| 2126 | /// Subclasses may override this routine to provide different behavior. |
| 2127 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2128 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2129 | } |
| 2130 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2131 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2132 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2133 | SourceLocation PackLoc, |
| 2134 | SourceLocation RParenLoc, |
| 2135 | unsigned Length) { |
| 2136 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2137 | OperatorLoc, Pack, PackLoc, |
| 2138 | RParenLoc, Length); |
| 2139 | } |
| 2140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2141 | /// \brief Build a new Objective-C @encode expression. |
| 2142 | /// |
| 2143 | /// By default, performs semantic analysis to build the new expression. |
| 2144 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2145 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2146 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2147 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2148 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2149 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2150 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2151 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2152 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2153 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2154 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2155 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2156 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2157 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2158 | MultiExprArg Args, |
| 2159 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2160 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2161 | ReceiverTypeInfo->getType(), |
| 2162 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2163 | Sel, Method, LBracLoc, SelectorLoc, |
| 2164 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2168 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2169 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2170 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2171 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2172 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2173 | MultiExprArg Args, |
| 2174 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2175 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2176 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2177 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2178 | Sel, Method, LBracLoc, SelectorLoc, |
| 2179 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2182 | /// \brief Build a new Objective-C ivar reference expression. |
| 2183 | /// |
| 2184 | /// By default, performs semantic analysis to build the new expression. |
| 2185 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2186 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2187 | SourceLocation IvarLoc, |
| 2188 | bool IsArrow, bool IsFreeIvar) { |
| 2189 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2190 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2191 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2192 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2193 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2194 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2195 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2196 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2197 | false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2198 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2199 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2200 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2201 | if (Result.get()) |
| 2202 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2203 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2204 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2205 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2206 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2207 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2208 | /*TemplateArgs=*/0); |
| 2209 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2210 | |
| 2211 | /// \brief Build a new Objective-C property reference expression. |
| 2212 | /// |
| 2213 | /// By default, performs semantic analysis to build the new expression. |
| 2214 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2215 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2216 | ObjCPropertyDecl *Property, |
| 2217 | SourceLocation PropertyLoc) { |
| 2218 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2219 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2220 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2221 | Sema::LookupMemberName); |
| 2222 | bool IsArrow = false; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2223 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2224 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2225 | SS, 0, false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2226 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2227 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2228 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2229 | if (Result.get()) |
| 2230 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2231 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2232 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2233 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2234 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2235 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2236 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2237 | /*TemplateArgs=*/0); |
| 2238 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2239 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2240 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2241 | /// |
| 2242 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2243 | /// Subclasses may override this routine to provide different behavior. |
| 2244 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2245 | ObjCMethodDecl *Getter, |
| 2246 | ObjCMethodDecl *Setter, |
| 2247 | SourceLocation PropertyLoc) { |
| 2248 | // Since these expressions can only be value-dependent, we do not |
| 2249 | // need to perform semantic analysis again. |
| 2250 | return Owned( |
| 2251 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2252 | VK_LValue, OK_ObjCProperty, |
| 2253 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2256 | /// \brief Build a new Objective-C "isa" expression. |
| 2257 | /// |
| 2258 | /// By default, performs semantic analysis to build the new expression. |
| 2259 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2260 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2261 | bool IsArrow) { |
| 2262 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2263 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2264 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2265 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2266 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2267 | /*FIME:*/IsaLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2268 | SS, 0, false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2269 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2270 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2271 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2272 | if (Result.get()) |
| 2273 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2274 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2275 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2276 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2277 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2278 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2279 | /*TemplateArgs=*/0); |
| 2280 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2282 | /// \brief Build a new shuffle vector expression. |
| 2283 | /// |
| 2284 | /// By default, performs semantic analysis to build the new expression. |
| 2285 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2286 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2287 | MultiExprArg SubExprs, |
| 2288 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2289 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2291 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2292 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2293 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2294 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2295 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2296 | // Build a reference to the __builtin_shufflevector builtin |
| 2297 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2298 | ExprResult Callee |
| 2299 | = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
| 2300 | VK_LValue, BuiltinLoc)); |
| 2301 | Callee = SemaRef.UsualUnaryConversions(Callee.take()); |
| 2302 | if (Callee.isInvalid()) |
| 2303 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2304 | |
| 2305 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2306 | unsigned NumSubExprs = SubExprs.size(); |
| 2307 | Expr **Subs = (Expr **)SubExprs.release(); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2308 | ExprResult TheCall = SemaRef.Owned( |
| 2309 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2310 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2311 | Builtin->getCallResultType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2312 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2313 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2315 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2316 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2317 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2318 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2319 | /// \brief Build a new template argument pack expansion. |
| 2320 | /// |
| 2321 | /// By default, performs semantic analysis to build a new pack expansion |
| 2322 | /// for a template argument. Subclasses may override this routine to provide |
| 2323 | /// different behavior. |
| 2324 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2325 | SourceLocation EllipsisLoc, |
| 2326 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2327 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2328 | case TemplateArgument::Expression: { |
| 2329 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2330 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2331 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2332 | if (Result.isInvalid()) |
| 2333 | return TemplateArgumentLoc(); |
| 2334 | |
| 2335 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2336 | } |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2338 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2339 | return TemplateArgumentLoc(TemplateArgument( |
| 2340 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2341 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2342 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2343 | Pattern.getTemplateNameLoc(), |
| 2344 | EllipsisLoc); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2345 | |
| 2346 | case TemplateArgument::Null: |
| 2347 | case TemplateArgument::Integral: |
| 2348 | case TemplateArgument::Declaration: |
| 2349 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2350 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2351 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2352 | |
| 2353 | case TemplateArgument::Type: |
| 2354 | if (TypeSourceInfo *Expansion |
| 2355 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2356 | EllipsisLoc, |
| 2357 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2358 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2359 | Expansion); |
| 2360 | break; |
| 2361 | } |
| 2362 | |
| 2363 | return TemplateArgumentLoc(); |
| 2364 | } |
| 2365 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2366 | /// \brief Build a new expression pack expansion. |
| 2367 | /// |
| 2368 | /// By default, performs semantic analysis to build a new pack expansion |
| 2369 | /// for an expression. Subclasses may override this routine to provide |
| 2370 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2371 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2372 | llvm::Optional<unsigned> NumExpansions) { |
| 2373 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2376 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2377 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2378 | QualType ObjectType, |
| 2379 | NamedDecl *FirstQualifierInScope, |
| 2380 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2381 | |
| 2382 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2383 | QualType ObjectType, |
| 2384 | NamedDecl *FirstQualifierInScope, |
| 2385 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2386 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2387 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2388 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2389 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2390 | if (!S) |
| 2391 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2392 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2393 | switch (S->getStmtClass()) { |
| 2394 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2395 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2396 | // Transform individual statement nodes |
| 2397 | #define STMT(Node, Parent) \ |
| 2398 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2399 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2400 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2401 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2402 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2403 | // Transform expressions by calling TransformExpr. |
| 2404 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2405 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2406 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2407 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2408 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2409 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2410 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2411 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2412 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2413 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2417 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2418 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2419 | |
| 2420 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2421 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2422 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2423 | if (!E) |
| 2424 | return SemaRef.Owned(E); |
| 2425 | |
| 2426 | switch (E->getStmtClass()) { |
| 2427 | case Stmt::NoStmtClass: break; |
| 2428 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2429 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2430 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2431 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2432 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2433 | } |
| 2434 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2435 | return SemaRef.Owned(E); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | template<typename Derived> |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2439 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2440 | unsigned NumInputs, |
| 2441 | bool IsCall, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2442 | SmallVectorImpl<Expr *> &Outputs, |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2443 | bool *ArgChanged) { |
| 2444 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2445 | // If requested, drop call arguments that need to be dropped. |
| 2446 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2447 | if (ArgChanged) |
| 2448 | *ArgChanged = true; |
| 2449 | |
| 2450 | break; |
| 2451 | } |
| 2452 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2453 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2454 | Expr *Pattern = Expansion->getPattern(); |
| 2455 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2456 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2457 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2458 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2459 | |
| 2460 | // Determine whether the set of unexpanded parameter packs can and should |
| 2461 | // be expanded. |
| 2462 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2463 | bool RetainExpansion = false; |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2464 | llvm::Optional<unsigned> OrigNumExpansions |
| 2465 | = Expansion->getNumExpansions(); |
| 2466 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2467 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2468 | Pattern->getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 2469 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2470 | Expand, RetainExpansion, |
| 2471 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2472 | return true; |
| 2473 | |
| 2474 | if (!Expand) { |
| 2475 | // The transform has determined that we should perform a simple |
| 2476 | // transformation on the pack expansion, producing another pack |
| 2477 | // expansion. |
| 2478 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2479 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2480 | if (OutPattern.isInvalid()) |
| 2481 | return true; |
| 2482 | |
| 2483 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2484 | Expansion->getEllipsisLoc(), |
| 2485 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2486 | if (Out.isInvalid()) |
| 2487 | return true; |
| 2488 | |
| 2489 | if (ArgChanged) |
| 2490 | *ArgChanged = true; |
| 2491 | Outputs.push_back(Out.get()); |
| 2492 | continue; |
| 2493 | } |
John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2494 | |
| 2495 | // Record right away that the argument was changed. This needs |
| 2496 | // to happen even if the array expands to nothing. |
| 2497 | if (ArgChanged) *ArgChanged = true; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2498 | |
| 2499 | // The transform has determined that we should perform an elementwise |
| 2500 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2501 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2502 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2503 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2504 | if (Out.isInvalid()) |
| 2505 | return true; |
| 2506 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2507 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2508 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2509 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2510 | if (Out.isInvalid()) |
| 2511 | return true; |
| 2512 | } |
| 2513 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2514 | Outputs.push_back(Out.get()); |
| 2515 | } |
| 2516 | |
| 2517 | continue; |
| 2518 | } |
| 2519 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2520 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2521 | if (Result.isInvalid()) |
| 2522 | return true; |
| 2523 | |
| 2524 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2525 | *ArgChanged = true; |
| 2526 | |
| 2527 | Outputs.push_back(Result.get()); |
| 2528 | } |
| 2529 | |
| 2530 | return false; |
| 2531 | } |
| 2532 | |
| 2533 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2534 | NestedNameSpecifierLoc |
| 2535 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2536 | NestedNameSpecifierLoc NNS, |
| 2537 | QualType ObjectType, |
| 2538 | NamedDecl *FirstQualifierInScope) { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2539 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2540 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2541 | Qualifier = Qualifier.getPrefix()) |
| 2542 | Qualifiers.push_back(Qualifier); |
| 2543 | |
| 2544 | CXXScopeSpec SS; |
| 2545 | while (!Qualifiers.empty()) { |
| 2546 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2547 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2548 | |
| 2549 | switch (QNNS->getKind()) { |
| 2550 | case NestedNameSpecifier::Identifier: |
| 2551 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2552 | *QNNS->getAsIdentifier(), |
| 2553 | Q.getLocalBeginLoc(), |
| 2554 | Q.getLocalEndLoc(), |
| 2555 | ObjectType, false, SS, |
| 2556 | FirstQualifierInScope, false)) |
| 2557 | return NestedNameSpecifierLoc(); |
| 2558 | |
| 2559 | break; |
| 2560 | |
| 2561 | case NestedNameSpecifier::Namespace: { |
| 2562 | NamespaceDecl *NS |
| 2563 | = cast_or_null<NamespaceDecl>( |
| 2564 | getDerived().TransformDecl( |
| 2565 | Q.getLocalBeginLoc(), |
| 2566 | QNNS->getAsNamespace())); |
| 2567 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2568 | break; |
| 2569 | } |
| 2570 | |
| 2571 | case NestedNameSpecifier::NamespaceAlias: { |
| 2572 | NamespaceAliasDecl *Alias |
| 2573 | = cast_or_null<NamespaceAliasDecl>( |
| 2574 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2575 | QNNS->getAsNamespaceAlias())); |
| 2576 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2577 | Q.getLocalEndLoc()); |
| 2578 | break; |
| 2579 | } |
| 2580 | |
| 2581 | case NestedNameSpecifier::Global: |
| 2582 | // There is no meaningful transformation that one could perform on the |
| 2583 | // global scope. |
| 2584 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2585 | break; |
| 2586 | |
| 2587 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2588 | case NestedNameSpecifier::TypeSpec: { |
| 2589 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2590 | FirstQualifierInScope, SS); |
| 2591 | |
| 2592 | if (!TL) |
| 2593 | return NestedNameSpecifierLoc(); |
| 2594 | |
| 2595 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 2596 | (SemaRef.getLangOptions().CPlusPlus0x && |
| 2597 | TL.getType()->isEnumeralType())) { |
| 2598 | assert(!TL.getType().hasLocalQualifiers() && |
| 2599 | "Can't get cv-qualifiers here"); |
| 2600 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2601 | Q.getLocalEndLoc()); |
| 2602 | break; |
| 2603 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 2604 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2605 | // error because a previous error should have already been emitted. |
| 2606 | TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); |
| 2607 | if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { |
| 2608 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2609 | << TL.getType() << SS.getRange(); |
| 2610 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2611 | return NestedNameSpecifierLoc(); |
| 2612 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2613 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2614 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2615 | // 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] | 2616 | FirstQualifierInScope = 0; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2617 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2621 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2622 | !getDerived().AlwaysRebuild()) |
| 2623 | return NNS; |
| 2624 | |
| 2625 | // If we can re-use the source-location data from the original |
| 2626 | // nested-name-specifier, do so. |
| 2627 | if (SS.location_size() == NNS.getDataLength() && |
| 2628 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2629 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2630 | |
| 2631 | // Allocate new nested-name-specifier location information. |
| 2632 | return SS.getWithLocInContext(SemaRef.Context); |
| 2633 | } |
| 2634 | |
| 2635 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2636 | DeclarationNameInfo |
| 2637 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2638 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2639 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2640 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2641 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2642 | |
| 2643 | switch (Name.getNameKind()) { |
| 2644 | case DeclarationName::Identifier: |
| 2645 | case DeclarationName::ObjCZeroArgSelector: |
| 2646 | case DeclarationName::ObjCOneArgSelector: |
| 2647 | case DeclarationName::ObjCMultiArgSelector: |
| 2648 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2649 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2650 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2651 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2652 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2653 | case DeclarationName::CXXConstructorName: |
| 2654 | case DeclarationName::CXXDestructorName: |
| 2655 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2656 | TypeSourceInfo *NewTInfo; |
| 2657 | CanQualType NewCanTy; |
| 2658 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2659 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2660 | if (!NewTInfo) |
| 2661 | return DeclarationNameInfo(); |
| 2662 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2663 | } |
| 2664 | else { |
| 2665 | NewTInfo = 0; |
| 2666 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2667 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2668 | if (NewT.isNull()) |
| 2669 | return DeclarationNameInfo(); |
| 2670 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2672 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2673 | DeclarationName NewName |
| 2674 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2675 | NewCanTy); |
| 2676 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2677 | NewNameInfo.setName(NewName); |
| 2678 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2679 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2683 | llvm_unreachable("Unknown name kind."); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2688 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2689 | TemplateName Name, |
| 2690 | SourceLocation NameLoc, |
| 2691 | QualType ObjectType, |
| 2692 | NamedDecl *FirstQualifierInScope) { |
| 2693 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2694 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2695 | assert(Template && "qualified template name must refer to a template"); |
| 2696 | |
| 2697 | TemplateDecl *TransTemplate |
| 2698 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2699 | Template)); |
| 2700 | if (!TransTemplate) |
| 2701 | return TemplateName(); |
| 2702 | |
| 2703 | if (!getDerived().AlwaysRebuild() && |
| 2704 | SS.getScopeRep() == QTN->getQualifier() && |
| 2705 | TransTemplate == Template) |
| 2706 | return Name; |
| 2707 | |
| 2708 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2709 | TransTemplate); |
| 2710 | } |
| 2711 | |
| 2712 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2713 | if (SS.getScopeRep()) { |
| 2714 | // These apply to the scope specifier, not the template. |
| 2715 | ObjectType = QualType(); |
| 2716 | FirstQualifierInScope = 0; |
| 2717 | } |
| 2718 | |
| 2719 | if (!getDerived().AlwaysRebuild() && |
| 2720 | SS.getScopeRep() == DTN->getQualifier() && |
| 2721 | ObjectType.isNull()) |
| 2722 | return Name; |
| 2723 | |
| 2724 | if (DTN->isIdentifier()) { |
| 2725 | return getDerived().RebuildTemplateName(SS, |
| 2726 | *DTN->getIdentifier(), |
| 2727 | NameLoc, |
| 2728 | ObjectType, |
| 2729 | FirstQualifierInScope); |
| 2730 | } |
| 2731 | |
| 2732 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2733 | ObjectType); |
| 2734 | } |
| 2735 | |
| 2736 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2737 | TemplateDecl *TransTemplate |
| 2738 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2739 | Template)); |
| 2740 | if (!TransTemplate) |
| 2741 | return TemplateName(); |
| 2742 | |
| 2743 | if (!getDerived().AlwaysRebuild() && |
| 2744 | TransTemplate == Template) |
| 2745 | return Name; |
| 2746 | |
| 2747 | return TemplateName(TransTemplate); |
| 2748 | } |
| 2749 | |
| 2750 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2751 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2752 | TemplateTemplateParmDecl *TransParam |
| 2753 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2754 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2755 | if (!TransParam) |
| 2756 | return TemplateName(); |
| 2757 | |
| 2758 | if (!getDerived().AlwaysRebuild() && |
| 2759 | TransParam == SubstPack->getParameterPack()) |
| 2760 | return Name; |
| 2761 | |
| 2762 | return getDerived().RebuildTemplateName(TransParam, |
| 2763 | SubstPack->getArgumentPack()); |
| 2764 | } |
| 2765 | |
| 2766 | // These should be getting filtered out before they reach the AST. |
| 2767 | llvm_unreachable("overloaded function decl survived to here"); |
| 2768 | return TemplateName(); |
| 2769 | } |
| 2770 | |
| 2771 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2772 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2773 | const TemplateArgument &Arg, |
| 2774 | TemplateArgumentLoc &Output) { |
| 2775 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2776 | switch (Arg.getKind()) { |
| 2777 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2778 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2779 | break; |
| 2780 | |
| 2781 | case TemplateArgument::Type: |
| 2782 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2783 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2784 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2785 | break; |
| 2786 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2787 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2788 | case TemplateArgument::TemplateExpansion: { |
| 2789 | NestedNameSpecifierLocBuilder Builder; |
| 2790 | TemplateName Template = Arg.getAsTemplate(); |
| 2791 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 2792 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 2793 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 2794 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| 2795 | |
| 2796 | if (Arg.getKind() == TemplateArgument::Template) |
| 2797 | Output = TemplateArgumentLoc(Arg, |
| 2798 | Builder.getWithLocInContext(SemaRef.Context), |
| 2799 | Loc); |
| 2800 | else |
| 2801 | Output = TemplateArgumentLoc(Arg, |
| 2802 | Builder.getWithLocInContext(SemaRef.Context), |
| 2803 | Loc, Loc); |
| 2804 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2805 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2806 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2807 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2808 | case TemplateArgument::Expression: |
| 2809 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2810 | break; |
| 2811 | |
| 2812 | case TemplateArgument::Declaration: |
| 2813 | case TemplateArgument::Integral: |
| 2814 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2815 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2816 | break; |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | template<typename Derived> |
| 2821 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2822 | const TemplateArgumentLoc &Input, |
| 2823 | TemplateArgumentLoc &Output) { |
| 2824 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2825 | switch (Arg.getKind()) { |
| 2826 | case TemplateArgument::Null: |
| 2827 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2828 | Output = Input; |
| 2829 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2830 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2831 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2832 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2833 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2834 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2835 | |
| 2836 | DI = getDerived().TransformType(DI); |
| 2837 | if (!DI) return true; |
| 2838 | |
| 2839 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2840 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2842 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2843 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2844 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2845 | DeclarationName Name; |
| 2846 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2847 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2848 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2849 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2850 | if (!D) return true; |
| 2851 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2852 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2853 | if (SourceExpr) { |
| 2854 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2855 | Sema::Unevaluated); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2856 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2857 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2861 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2864 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2865 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 2866 | if (QualifierLoc) { |
| 2867 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 2868 | if (!QualifierLoc) |
| 2869 | return true; |
| 2870 | } |
| 2871 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2872 | CXXScopeSpec SS; |
| 2873 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2874 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2875 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 2876 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2877 | if (Template.isNull()) |
| 2878 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2879 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2880 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2881 | Input.getTemplateNameLoc()); |
| 2882 | return false; |
| 2883 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2884 | |
| 2885 | case TemplateArgument::TemplateExpansion: |
| 2886 | llvm_unreachable("Caller should expand pack expansions"); |
| 2887 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2888 | case TemplateArgument::Expression: { |
| 2889 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2890 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2891 | Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2892 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2893 | Expr *InputExpr = Input.getSourceExpression(); |
| 2894 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2895 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 2896 | ExprResult E = getDerived().TransformExpr(InputExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2897 | if (E.isInvalid()) return true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2898 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2899 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2901 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2902 | case TemplateArgument::Pack: { |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2903 | SmallVector<TemplateArgument, 4> TransformedArgs; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2904 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2905 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2906 | AEnd = Arg.pack_end(); |
| 2907 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2908 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2909 | // FIXME: preserve source information here when we start |
| 2910 | // caring about parameter packs. |
| 2911 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2912 | TemplateArgumentLoc InputArg; |
| 2913 | TemplateArgumentLoc OutputArg; |
| 2914 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2915 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2916 | return true; |
| 2917 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2918 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2919 | } |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2920 | |
| 2921 | TemplateArgument *TransformedArgsPtr |
| 2922 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2923 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2924 | TransformedArgsPtr); |
| 2925 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2926 | TransformedArgs.size()), |
| 2927 | Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2928 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2929 | } |
| 2930 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2932 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2933 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2936 | /// \brief Iterator adaptor that invents template argument location information |
| 2937 | /// for each of the template arguments in its underlying iterator. |
| 2938 | template<typename Derived, typename InputIterator> |
| 2939 | class TemplateArgumentLocInventIterator { |
| 2940 | TreeTransform<Derived> &Self; |
| 2941 | InputIterator Iter; |
| 2942 | |
| 2943 | public: |
| 2944 | typedef TemplateArgumentLoc value_type; |
| 2945 | typedef TemplateArgumentLoc reference; |
| 2946 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2947 | difference_type; |
| 2948 | typedef std::input_iterator_tag iterator_category; |
| 2949 | |
| 2950 | class pointer { |
| 2951 | TemplateArgumentLoc Arg; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2952 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2953 | public: |
| 2954 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2955 | |
| 2956 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2957 | }; |
| 2958 | |
| 2959 | TemplateArgumentLocInventIterator() { } |
| 2960 | |
| 2961 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2962 | InputIterator Iter) |
| 2963 | : Self(Self), Iter(Iter) { } |
| 2964 | |
| 2965 | TemplateArgumentLocInventIterator &operator++() { |
| 2966 | ++Iter; |
| 2967 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2970 | TemplateArgumentLocInventIterator operator++(int) { |
| 2971 | TemplateArgumentLocInventIterator Old(*this); |
| 2972 | ++(*this); |
| 2973 | return Old; |
| 2974 | } |
| 2975 | |
| 2976 | reference operator*() const { |
| 2977 | TemplateArgumentLoc Result; |
| 2978 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 2979 | return Result; |
| 2980 | } |
| 2981 | |
| 2982 | pointer operator->() const { return pointer(**this); } |
| 2983 | |
| 2984 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 2985 | const TemplateArgumentLocInventIterator &Y) { |
| 2986 | return X.Iter == Y.Iter; |
| 2987 | } |
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 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 2990 | const TemplateArgumentLocInventIterator &Y) { |
| 2991 | return X.Iter != Y.Iter; |
| 2992 | } |
| 2993 | }; |
| 2994 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2995 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2996 | template<typename InputIterator> |
| 2997 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 2998 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2999 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3000 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3001 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3002 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3003 | |
| 3004 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 3005 | // Unpack argument packs, which we translate them into separate |
| 3006 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3007 | // FIXME: We could do much better if we could guarantee that the |
| 3008 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 3009 | // all of the template arguments in the argument pack. |
| 3010 | typedef TemplateArgumentLocInventIterator<Derived, |
| 3011 | TemplateArgument::pack_iterator> |
| 3012 | PackLocIterator; |
| 3013 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 3014 | In.getArgument().pack_begin()), |
| 3015 | PackLocIterator(*this, |
| 3016 | In.getArgument().pack_end()), |
| 3017 | Outputs)) |
| 3018 | return true; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3019 | |
| 3020 | continue; |
| 3021 | } |
| 3022 | |
| 3023 | if (In.getArgument().isPackExpansion()) { |
| 3024 | // We have a pack expansion, for which we will be substituting into |
| 3025 | // the pattern. |
| 3026 | SourceLocation Ellipsis; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3027 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3028 | TemplateArgumentLoc Pattern |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3029 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 3030 | getSema().Context); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3031 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3032 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3033 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3034 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 3035 | |
| 3036 | // Determine whether the set of unexpanded parameter packs can and should |
| 3037 | // be expanded. |
| 3038 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3039 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3040 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3041 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3042 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3043 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3044 | Expand, |
| 3045 | RetainExpansion, |
| 3046 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3047 | return true; |
| 3048 | |
| 3049 | if (!Expand) { |
| 3050 | // The transform has determined that we should perform a simple |
| 3051 | // transformation on the pack expansion, producing another pack |
| 3052 | // expansion. |
| 3053 | TemplateArgumentLoc OutPattern; |
| 3054 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3055 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3056 | return true; |
| 3057 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3058 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3059 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3060 | if (Out.getArgument().isNull()) |
| 3061 | return true; |
| 3062 | |
| 3063 | Outputs.addArgument(Out); |
| 3064 | continue; |
| 3065 | } |
| 3066 | |
| 3067 | // The transform has determined that we should perform an elementwise |
| 3068 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3069 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3070 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3071 | |
| 3072 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3073 | return true; |
| 3074 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3075 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3076 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3077 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3078 | if (Out.getArgument().isNull()) |
| 3079 | return true; |
| 3080 | } |
| 3081 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3082 | Outputs.addArgument(Out); |
| 3083 | } |
| 3084 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3085 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3086 | // forgetting the partially-substituted parameter pack. |
| 3087 | if (RetainExpansion) { |
| 3088 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3089 | |
| 3090 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3091 | return true; |
| 3092 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3093 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3094 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3095 | if (Out.getArgument().isNull()) |
| 3096 | return true; |
| 3097 | |
| 3098 | Outputs.addArgument(Out); |
| 3099 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3100 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3101 | continue; |
| 3102 | } |
| 3103 | |
| 3104 | // The simple case: |
| 3105 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3106 | return true; |
| 3107 | |
| 3108 | Outputs.addArgument(Out); |
| 3109 | } |
| 3110 | |
| 3111 | return false; |
| 3112 | |
| 3113 | } |
| 3114 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3115 | //===----------------------------------------------------------------------===// |
| 3116 | // Type transformation |
| 3117 | //===----------------------------------------------------------------------===// |
| 3118 | |
| 3119 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3120 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3121 | if (getDerived().AlreadyTransformed(T)) |
| 3122 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3123 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3124 | // Temporary workaround. All of these transformations should |
| 3125 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3126 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3127 | getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3128 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3129 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3130 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3131 | if (!NewDI) |
| 3132 | return QualType(); |
| 3133 | |
| 3134 | return NewDI->getType(); |
| 3135 | } |
| 3136 | |
| 3137 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3138 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3139 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3140 | return DI; |
| 3141 | |
| 3142 | TypeLocBuilder TLB; |
| 3143 | |
| 3144 | TypeLoc TL = DI->getTypeLoc(); |
| 3145 | TLB.reserve(TL.getFullDataSize()); |
| 3146 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3147 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3148 | if (Result.isNull()) |
| 3149 | return 0; |
| 3150 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3151 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | template<typename Derived> |
| 3155 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3156 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3157 | switch (T.getTypeLocClass()) { |
| 3158 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3159 | #define TYPELOC(CLASS, PARENT) \ |
| 3160 | case TypeLoc::CLASS: \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3161 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3162 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3165 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3166 | return QualType(); |
| 3167 | } |
| 3168 | |
| 3169 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3170 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3171 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3172 | /// types). This is the right thing for template instantiation, but |
| 3173 | /// probably not for other clients. |
| 3174 | template<typename Derived> |
| 3175 | QualType |
| 3176 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3177 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3178 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3179 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3180 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3181 | if (Result.isNull()) |
| 3182 | return QualType(); |
| 3183 | |
| 3184 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3185 | // FIXME: this is the right thing for template instantiation, but |
| 3186 | // probably not for other clients. |
| 3187 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3188 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3190 | // Suppress Objective-C lifetime qualifiers if they don't make sense for the |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3191 | // resulting type. |
| 3192 | if (Quals.hasObjCLifetime()) { |
| 3193 | if (!Result->isObjCLifetimeType() && !Result->isDependentType()) |
| 3194 | Quals.removeObjCLifetime(); |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3195 | else if (Result.getObjCLifetime()) { |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3196 | // Objective-C ARC: |
| 3197 | // A lifetime qualifier applied to a substituted template parameter |
| 3198 | // overrides the lifetime qualifier from the template argument. |
| 3199 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| 3200 | = dyn_cast<SubstTemplateTypeParmType>(Result)) { |
| 3201 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 3202 | Qualifiers Qs = Replacement.getQualifiers(); |
| 3203 | Qs.removeObjCLifetime(); |
| 3204 | Replacement |
| 3205 | = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), |
| 3206 | Qs); |
| 3207 | Result = SemaRef.Context.getSubstTemplateTypeParmType( |
| 3208 | SubstTypeParam->getReplacedParameter(), |
| 3209 | Replacement); |
| 3210 | TLB.TypeWasModifiedSafely(Result); |
| 3211 | } else { |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3212 | // Otherwise, complain about the addition of a qualifier to an |
| 3213 | // already-qualified type. |
| 3214 | SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 3215 | SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) |
Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 3216 | << Result << R; |
| 3217 | |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 3218 | Quals.removeObjCLifetime(); |
| 3219 | } |
| 3220 | } |
| 3221 | } |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3222 | if (!Quals.empty()) { |
| 3223 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3224 | TLB.push<QualifiedTypeLoc>(Result); |
| 3225 | // No location information to preserve. |
| 3226 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3227 | |
| 3228 | return Result; |
| 3229 | } |
| 3230 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3231 | template<typename Derived> |
| 3232 | TypeLoc |
| 3233 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3234 | QualType ObjectType, |
| 3235 | NamedDecl *UnqualLookup, |
| 3236 | CXXScopeSpec &SS) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3237 | QualType T = TL.getType(); |
| 3238 | if (getDerived().AlreadyTransformed(T)) |
| 3239 | return TL; |
| 3240 | |
| 3241 | TypeLocBuilder TLB; |
| 3242 | QualType Result; |
| 3243 | |
| 3244 | if (isa<TemplateSpecializationType>(T)) { |
| 3245 | TemplateSpecializationTypeLoc SpecTL |
| 3246 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3247 | |
| 3248 | TemplateName Template = |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3249 | getDerived().TransformTemplateName(SS, |
| 3250 | SpecTL.getTypePtr()->getTemplateName(), |
| 3251 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3252 | ObjectType, UnqualLookup); |
| 3253 | if (Template.isNull()) |
| 3254 | return TypeLoc(); |
| 3255 | |
| 3256 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3257 | Template); |
| 3258 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3259 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3260 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3261 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3262 | TemplateName Template |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3263 | = getDerived().RebuildTemplateName(SS, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3264 | *SpecTL.getTypePtr()->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3265 | SpecTL.getNameLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3266 | ObjectType, UnqualLookup); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3267 | if (Template.isNull()) |
| 3268 | return TypeLoc(); |
| 3269 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3270 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3271 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3272 | Template, |
| 3273 | SS); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3274 | } else { |
| 3275 | // Nothing special needs to be done for these. |
| 3276 | Result = getDerived().TransformType(TLB, TL); |
| 3277 | } |
| 3278 | |
| 3279 | if (Result.isNull()) |
| 3280 | return TypeLoc(); |
| 3281 | |
| 3282 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3283 | } |
| 3284 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3285 | template<typename Derived> |
| 3286 | TypeSourceInfo * |
| 3287 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3288 | QualType ObjectType, |
| 3289 | NamedDecl *UnqualLookup, |
| 3290 | CXXScopeSpec &SS) { |
| 3291 | // FIXME: Painfully copy-paste from the above! |
| 3292 | |
| 3293 | QualType T = TSInfo->getType(); |
| 3294 | if (getDerived().AlreadyTransformed(T)) |
| 3295 | return TSInfo; |
| 3296 | |
| 3297 | TypeLocBuilder TLB; |
| 3298 | QualType Result; |
| 3299 | |
| 3300 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3301 | if (isa<TemplateSpecializationType>(T)) { |
| 3302 | TemplateSpecializationTypeLoc SpecTL |
| 3303 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3304 | |
| 3305 | TemplateName Template |
| 3306 | = getDerived().TransformTemplateName(SS, |
| 3307 | SpecTL.getTypePtr()->getTemplateName(), |
| 3308 | SpecTL.getTemplateNameLoc(), |
| 3309 | ObjectType, UnqualLookup); |
| 3310 | if (Template.isNull()) |
| 3311 | return 0; |
| 3312 | |
| 3313 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3314 | Template); |
| 3315 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3316 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3317 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3318 | |
| 3319 | TemplateName Template |
| 3320 | = getDerived().RebuildTemplateName(SS, |
| 3321 | *SpecTL.getTypePtr()->getIdentifier(), |
| 3322 | SpecTL.getNameLoc(), |
| 3323 | ObjectType, UnqualLookup); |
| 3324 | if (Template.isNull()) |
| 3325 | return 0; |
| 3326 | |
| 3327 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| 3328 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3329 | Template, |
| 3330 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3331 | } else { |
| 3332 | // Nothing special needs to be done for these. |
| 3333 | Result = getDerived().TransformType(TLB, TL); |
| 3334 | } |
| 3335 | |
| 3336 | if (Result.isNull()) |
| 3337 | return 0; |
| 3338 | |
| 3339 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3340 | } |
| 3341 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3342 | template <class TyLoc> static inline |
| 3343 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3344 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3345 | NewT.setNameLoc(T.getNameLoc()); |
| 3346 | return T.getType(); |
| 3347 | } |
| 3348 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3349 | template<typename Derived> |
| 3350 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3351 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3352 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3353 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3354 | if (T.needsExtraLocalData()) |
| 3355 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3356 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3359 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3360 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3361 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3362 | // FIXME: recurse? |
| 3363 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3366 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3367 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3368 | PointerTypeLoc TL) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3369 | QualType PointeeType |
| 3370 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3371 | if (PointeeType.isNull()) |
| 3372 | return QualType(); |
| 3373 | |
| 3374 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3375 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3376 | // A dependent pointer type 'T *' has is being transformed such |
| 3377 | // that an Objective-C class type is being replaced for 'T'. The |
| 3378 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3379 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3380 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3381 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3382 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3383 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3384 | return Result; |
| 3385 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3386 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3387 | if (getDerived().AlwaysRebuild() || |
| 3388 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3389 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3390 | if (Result.isNull()) |
| 3391 | return QualType(); |
| 3392 | } |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3393 | |
| 3394 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3395 | // pointing to. |
| 3396 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| 3397 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3398 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3399 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3400 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3402 | |
| 3403 | template<typename Derived> |
| 3404 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3405 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3406 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3407 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3408 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3409 | if (PointeeType.isNull()) |
| 3410 | return QualType(); |
| 3411 | |
| 3412 | QualType Result = TL.getType(); |
| 3413 | if (getDerived().AlwaysRebuild() || |
| 3414 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3415 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3416 | TL.getSigilLoc()); |
| 3417 | if (Result.isNull()) |
| 3418 | return QualType(); |
| 3419 | } |
| 3420 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3421 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3422 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3423 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3426 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3427 | /// don't care whether the type itself is an l-value type or an r-value |
| 3428 | /// type; we only care if the type was *written* as an l-value type |
| 3429 | /// or an r-value type. |
| 3430 | template<typename Derived> |
| 3431 | QualType |
| 3432 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3433 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3434 | const ReferenceType *T = TL.getTypePtr(); |
| 3435 | |
| 3436 | // Note that this works with the pointee-as-written. |
| 3437 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3438 | if (PointeeType.isNull()) |
| 3439 | return QualType(); |
| 3440 | |
| 3441 | QualType Result = TL.getType(); |
| 3442 | if (getDerived().AlwaysRebuild() || |
| 3443 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3444 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3445 | T->isSpelledAsLValue(), |
| 3446 | TL.getSigilLoc()); |
| 3447 | if (Result.isNull()) |
| 3448 | return QualType(); |
| 3449 | } |
| 3450 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3451 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 3452 | // referring to. |
| 3453 | TLB.TypeWasModifiedSafely( |
| 3454 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 3455 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3456 | // r-value references can be rebuilt as l-value references. |
| 3457 | ReferenceTypeLoc NewTL; |
| 3458 | if (isa<LValueReferenceType>(Result)) |
| 3459 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3460 | else |
| 3461 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3462 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3463 | |
| 3464 | return Result; |
| 3465 | } |
| 3466 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3467 | template<typename Derived> |
| 3468 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3469 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3470 | LValueReferenceTypeLoc TL) { |
| 3471 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | template<typename Derived> |
| 3475 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3476 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3477 | RValueReferenceTypeLoc TL) { |
| 3478 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3481 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3483 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3484 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3485 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3486 | if (PointeeType.isNull()) |
| 3487 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3489 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3490 | TypeSourceInfo* NewClsTInfo = 0; |
| 3491 | if (OldClsTInfo) { |
| 3492 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3493 | if (!NewClsTInfo) |
| 3494 | return QualType(); |
| 3495 | } |
| 3496 | |
| 3497 | const MemberPointerType *T = TL.getTypePtr(); |
| 3498 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3499 | QualType NewClsType; |
| 3500 | if (NewClsTInfo) |
| 3501 | NewClsType = NewClsTInfo->getType(); |
| 3502 | else { |
| 3503 | NewClsType = getDerived().TransformType(OldClsType); |
| 3504 | if (NewClsType.isNull()) |
| 3505 | return QualType(); |
| 3506 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3507 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3508 | QualType Result = TL.getType(); |
| 3509 | if (getDerived().AlwaysRebuild() || |
| 3510 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3511 | NewClsType != OldClsType) { |
| 3512 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3513 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3514 | if (Result.isNull()) |
| 3515 | return QualType(); |
| 3516 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3517 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3518 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3519 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3520 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3521 | |
| 3522 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3523 | } |
| 3524 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3525 | template<typename Derived> |
| 3526 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3527 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3528 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3529 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3530 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3531 | if (ElementType.isNull()) |
| 3532 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3534 | QualType Result = TL.getType(); |
| 3535 | if (getDerived().AlwaysRebuild() || |
| 3536 | ElementType != T->getElementType()) { |
| 3537 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3538 | T->getSizeModifier(), |
| 3539 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3540 | T->getIndexTypeCVRQualifiers(), |
| 3541 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3542 | if (Result.isNull()) |
| 3543 | return QualType(); |
| 3544 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3545 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3546 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3547 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3548 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3550 | Expr *Size = TL.getSizeExpr(); |
| 3551 | if (Size) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3552 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3553 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3554 | } |
| 3555 | NewTL.setSizeExpr(Size); |
| 3556 | |
| 3557 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3558 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3559 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3560 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3561 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3562 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3563 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3564 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3565 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3566 | if (ElementType.isNull()) |
| 3567 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3568 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3569 | QualType Result = TL.getType(); |
| 3570 | if (getDerived().AlwaysRebuild() || |
| 3571 | ElementType != T->getElementType()) { |
| 3572 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3573 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3574 | T->getIndexTypeCVRQualifiers(), |
| 3575 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3576 | if (Result.isNull()) |
| 3577 | return QualType(); |
| 3578 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3579 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3580 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3581 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3582 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3583 | NewTL.setSizeExpr(0); |
| 3584 | |
| 3585 | return Result; |
| 3586 | } |
| 3587 | |
| 3588 | template<typename Derived> |
| 3589 | QualType |
| 3590 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3591 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3592 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3593 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3594 | if (ElementType.isNull()) |
| 3595 | return QualType(); |
| 3596 | |
| 3597 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3598 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3599 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3600 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3601 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3602 | if (SizeResult.isInvalid()) |
| 3603 | return QualType(); |
| 3604 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3605 | Expr *Size = SizeResult.take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3606 | |
| 3607 | QualType Result = TL.getType(); |
| 3608 | if (getDerived().AlwaysRebuild() || |
| 3609 | ElementType != T->getElementType() || |
| 3610 | Size != T->getSizeExpr()) { |
| 3611 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3612 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3613 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3614 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3615 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3616 | if (Result.isNull()) |
| 3617 | return QualType(); |
| 3618 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3619 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3620 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3621 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3622 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3623 | NewTL.setSizeExpr(Size); |
| 3624 | |
| 3625 | return Result; |
| 3626 | } |
| 3627 | |
| 3628 | template<typename Derived> |
| 3629 | QualType |
| 3630 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3631 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3632 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3633 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3634 | if (ElementType.isNull()) |
| 3635 | return QualType(); |
| 3636 | |
| 3637 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3638 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3639 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3640 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3641 | Expr *origSize = TL.getSizeExpr(); |
| 3642 | if (!origSize) origSize = T->getSizeExpr(); |
| 3643 | |
| 3644 | ExprResult sizeResult |
| 3645 | = getDerived().TransformExpr(origSize); |
| 3646 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3647 | return QualType(); |
| 3648 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3649 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3650 | |
| 3651 | QualType Result = TL.getType(); |
| 3652 | if (getDerived().AlwaysRebuild() || |
| 3653 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3654 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3655 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3656 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3657 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3658 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3659 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3660 | if (Result.isNull()) |
| 3661 | return QualType(); |
| 3662 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3663 | |
| 3664 | // We might have any sort of array type now, but fortunately they |
| 3665 | // all have the same location layout. |
| 3666 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3667 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3668 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3669 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3670 | |
| 3671 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3673 | |
| 3674 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3675 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3676 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3677 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3678 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3679 | |
| 3680 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3681 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3682 | if (ElementType.isNull()) |
| 3683 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3685 | // Vector sizes are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3686 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3687 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3688 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3689 | if (Size.isInvalid()) |
| 3690 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3691 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3692 | QualType Result = TL.getType(); |
| 3693 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3694 | ElementType != T->getElementType() || |
| 3695 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3696 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3697 | Size.take(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3698 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3699 | if (Result.isNull()) |
| 3700 | return QualType(); |
| 3701 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3702 | |
| 3703 | // Result might be dependent or not. |
| 3704 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3705 | DependentSizedExtVectorTypeLoc NewTL |
| 3706 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3707 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3708 | } else { |
| 3709 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3710 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3711 | } |
| 3712 | |
| 3713 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3714 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | |
| 3716 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3717 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3718 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3719 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3720 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3721 | if (ElementType.isNull()) |
| 3722 | return QualType(); |
| 3723 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3724 | QualType Result = TL.getType(); |
| 3725 | if (getDerived().AlwaysRebuild() || |
| 3726 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3727 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3728 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3729 | if (Result.isNull()) |
| 3730 | return QualType(); |
| 3731 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3732 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3733 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3734 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3735 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3736 | return Result; |
| 3737 | } |
| 3738 | |
| 3739 | template<typename Derived> |
| 3740 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3741 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3742 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3743 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3744 | if (ElementType.isNull()) |
| 3745 | return QualType(); |
| 3746 | |
| 3747 | QualType Result = TL.getType(); |
| 3748 | if (getDerived().AlwaysRebuild() || |
| 3749 | ElementType != T->getElementType()) { |
| 3750 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3751 | T->getNumElements(), |
| 3752 | /*FIXME*/ SourceLocation()); |
| 3753 | if (Result.isNull()) |
| 3754 | return QualType(); |
| 3755 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3756 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3757 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3758 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3759 | |
| 3760 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3762 | |
| 3763 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3764 | ParmVarDecl * |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3765 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3766 | int indexAdjustment, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3767 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3768 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3769 | TypeSourceInfo *NewDI = 0; |
| 3770 | |
| 3771 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3772 | // If we're substituting into a pack expansion type and we know the |
| 3773 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3774 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3775 | |
| 3776 | TypeLocBuilder TLB; |
| 3777 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3778 | TLB.reserve(NewTL.getFullDataSize()); |
| 3779 | |
| 3780 | QualType Result = getDerived().TransformType(TLB, |
| 3781 | OldExpansionTL.getPatternLoc()); |
| 3782 | if (Result.isNull()) |
| 3783 | return 0; |
| 3784 | |
| 3785 | Result = RebuildPackExpansionType(Result, |
| 3786 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3787 | OldExpansionTL.getEllipsisLoc(), |
| 3788 | NumExpansions); |
| 3789 | if (Result.isNull()) |
| 3790 | return 0; |
| 3791 | |
| 3792 | PackExpansionTypeLoc NewExpansionTL |
| 3793 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3794 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3795 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3796 | } else |
| 3797 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3798 | if (!NewDI) |
| 3799 | return 0; |
| 3800 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3801 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3802 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3803 | |
| 3804 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 3805 | OldParm->getDeclContext(), |
| 3806 | OldParm->getInnerLocStart(), |
| 3807 | OldParm->getLocation(), |
| 3808 | OldParm->getIdentifier(), |
| 3809 | NewDI->getType(), |
| 3810 | NewDI, |
| 3811 | OldParm->getStorageClass(), |
| 3812 | OldParm->getStorageClassAsWritten(), |
| 3813 | /* DefArg */ NULL); |
| 3814 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 3815 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 3816 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | template<typename Derived> |
| 3820 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3821 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3822 | ParmVarDecl **Params, unsigned NumParams, |
| 3823 | const QualType *ParamTypes, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3824 | SmallVectorImpl<QualType> &OutParamTypes, |
| 3825 | SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3826 | int indexAdjustment = 0; |
| 3827 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3828 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3829 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3830 | assert(OldParm->getFunctionScopeIndex() == i); |
| 3831 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3832 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3833 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3834 | if (OldParm->isParameterPack()) { |
| 3835 | // We have a function parameter pack that may need to be expanded. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3836 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3837 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3838 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3839 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3840 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3841 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3842 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3843 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 3844 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3845 | // Determine whether we should expand the parameter packs. |
| 3846 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3847 | bool RetainExpansion = false; |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3848 | llvm::Optional<unsigned> OrigNumExpansions |
| 3849 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3850 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3851 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3852 | Pattern.getSourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3853 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3854 | ShouldExpand, |
| 3855 | RetainExpansion, |
| 3856 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3857 | return true; |
| 3858 | } |
| 3859 | |
| 3860 | if (ShouldExpand) { |
| 3861 | // Expand the function parameter pack into multiple, separate |
| 3862 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3863 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3864 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3865 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3866 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3867 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3868 | indexAdjustment++, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3869 | OrigNumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3870 | if (!NewParm) |
| 3871 | return true; |
| 3872 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3873 | OutParamTypes.push_back(NewParm->getType()); |
| 3874 | if (PVars) |
| 3875 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3876 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3877 | |
| 3878 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3879 | // forgetting the partially-substituted parameter pack. |
| 3880 | if (RetainExpansion) { |
| 3881 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3882 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3883 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3884 | indexAdjustment++, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3885 | OrigNumExpansions); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3886 | if (!NewParm) |
| 3887 | return true; |
| 3888 | |
| 3889 | OutParamTypes.push_back(NewParm->getType()); |
| 3890 | if (PVars) |
| 3891 | PVars->push_back(NewParm); |
| 3892 | } |
| 3893 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3894 | // The next parameter should have the same adjustment as the |
| 3895 | // last thing we pushed, but we post-incremented indexAdjustment |
| 3896 | // on every push. Also, if we push nothing, the adjustment should |
| 3897 | // go down by one. |
| 3898 | indexAdjustment--; |
| 3899 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3900 | // We're done with the pack expansion. |
| 3901 | continue; |
| 3902 | } |
| 3903 | |
| 3904 | // We'll substitute the parameter now without expanding the pack |
| 3905 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3906 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3907 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3908 | indexAdjustment, |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3909 | NumExpansions); |
| 3910 | } else { |
| 3911 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3912 | indexAdjustment, |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3913 | llvm::Optional<unsigned>()); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3914 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3915 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3916 | if (!NewParm) |
| 3917 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3918 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3919 | OutParamTypes.push_back(NewParm->getType()); |
| 3920 | if (PVars) |
| 3921 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3922 | continue; |
| 3923 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3924 | |
| 3925 | // Deal with the possibility that we don't have a parameter |
| 3926 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3927 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3928 | bool IsPackExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3929 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3930 | QualType NewType; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3931 | if (const PackExpansionType *Expansion |
| 3932 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3933 | // We have a function parameter pack that may need to be expanded. |
| 3934 | QualType Pattern = Expansion->getPattern(); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3935 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3936 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3937 | |
| 3938 | // Determine whether we should expand the parameter packs. |
| 3939 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3940 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3941 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3942 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3943 | ShouldExpand, |
| 3944 | RetainExpansion, |
| 3945 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3946 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | if (ShouldExpand) { |
| 3950 | // Expand the function parameter pack into multiple, separate |
| 3951 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3952 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3953 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3954 | QualType NewType = getDerived().TransformType(Pattern); |
| 3955 | if (NewType.isNull()) |
| 3956 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3957 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3958 | OutParamTypes.push_back(NewType); |
| 3959 | if (PVars) |
| 3960 | PVars->push_back(0); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | // We're done with the pack expansion. |
| 3964 | continue; |
| 3965 | } |
| 3966 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3967 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3968 | // forgetting the partially-substituted parameter pack. |
| 3969 | if (RetainExpansion) { |
| 3970 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3971 | QualType NewType = getDerived().TransformType(Pattern); |
| 3972 | if (NewType.isNull()) |
| 3973 | return true; |
| 3974 | |
| 3975 | OutParamTypes.push_back(NewType); |
| 3976 | if (PVars) |
| 3977 | PVars->push_back(0); |
| 3978 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3980 | // We'll substitute the parameter now without expanding the pack |
| 3981 | // expansion. |
| 3982 | OldType = Expansion->getPattern(); |
| 3983 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3984 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3985 | NewType = getDerived().TransformType(OldType); |
| 3986 | } else { |
| 3987 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3988 | } |
| 3989 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3990 | if (NewType.isNull()) |
| 3991 | return true; |
| 3992 | |
| 3993 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3994 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3995 | NumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3996 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3997 | OutParamTypes.push_back(NewType); |
| 3998 | if (PVars) |
| 3999 | PVars->push_back(0); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4000 | } |
| 4001 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4002 | #ifndef NDEBUG |
| 4003 | if (PVars) { |
| 4004 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 4005 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 4006 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 4007 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4008 | #endif |
| 4009 | |
| 4010 | return false; |
| 4011 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4012 | |
| 4013 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4014 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4015 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4016 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4017 | // Transform the parameters and return type. |
| 4018 | // |
| 4019 | // We instantiate in source order, with the return type first followed by |
| 4020 | // the parameters, because users tend to expect this (even if they shouldn't |
| 4021 | // rely on it!). |
| 4022 | // |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4023 | // When the function has a trailing return type, we instantiate the |
| 4024 | // parameters before the return type, since the return type can then refer |
| 4025 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 4026 | // |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4027 | SmallVector<QualType, 4> ParamTypes; |
| 4028 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4029 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 4030 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4031 | QualType ResultType; |
| 4032 | |
| 4033 | if (TL.getTrailingReturn()) { |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4034 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4035 | TL.getParmArray(), |
| 4036 | TL.getNumArgs(), |
| 4037 | TL.getTypePtr()->arg_type_begin(), |
| 4038 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4039 | return QualType(); |
| 4040 | |
| 4041 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4042 | if (ResultType.isNull()) |
| 4043 | return QualType(); |
| 4044 | } |
| 4045 | else { |
| 4046 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4047 | if (ResultType.isNull()) |
| 4048 | return QualType(); |
| 4049 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 4050 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 4051 | TL.getParmArray(), |
| 4052 | TL.getNumArgs(), |
| 4053 | TL.getTypePtr()->arg_type_begin(), |
| 4054 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4055 | return QualType(); |
| 4056 | } |
| 4057 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4058 | QualType Result = TL.getType(); |
| 4059 | if (getDerived().AlwaysRebuild() || |
| 4060 | ResultType != T->getResultType() || |
Douglas Gregor | 9f627df | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 4061 | T->getNumArgs() != ParamTypes.size() || |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4062 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 4063 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 4064 | ParamTypes.data(), |
| 4065 | ParamTypes.size(), |
| 4066 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4067 | T->getTypeQuals(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 4068 | T->getRefQualifier(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 4069 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4070 | if (Result.isNull()) |
| 4071 | return QualType(); |
| 4072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4074 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4075 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4076 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4077 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4078 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4079 | NewTL.setArg(i, ParamDecls[i]); |
| 4080 | |
| 4081 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4082 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4084 | template<typename Derived> |
| 4085 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4086 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4087 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4088 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4089 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4090 | if (ResultType.isNull()) |
| 4091 | return QualType(); |
| 4092 | |
| 4093 | QualType Result = TL.getType(); |
| 4094 | if (getDerived().AlwaysRebuild() || |
| 4095 | ResultType != T->getResultType()) |
| 4096 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4097 | |
| 4098 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4099 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4100 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4101 | NewTL.setTrailingReturn(false); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4102 | |
| 4103 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4106 | template<typename Derived> QualType |
| 4107 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4108 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4109 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4110 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4111 | if (!D) |
| 4112 | return QualType(); |
| 4113 | |
| 4114 | QualType Result = TL.getType(); |
| 4115 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4116 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4117 | if (Result.isNull()) |
| 4118 | return QualType(); |
| 4119 | } |
| 4120 | |
| 4121 | // We might get an arbitrary type spec type back. We should at |
| 4122 | // least always get a type spec type, though. |
| 4123 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4124 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4125 | |
| 4126 | return Result; |
| 4127 | } |
| 4128 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4129 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4130 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4131 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4132 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4133 | TypedefNameDecl *Typedef |
| 4134 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4135 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4136 | if (!Typedef) |
| 4137 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4139 | QualType Result = TL.getType(); |
| 4140 | if (getDerived().AlwaysRebuild() || |
| 4141 | Typedef != T->getDecl()) { |
| 4142 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4143 | if (Result.isNull()) |
| 4144 | return QualType(); |
| 4145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4147 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4148 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4149 | |
| 4150 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4151 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4153 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4154 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4155 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4156 | // typeof expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4157 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4159 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4160 | if (E.isInvalid()) |
| 4161 | return QualType(); |
| 4162 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4163 | QualType Result = TL.getType(); |
| 4164 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4165 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4166 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4167 | if (Result.isNull()) |
| 4168 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4169 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4170 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4171 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4172 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4173 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4174 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4175 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4176 | |
| 4177 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | |
| 4180 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4181 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4182 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4183 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4184 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4185 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4186 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4188 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4189 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4190 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4191 | if (Result.isNull()) |
| 4192 | return QualType(); |
| 4193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4194 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4195 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4196 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4197 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4198 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4199 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4200 | |
| 4201 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
| 4204 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4205 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4206 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4207 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4208 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4209 | // decltype expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4210 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4211 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4212 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4213 | if (E.isInvalid()) |
| 4214 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4215 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4216 | QualType Result = TL.getType(); |
| 4217 | if (getDerived().AlwaysRebuild() || |
| 4218 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4219 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4220 | if (Result.isNull()) |
| 4221 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4222 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4223 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4224 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4225 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4226 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4227 | |
| 4228 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4232 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 4233 | TypeLocBuilder &TLB, |
| 4234 | UnaryTransformTypeLoc TL) { |
| 4235 | QualType Result = TL.getType(); |
| 4236 | if (Result->isDependentType()) { |
| 4237 | const UnaryTransformType *T = TL.getTypePtr(); |
| 4238 | QualType NewBase = |
| 4239 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 4240 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 4241 | T->getUTTKind(), |
| 4242 | TL.getKWLoc()); |
| 4243 | if (Result.isNull()) |
| 4244 | return QualType(); |
| 4245 | } |
| 4246 | |
| 4247 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 4248 | NewTL.setKWLoc(TL.getKWLoc()); |
| 4249 | NewTL.setParensRange(TL.getParensRange()); |
| 4250 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 4251 | return Result; |
| 4252 | } |
| 4253 | |
| 4254 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4255 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4256 | AutoTypeLoc TL) { |
| 4257 | const AutoType *T = TL.getTypePtr(); |
| 4258 | QualType OldDeduced = T->getDeducedType(); |
| 4259 | QualType NewDeduced; |
| 4260 | if (!OldDeduced.isNull()) { |
| 4261 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4262 | if (NewDeduced.isNull()) |
| 4263 | return QualType(); |
| 4264 | } |
| 4265 | |
| 4266 | QualType Result = TL.getType(); |
| 4267 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4268 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4269 | if (Result.isNull()) |
| 4270 | return QualType(); |
| 4271 | } |
| 4272 | |
| 4273 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4274 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4275 | |
| 4276 | return Result; |
| 4277 | } |
| 4278 | |
| 4279 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4280 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4281 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4282 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4283 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4284 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4285 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4286 | if (!Record) |
| 4287 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4289 | QualType Result = TL.getType(); |
| 4290 | if (getDerived().AlwaysRebuild() || |
| 4291 | Record != T->getDecl()) { |
| 4292 | Result = getDerived().RebuildRecordType(Record); |
| 4293 | if (Result.isNull()) |
| 4294 | return QualType(); |
| 4295 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4297 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4298 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4299 | |
| 4300 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4301 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4302 | |
| 4303 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4304 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4305 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4306 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4307 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4308 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4309 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4310 | if (!Enum) |
| 4311 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4313 | QualType Result = TL.getType(); |
| 4314 | if (getDerived().AlwaysRebuild() || |
| 4315 | Enum != T->getDecl()) { |
| 4316 | Result = getDerived().RebuildEnumType(Enum); |
| 4317 | if (Result.isNull()) |
| 4318 | return QualType(); |
| 4319 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4320 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4321 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4322 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4323 | |
| 4324 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4325 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4326 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4327 | template<typename Derived> |
| 4328 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4329 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4330 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4331 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4332 | TL.getTypePtr()->getDecl()); |
| 4333 | if (!D) return QualType(); |
| 4334 | |
| 4335 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4336 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4337 | return T; |
| 4338 | } |
| 4339 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4340 | template<typename Derived> |
| 4341 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4342 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4343 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4344 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4345 | } |
| 4346 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4348 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4349 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4350 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4351 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| 4352 | |
| 4353 | // Substitute into the replacement type, which itself might involve something |
| 4354 | // that needs to be transformed. This only tends to occur with default |
| 4355 | // template arguments of template template parameters. |
| 4356 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4357 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4358 | if (Replacement.isNull()) |
| 4359 | return QualType(); |
| 4360 | |
| 4361 | // Always canonicalize the replacement type. |
| 4362 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4363 | QualType Result |
| 4364 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| 4365 | Replacement); |
| 4366 | |
| 4367 | // Propagate type-source information. |
| 4368 | SubstTemplateTypeParmTypeLoc NewTL |
| 4369 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4370 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4371 | return Result; |
| 4372 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4376 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4377 | TypeLocBuilder &TLB, |
| 4378 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4379 | return TransformTypeSpecType(TLB, TL); |
| 4380 | } |
| 4381 | |
| 4382 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4383 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4384 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4385 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4386 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4387 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4388 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4389 | // because we can't have a dependent nested-name-specifier anyway. |
| 4390 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4392 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4393 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4394 | if (Template.isNull()) |
| 4395 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4397 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4398 | } |
| 4399 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4400 | namespace { |
| 4401 | /// \brief Simple iterator that traverses the template arguments in a |
| 4402 | /// container that provides a \c getArgLoc() member function. |
| 4403 | /// |
| 4404 | /// This iterator is intended to be used with the iterator form of |
| 4405 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4406 | template<typename ArgLocContainer> |
| 4407 | class TemplateArgumentLocContainerIterator { |
| 4408 | ArgLocContainer *Container; |
| 4409 | unsigned Index; |
| 4410 | |
| 4411 | public: |
| 4412 | typedef TemplateArgumentLoc value_type; |
| 4413 | typedef TemplateArgumentLoc reference; |
| 4414 | typedef int difference_type; |
| 4415 | typedef std::input_iterator_tag iterator_category; |
| 4416 | |
| 4417 | class pointer { |
| 4418 | TemplateArgumentLoc Arg; |
| 4419 | |
| 4420 | public: |
| 4421 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4422 | |
| 4423 | const TemplateArgumentLoc *operator->() const { |
| 4424 | return &Arg; |
| 4425 | } |
| 4426 | }; |
| 4427 | |
| 4428 | |
| 4429 | TemplateArgumentLocContainerIterator() {} |
| 4430 | |
| 4431 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4432 | unsigned Index) |
| 4433 | : Container(&Container), Index(Index) { } |
| 4434 | |
| 4435 | TemplateArgumentLocContainerIterator &operator++() { |
| 4436 | ++Index; |
| 4437 | return *this; |
| 4438 | } |
| 4439 | |
| 4440 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4441 | TemplateArgumentLocContainerIterator Old(*this); |
| 4442 | ++(*this); |
| 4443 | return Old; |
| 4444 | } |
| 4445 | |
| 4446 | TemplateArgumentLoc operator*() const { |
| 4447 | return Container->getArgLoc(Index); |
| 4448 | } |
| 4449 | |
| 4450 | pointer operator->() const { |
| 4451 | return pointer(Container->getArgLoc(Index)); |
| 4452 | } |
| 4453 | |
| 4454 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4455 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4456 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4457 | } |
| 4458 | |
| 4459 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4460 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4461 | return !(X == Y); |
| 4462 | } |
| 4463 | }; |
| 4464 | } |
| 4465 | |
| 4466 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4467 | template <typename Derived> |
| 4468 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4469 | TypeLocBuilder &TLB, |
| 4470 | TemplateSpecializationTypeLoc TL, |
| 4471 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4472 | TemplateArgumentListInfo NewTemplateArgs; |
| 4473 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4474 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4475 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4476 | ArgIterator; |
| 4477 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4478 | ArgIterator(TL, TL.getNumArgs()), |
| 4479 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4480 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4481 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4482 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4483 | |
| 4484 | QualType Result = |
| 4485 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4486 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4487 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4488 | |
| 4489 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4490 | // Specializations of template template parameters are represented as |
| 4491 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4492 | // within a dependent context can transform them into |
| 4493 | // DependentTemplateSpecializationTypes. |
| 4494 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4495 | DependentTemplateSpecializationTypeLoc NewTL |
| 4496 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4497 | NewTL.setKeywordLoc(TL.getTemplateNameLoc()); |
| 4498 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
| 4499 | NewTL.setNameLoc(TL.getTemplateNameLoc()); |
| 4500 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4501 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4502 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4503 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4504 | return Result; |
| 4505 | } |
| 4506 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4507 | TemplateSpecializationTypeLoc NewTL |
| 4508 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4509 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4510 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4511 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4512 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4513 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4514 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4516 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4517 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4518 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4519 | template <typename Derived> |
| 4520 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4521 | TypeLocBuilder &TLB, |
| 4522 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4523 | TemplateName Template, |
| 4524 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4525 | TemplateArgumentListInfo NewTemplateArgs; |
| 4526 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4527 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4528 | typedef TemplateArgumentLocContainerIterator< |
| 4529 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4530 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4531 | ArgIterator(TL, TL.getNumArgs()), |
| 4532 | NewTemplateArgs)) |
| 4533 | return QualType(); |
| 4534 | |
| 4535 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4536 | |
| 4537 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4538 | QualType Result |
| 4539 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4540 | TL.getTypePtr()->getKeyword(), |
| 4541 | DTN->getQualifier(), |
| 4542 | DTN->getIdentifier(), |
| 4543 | NewTemplateArgs); |
| 4544 | |
| 4545 | DependentTemplateSpecializationTypeLoc NewTL |
| 4546 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4547 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4548 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4549 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4550 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4551 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4552 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4553 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4554 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4555 | return Result; |
| 4556 | } |
| 4557 | |
| 4558 | QualType Result |
| 4559 | = getDerived().RebuildTemplateSpecializationType(Template, |
| 4560 | TL.getNameLoc(), |
| 4561 | NewTemplateArgs); |
| 4562 | |
| 4563 | if (!Result.isNull()) { |
| 4564 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4565 | TemplateSpecializationTypeLoc NewTL |
| 4566 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4567 | NewTL.setTemplateNameLoc(TL.getNameLoc()); |
| 4568 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4569 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4570 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4571 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4572 | } |
| 4573 | |
| 4574 | return Result; |
| 4575 | } |
| 4576 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4577 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4578 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4579 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4580 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4581 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4582 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4583 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4584 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4585 | if (TL.getQualifierLoc()) { |
| 4586 | QualifierLoc |
| 4587 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4588 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4589 | return QualType(); |
| 4590 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4591 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4592 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4593 | if (NamedT.isNull()) |
| 4594 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4595 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4596 | // C++0x [dcl.type.elab]p2: |
| 4597 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4598 | // resolves to an alias template specialization, the |
| 4599 | // elaborated-type-specifier is ill-formed. |
Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 4600 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 4601 | if (const TemplateSpecializationType *TST = |
| 4602 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4603 | TemplateName Template = TST->getTemplateName(); |
| 4604 | if (TypeAliasTemplateDecl *TAT = |
| 4605 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4606 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4607 | diag::err_tag_reference_non_tag) << 4; |
| 4608 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4609 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4610 | } |
| 4611 | } |
| 4612 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4613 | QualType Result = TL.getType(); |
| 4614 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4615 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4616 | NamedT != T->getNamedType()) { |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4617 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4618 | T->getKeyword(), |
| 4619 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4620 | if (Result.isNull()) |
| 4621 | return QualType(); |
| 4622 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4623 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4624 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4625 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4626 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4627 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4628 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4629 | |
| 4630 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4631 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4632 | TypeLocBuilder &TLB, |
| 4633 | AttributedTypeLoc TL) { |
| 4634 | const AttributedType *oldType = TL.getTypePtr(); |
| 4635 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4636 | if (modifiedType.isNull()) |
| 4637 | return QualType(); |
| 4638 | |
| 4639 | QualType result = TL.getType(); |
| 4640 | |
| 4641 | // FIXME: dependent operand expressions? |
| 4642 | if (getDerived().AlwaysRebuild() || |
| 4643 | modifiedType != oldType->getModifiedType()) { |
| 4644 | // TODO: this is really lame; we should really be rebuilding the |
| 4645 | // equivalent type from first principles. |
| 4646 | QualType equivalentType |
| 4647 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4648 | if (equivalentType.isNull()) |
| 4649 | return QualType(); |
| 4650 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4651 | modifiedType, |
| 4652 | equivalentType); |
| 4653 | } |
| 4654 | |
| 4655 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4656 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4657 | if (TL.hasAttrOperand()) |
| 4658 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4659 | if (TL.hasAttrExprOperand()) |
| 4660 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4661 | else if (TL.hasAttrEnumOperand()) |
| 4662 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4663 | |
| 4664 | return result; |
| 4665 | } |
| 4666 | |
| 4667 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4668 | QualType |
| 4669 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4670 | ParenTypeLoc TL) { |
| 4671 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4672 | if (Inner.isNull()) |
| 4673 | return QualType(); |
| 4674 | |
| 4675 | QualType Result = TL.getType(); |
| 4676 | if (getDerived().AlwaysRebuild() || |
| 4677 | Inner != TL.getInnerLoc().getType()) { |
| 4678 | Result = getDerived().RebuildParenType(Inner); |
| 4679 | if (Result.isNull()) |
| 4680 | return QualType(); |
| 4681 | } |
| 4682 | |
| 4683 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4684 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4685 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4686 | return Result; |
| 4687 | } |
| 4688 | |
| 4689 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4690 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4691 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4692 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4693 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4694 | NestedNameSpecifierLoc QualifierLoc |
| 4695 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4696 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4697 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4699 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4700 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4701 | TL.getKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4702 | QualifierLoc, |
| 4703 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4704 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4705 | if (Result.isNull()) |
| 4706 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4707 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4708 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4709 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4710 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4711 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4712 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4713 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4714 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4715 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4716 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4717 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4718 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4719 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4720 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4721 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4724 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4725 | QualType TreeTransform<Derived>:: |
| 4726 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4727 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4728 | NestedNameSpecifierLoc QualifierLoc; |
| 4729 | if (TL.getQualifierLoc()) { |
| 4730 | QualifierLoc |
| 4731 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4732 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4733 | return QualType(); |
| 4734 | } |
| 4735 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4736 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4737 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | template<typename Derived> |
| 4741 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4742 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4743 | DependentTemplateSpecializationTypeLoc TL, |
| 4744 | NestedNameSpecifierLoc QualifierLoc) { |
| 4745 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 4746 | |
| 4747 | TemplateArgumentListInfo NewTemplateArgs; |
| 4748 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4749 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4750 | |
| 4751 | typedef TemplateArgumentLocContainerIterator< |
| 4752 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4753 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4754 | ArgIterator(TL, TL.getNumArgs()), |
| 4755 | NewTemplateArgs)) |
| 4756 | return QualType(); |
| 4757 | |
| 4758 | QualType Result |
| 4759 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4760 | QualifierLoc, |
| 4761 | T->getIdentifier(), |
| 4762 | TL.getNameLoc(), |
| 4763 | NewTemplateArgs); |
| 4764 | if (Result.isNull()) |
| 4765 | return QualType(); |
| 4766 | |
| 4767 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4768 | QualType NamedT = ElabT->getNamedType(); |
| 4769 | |
| 4770 | // Copy information relevant to the template specialization. |
| 4771 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4772 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Chandler Carruth | 3d7e3da | 2011-04-01 02:03:23 +0000 | [diff] [blame] | 4773 | NamedTL.setTemplateNameLoc(TL.getNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4774 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4775 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4776 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4777 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4778 | |
| 4779 | // Copy information relevant to the elaborated type. |
| 4780 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4781 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4782 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4783 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4784 | DependentTemplateSpecializationTypeLoc SpecTL |
| 4785 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4786 | SpecTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4787 | SpecTL.setQualifierLoc(QualifierLoc); |
Chandler Carruth | 3d7e3da | 2011-04-01 02:03:23 +0000 | [diff] [blame] | 4788 | SpecTL.setNameLoc(TL.getNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4789 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4790 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4791 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4792 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4793 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4794 | TemplateSpecializationTypeLoc SpecTL |
| 4795 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Chandler Carruth | 3d7e3da | 2011-04-01 02:03:23 +0000 | [diff] [blame] | 4796 | SpecTL.setTemplateNameLoc(TL.getNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4797 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4798 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4799 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4800 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4801 | } |
| 4802 | return Result; |
| 4803 | } |
| 4804 | |
| 4805 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4806 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4807 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4808 | QualType Pattern |
| 4809 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4810 | if (Pattern.isNull()) |
| 4811 | return QualType(); |
| 4812 | |
| 4813 | QualType Result = TL.getType(); |
| 4814 | if (getDerived().AlwaysRebuild() || |
| 4815 | Pattern != TL.getPatternLoc().getType()) { |
| 4816 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4817 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4818 | TL.getEllipsisLoc(), |
| 4819 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4820 | if (Result.isNull()) |
| 4821 | return QualType(); |
| 4822 | } |
| 4823 | |
| 4824 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4825 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4826 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4830 | QualType |
| 4831 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4832 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4833 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4834 | TLB.pushFullCopy(TL); |
| 4835 | return TL.getType(); |
| 4836 | } |
| 4837 | |
| 4838 | template<typename Derived> |
| 4839 | QualType |
| 4840 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4841 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4842 | // ObjCObjectType is never dependent. |
| 4843 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4844 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4846 | |
| 4847 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4848 | QualType |
| 4849 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4850 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4851 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4852 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4853 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4856 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4857 | // Statement transformation |
| 4858 | //===----------------------------------------------------------------------===// |
| 4859 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4860 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4862 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4866 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4867 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4868 | return getDerived().TransformCompoundStmt(S, false); |
| 4869 | } |
| 4870 | |
| 4871 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4872 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4873 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4874 | bool IsStmtExpr) { |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4875 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4876 | bool SubStmtChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4877 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4878 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4879 | B != BEnd; ++B) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4880 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4881 | if (Result.isInvalid()) { |
| 4882 | // Immediately fail if this was a DeclStmt, since it's very |
| 4883 | // likely that this will cause problems for future statements. |
| 4884 | if (isa<DeclStmt>(*B)) |
| 4885 | return StmtError(); |
| 4886 | |
| 4887 | // Otherwise, just keep processing substatements and fail later. |
| 4888 | SubStmtInvalid = true; |
| 4889 | continue; |
| 4890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4892 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4893 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4895 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4896 | if (SubStmtInvalid) |
| 4897 | return StmtError(); |
| 4898 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4899 | if (!getDerived().AlwaysRebuild() && |
| 4900 | !SubStmtChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4901 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4902 | |
| 4903 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4904 | move_arg(Statements), |
| 4905 | S->getRBracLoc(), |
| 4906 | IsStmtExpr); |
| 4907 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4908 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4909 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4910 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4911 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4912 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4913 | { |
| 4914 | // The case value expressions are not potentially evaluated. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4915 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4917 | // Transform the left-hand case value. |
| 4918 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4919 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4920 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4921 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4922 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4923 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4924 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4925 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4927 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4928 | // Build the case statement. |
| 4929 | // Case statements are always rebuilt so that they will attached to their |
| 4930 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4931 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4932 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4933 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4934 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4935 | S->getColonLoc()); |
| 4936 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4937 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4938 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4939 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4940 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4941 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4942 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4943 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4944 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4945 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4949 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4951 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4952 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4953 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4954 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4955 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4956 | // Default statements are always rebuilt |
| 4957 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4958 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4959 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4960 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4961 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4962 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4963 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4964 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4965 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4966 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4967 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4968 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 4969 | S->getDecl()); |
| 4970 | if (!LD) |
| 4971 | return StmtError(); |
| 4972 | |
| 4973 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4974 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 4975 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4976 | cast<LabelDecl>(LD), SourceLocation(), |
| 4977 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4980 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4981 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4982 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4983 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4984 | ExprResult Cond; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4985 | VarDecl *ConditionVar = 0; |
| 4986 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4987 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4988 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4989 | getDerived().TransformDefinition( |
| 4990 | S->getConditionVariable()->getLocation(), |
| 4991 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4992 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4993 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4994 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4995 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4996 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4997 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4998 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4999 | |
| 5000 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5001 | if (S->getCond()) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5002 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 5003 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5004 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5005 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5006 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5007 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5008 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5009 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5010 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5011 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5012 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5013 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5014 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5015 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5016 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5017 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5018 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5020 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5021 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5022 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5023 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5024 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5025 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5026 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5027 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5028 | Then.get() == S->getThen() && |
| 5029 | Else.get() == S->getElse()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5030 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5032 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 5033 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5034 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5038 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5039 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5040 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5041 | ExprResult Cond; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5042 | VarDecl *ConditionVar = 0; |
| 5043 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5044 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5045 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5046 | getDerived().TransformDefinition( |
| 5047 | S->getConditionVariable()->getLocation(), |
| 5048 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5049 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5050 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5051 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 5052 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5053 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5054 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5055 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5056 | } |
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 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5059 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5060 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 5061 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5062 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5063 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5065 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5066 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5067 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5068 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5069 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5070 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5071 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 5072 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5074 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5075 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5076 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5078 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5079 | ExprResult Cond; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5080 | VarDecl *ConditionVar = 0; |
| 5081 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5082 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5083 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5084 | getDerived().TransformDefinition( |
| 5085 | S->getConditionVariable()->getLocation(), |
| 5086 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5087 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5088 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5089 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 5090 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5091 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5092 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5093 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5094 | |
| 5095 | if (S->getCond()) { |
| 5096 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5097 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 5098 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5099 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5100 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5101 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5102 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5103 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5104 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5105 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5106 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5107 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5108 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5109 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5110 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5111 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5112 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5113 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5114 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5115 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5116 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5117 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5118 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5119 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5120 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5121 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5123 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5124 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5125 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5126 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5127 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5128 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5129 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5130 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5131 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5132 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5133 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5134 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5135 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5136 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5137 | if (!getDerived().AlwaysRebuild() && |
| 5138 | Cond.get() == S->getCond() && |
| 5139 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5140 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5142 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5143 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5144 | S->getRParenLoc()); |
| 5145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5146 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5147 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5148 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5150 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5151 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5152 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5153 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5155 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5156 | ExprResult Cond; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5157 | VarDecl *ConditionVar = 0; |
| 5158 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5159 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5160 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5161 | getDerived().TransformDefinition( |
| 5162 | S->getConditionVariable()->getLocation(), |
| 5163 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5164 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5165 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5166 | } else { |
| 5167 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5168 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5169 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5170 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5171 | |
| 5172 | if (S->getCond()) { |
| 5173 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5174 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 5175 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5176 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5177 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5178 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5179 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5180 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5183 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5184 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5185 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5187 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5188 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5189 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5190 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5192 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5193 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5194 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5195 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5196 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5197 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5198 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5199 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5201 | if (!getDerived().AlwaysRebuild() && |
| 5202 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5203 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5204 | Inc.get() == S->getInc() && |
| 5205 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5206 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5207 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5208 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5209 | Init.get(), FullCond, ConditionVar, |
| 5210 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5214 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5215 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5216 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5217 | S->getLabel()); |
| 5218 | if (!LD) |
| 5219 | return StmtError(); |
| 5220 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5221 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5222 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5223 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5227 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5229 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5230 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5231 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5233 | if (!getDerived().AlwaysRebuild() && |
| 5234 | Target.get() == S->getTarget()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5235 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5236 | |
| 5237 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5238 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5242 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5244 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5245 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5247 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5248 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5250 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5253 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5254 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5255 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5256 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5257 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5258 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5259 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5261 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5262 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5265 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5266 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5267 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5268 | bool DeclChanged = false; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5269 | SmallVector<Decl *, 4> Decls; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5270 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5271 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5272 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5273 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5274 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5275 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5276 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5277 | if (Transformed != *D) |
| 5278 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5279 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5280 | Decls.push_back(Transformed); |
| 5281 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5282 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5283 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5284 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5285 | |
| 5286 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5287 | S->getStartLoc(), S->getEndLoc()); |
| 5288 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5290 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5291 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5292 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5293 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5294 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5295 | ASTOwningVector<Expr*> Exprs(getSema()); |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5296 | SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5297 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5298 | ExprResult AsmString; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5299 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5300 | |
| 5301 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5302 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5303 | // Go through the outputs. |
| 5304 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5305 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5306 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5307 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5308 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5309 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5310 | // Transform the output expr. |
| 5311 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5312 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5313 | if (Result.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 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5316 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5317 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5318 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5319 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5320 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5321 | // Go through the inputs. |
| 5322 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5323 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5324 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5325 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5326 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5327 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5328 | // Transform the input expr. |
| 5329 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5330 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5331 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5332 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5333 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5334 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5335 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5336 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5337 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5338 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5339 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5340 | return SemaRef.Owned(S); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5341 | |
| 5342 | // Go through the clobbers. |
| 5343 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5344 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5345 | |
| 5346 | // No need to transform the asm string literal. |
| 5347 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5348 | |
| 5349 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5350 | S->isSimple(), |
| 5351 | S->isVolatile(), |
| 5352 | S->getNumOutputs(), |
| 5353 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5354 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5355 | move_arg(Constraints), |
| 5356 | move_arg(Exprs), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5357 | AsmString.get(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5358 | move_arg(Clobbers), |
| 5359 | S->getRParenLoc(), |
| 5360 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | |
| 5364 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5365 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5366 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5367 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5368 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5369 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5370 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5371 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5372 | // Transform the @catch statements (if present). |
| 5373 | bool AnyCatchChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5374 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5375 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5376 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5377 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5378 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5379 | if (Catch.get() != S->getCatchStmt(I)) |
| 5380 | AnyCatchChanged = true; |
| 5381 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5382 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5383 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5384 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5385 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5386 | if (S->getFinallyStmt()) { |
| 5387 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5388 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5389 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | // If nothing changed, just retain this statement. |
| 5393 | if (!getDerived().AlwaysRebuild() && |
| 5394 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5395 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5396 | Finally.get() == S->getFinallyStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5397 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5398 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5399 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5400 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5401 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5403 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5404 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5405 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5406 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5407 | // Transform the @catch parameter, if there is one. |
| 5408 | VarDecl *Var = 0; |
| 5409 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5410 | TypeSourceInfo *TSInfo = 0; |
| 5411 | if (FromVar->getTypeSourceInfo()) { |
| 5412 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5413 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5414 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5415 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5416 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5417 | QualType T; |
| 5418 | if (TSInfo) |
| 5419 | T = TSInfo->getType(); |
| 5420 | else { |
| 5421 | T = getDerived().TransformType(FromVar->getType()); |
| 5422 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5423 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5424 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5425 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5426 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5427 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5428 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5429 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5430 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5431 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5432 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5433 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5434 | |
| 5435 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5436 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5437 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5439 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5440 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5441 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5442 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5443 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5444 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5445 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5446 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5447 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5448 | // If nothing changed, just retain this statement. |
| 5449 | if (!getDerived().AlwaysRebuild() && |
| 5450 | Body.get() == S->getFinallyBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5451 | return SemaRef.Owned(S); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5452 | |
| 5453 | // Build a new statement. |
| 5454 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5455 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5456 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5457 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5458 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5459 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5461 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5462 | if (S->getThrowExpr()) { |
| 5463 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5464 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5465 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5466 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5467 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5468 | if (!getDerived().AlwaysRebuild() && |
| 5469 | Operand.get() == S->getThrowExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5470 | return getSema().Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5471 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5472 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5473 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5474 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5475 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5476 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5477 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5478 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5479 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5480 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5481 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5482 | return StmtError(); |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 5483 | Object = |
| 5484 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 5485 | Object.get()); |
| 5486 | if (Object.isInvalid()) |
| 5487 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5489 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5490 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5491 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5492 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5494 | // If nothing change, just retain the current statement. |
| 5495 | if (!getDerived().AlwaysRebuild() && |
| 5496 | Object.get() == S->getSynchExpr() && |
| 5497 | Body.get() == S->getSynchBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5498 | return SemaRef.Owned(S); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5499 | |
| 5500 | // Build a new statement. |
| 5501 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5502 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5506 | StmtResult |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 5507 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 5508 | ObjCAutoreleasePoolStmt *S) { |
| 5509 | // Transform the body. |
| 5510 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 5511 | if (Body.isInvalid()) |
| 5512 | return StmtError(); |
| 5513 | |
| 5514 | // If nothing changed, just retain this statement. |
| 5515 | if (!getDerived().AlwaysRebuild() && |
| 5516 | Body.get() == S->getSubStmt()) |
| 5517 | return SemaRef.Owned(S); |
| 5518 | |
| 5519 | // Build a new statement. |
| 5520 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 5521 | S->getAtLoc(), Body.get()); |
| 5522 | } |
| 5523 | |
| 5524 | template<typename Derived> |
| 5525 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5526 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5527 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5528 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5529 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5530 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5531 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5532 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5533 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5534 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5535 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5536 | return StmtError(); |
John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 5537 | Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(), |
| 5538 | Collection.take()); |
| 5539 | if (Collection.isInvalid()) |
| 5540 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5541 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5542 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5543 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5544 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5545 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5546 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5547 | // If nothing changed, just retain this statement. |
| 5548 | if (!getDerived().AlwaysRebuild() && |
| 5549 | Element.get() == S->getElement() && |
| 5550 | Collection.get() == S->getCollection() && |
| 5551 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5552 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5553 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5554 | // Build a new statement. |
| 5555 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5556 | /*FIXME:*/S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5557 | Element.get(), |
| 5558 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5559 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5560 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | |
| 5564 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5565 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5566 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5567 | // Transform the exception declaration, if any. |
| 5568 | VarDecl *Var = 0; |
| 5569 | if (S->getExceptionDecl()) { |
| 5570 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5571 | TypeSourceInfo *T = getDerived().TransformType( |
| 5572 | ExceptionDecl->getTypeSourceInfo()); |
| 5573 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5574 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5575 | |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5576 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5577 | ExceptionDecl->getInnerLocStart(), |
| 5578 | ExceptionDecl->getLocation(), |
| 5579 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5580 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5581 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5584 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5585 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5586 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5587 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5588 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5589 | if (!getDerived().AlwaysRebuild() && |
| 5590 | !Var && |
| 5591 | Handler.get() == S->getHandlerBlock()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5592 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5593 | |
| 5594 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5595 | Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5596 | Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5597 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5598 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5599 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5600 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5601 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5602 | // Transform the try block itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5603 | StmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5604 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5605 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5606 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5608 | // Transform the handlers. |
| 5609 | bool HandlerChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5610 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5611 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5612 | StmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5613 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5614 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5615 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5617 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5618 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5619 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5621 | if (!getDerived().AlwaysRebuild() && |
| 5622 | TryBlock.get() == S->getTryBlock() && |
| 5623 | !HandlerChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5624 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5625 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5626 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5627 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5628 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5629 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5630 | template<typename Derived> |
| 5631 | StmtResult |
| 5632 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5633 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 5634 | if (Range.isInvalid()) |
| 5635 | return StmtError(); |
| 5636 | |
| 5637 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 5638 | if (BeginEnd.isInvalid()) |
| 5639 | return StmtError(); |
| 5640 | |
| 5641 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 5642 | if (Cond.isInvalid()) |
| 5643 | return StmtError(); |
| 5644 | |
| 5645 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 5646 | if (Inc.isInvalid()) |
| 5647 | return StmtError(); |
| 5648 | |
| 5649 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 5650 | if (LoopVar.isInvalid()) |
| 5651 | return StmtError(); |
| 5652 | |
| 5653 | StmtResult NewStmt = S; |
| 5654 | if (getDerived().AlwaysRebuild() || |
| 5655 | Range.get() != S->getRangeStmt() || |
| 5656 | BeginEnd.get() != S->getBeginEndStmt() || |
| 5657 | Cond.get() != S->getCond() || |
| 5658 | Inc.get() != S->getInc() || |
| 5659 | LoopVar.get() != S->getLoopVarStmt()) |
| 5660 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5661 | S->getColonLoc(), Range.get(), |
| 5662 | BeginEnd.get(), Cond.get(), |
| 5663 | Inc.get(), LoopVar.get(), |
| 5664 | S->getRParenLoc()); |
| 5665 | |
| 5666 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 5667 | if (Body.isInvalid()) |
| 5668 | return StmtError(); |
| 5669 | |
| 5670 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 5671 | // it now so we have a new statement to attach the body to. |
| 5672 | if (Body.get() != S->getBody() && NewStmt.get() == S) |
| 5673 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5674 | S->getColonLoc(), Range.get(), |
| 5675 | BeginEnd.get(), Cond.get(), |
| 5676 | Inc.get(), LoopVar.get(), |
| 5677 | S->getRParenLoc()); |
| 5678 | |
| 5679 | if (NewStmt.get() == S) |
| 5680 | return SemaRef.Owned(S); |
| 5681 | |
| 5682 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 5683 | } |
| 5684 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5685 | template<typename Derived> |
| 5686 | StmtResult |
| 5687 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 5688 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5689 | if(TryBlock.isInvalid()) return StmtError(); |
| 5690 | |
| 5691 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 5692 | if(!getDerived().AlwaysRebuild() && |
| 5693 | TryBlock.get() == S->getTryBlock() && |
| 5694 | Handler.get() == S->getHandler()) |
| 5695 | return SemaRef.Owned(S); |
| 5696 | |
| 5697 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 5698 | S->getTryLoc(), |
| 5699 | TryBlock.take(), |
| 5700 | Handler.take()); |
| 5701 | } |
| 5702 | |
| 5703 | template<typename Derived> |
| 5704 | StmtResult |
| 5705 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 5706 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5707 | if(Block.isInvalid()) return StmtError(); |
| 5708 | |
| 5709 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 5710 | Block.take()); |
| 5711 | } |
| 5712 | |
| 5713 | template<typename Derived> |
| 5714 | StmtResult |
| 5715 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 5716 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 5717 | if(FilterExpr.isInvalid()) return StmtError(); |
| 5718 | |
| 5719 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5720 | if(Block.isInvalid()) return StmtError(); |
| 5721 | |
| 5722 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 5723 | FilterExpr.take(), |
| 5724 | Block.take()); |
| 5725 | } |
| 5726 | |
| 5727 | template<typename Derived> |
| 5728 | StmtResult |
| 5729 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 5730 | if(isa<SEHFinallyStmt>(Handler)) |
| 5731 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 5732 | else |
| 5733 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 5734 | } |
| 5735 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5736 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5737 | // Expression transformation |
| 5738 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5739 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5740 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5741 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5742 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5743 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5744 | |
| 5745 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5746 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5747 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5748 | NestedNameSpecifierLoc QualifierLoc; |
| 5749 | if (E->getQualifierLoc()) { |
| 5750 | QualifierLoc |
| 5751 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5752 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5753 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5754 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5755 | |
| 5756 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5757 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5758 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5759 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5760 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5761 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5762 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5763 | if (NameInfo.getName()) { |
| 5764 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5765 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5766 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5767 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5768 | |
| 5769 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5770 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5771 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5772 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5773 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5774 | |
| 5775 | // Mark it referenced in the new context regardless. |
| 5776 | // FIXME: this is a bit instantiation-specific. |
| 5777 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5778 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5779 | return SemaRef.Owned(E); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5780 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5781 | |
| 5782 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5783 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5784 | TemplateArgs = &TransArgs; |
| 5785 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5786 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5787 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5788 | E->getNumTemplateArgs(), |
| 5789 | TransArgs)) |
| 5790 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5791 | } |
| 5792 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5793 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 5794 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5797 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5798 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5799 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5800 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5801 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5802 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5803 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5804 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5805 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5806 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5807 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5808 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5809 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5810 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5811 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5812 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5813 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5815 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5816 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5817 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5818 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5819 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5820 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5821 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5822 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5823 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5824 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5828 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 5829 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 5830 | ExprResult ControllingExpr = |
| 5831 | getDerived().TransformExpr(E->getControllingExpr()); |
| 5832 | if (ControllingExpr.isInvalid()) |
| 5833 | return ExprError(); |
| 5834 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5835 | SmallVector<Expr *, 4> AssocExprs; |
| 5836 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 5837 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 5838 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 5839 | if (TS) { |
| 5840 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 5841 | if (!AssocType) |
| 5842 | return ExprError(); |
| 5843 | AssocTypes.push_back(AssocType); |
| 5844 | } else { |
| 5845 | AssocTypes.push_back(0); |
| 5846 | } |
| 5847 | |
| 5848 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 5849 | if (AssocExpr.isInvalid()) |
| 5850 | return ExprError(); |
| 5851 | AssocExprs.push_back(AssocExpr.release()); |
| 5852 | } |
| 5853 | |
| 5854 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 5855 | E->getDefaultLoc(), |
| 5856 | E->getRParenLoc(), |
| 5857 | ControllingExpr.release(), |
| 5858 | AssocTypes.data(), |
| 5859 | AssocExprs.data(), |
| 5860 | E->getNumAssocs()); |
| 5861 | } |
| 5862 | |
| 5863 | template<typename Derived> |
| 5864 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5865 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5866 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5867 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5868 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5869 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5870 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5871 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5873 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5874 | E->getRParen()); |
| 5875 | } |
| 5876 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5877 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5878 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5879 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5880 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5881 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5882 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5883 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5884 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5885 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5886 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5887 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5888 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5889 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5891 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5892 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5893 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5894 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5895 | // Transform the type. |
| 5896 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5897 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5898 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5899 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5900 | // Transform all of the components into components similar to what the |
| 5901 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5902 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5903 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5904 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5905 | // template code that we don't care. |
| 5906 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5907 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5908 | typedef OffsetOfExpr::OffsetOfNode Node; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5909 | SmallVector<Component, 4> Components; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5910 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5911 | const Node &ON = E->getComponent(I); |
| 5912 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5913 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 5914 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 5915 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5916 | switch (ON.getKind()) { |
| 5917 | case Node::Array: { |
| 5918 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5919 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5920 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5921 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5922 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5923 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5924 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5925 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5926 | break; |
| 5927 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5928 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5929 | case Node::Field: |
| 5930 | case Node::Identifier: |
| 5931 | Comp.isBrackets = false; |
| 5932 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5933 | if (!Comp.U.IdentInfo) |
| 5934 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5935 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5936 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5937 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5938 | case Node::Base: |
| 5939 | // Will be recomputed during the rebuild. |
| 5940 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5941 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5942 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5943 | Components.push_back(Comp); |
| 5944 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5945 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5946 | // If nothing changed, retain the existing expression. |
| 5947 | if (!getDerived().AlwaysRebuild() && |
| 5948 | Type == E->getTypeSourceInfo() && |
| 5949 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5950 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5951 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5952 | // Build a new offsetof expression. |
| 5953 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5954 | Components.data(), Components.size(), |
| 5955 | E->getRParenLoc()); |
| 5956 | } |
| 5957 | |
| 5958 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5959 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5960 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5961 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5962 | "opaque value expression requires transformation"); |
| 5963 | return SemaRef.Owned(E); |
| 5964 | } |
| 5965 | |
| 5966 | template<typename Derived> |
| 5967 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5968 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 5969 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5970 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5971 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5972 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5973 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5974 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5975 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5976 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5977 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5978 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5979 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5980 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 5981 | E->getKind(), |
| 5982 | E->getSourceRange()); |
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 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5985 | ExprResult SubExpr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5986 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5987 | // C++0x [expr.sizeof]p1: |
| 5988 | // The operand is either an expression, which is an unevaluated operand |
| 5989 | // [...] |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5990 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5991 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5992 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5993 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5994 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5996 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5997 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5999 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 6000 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 6001 | E->getOperatorLoc(), |
| 6002 | E->getKind(), |
| 6003 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6006 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6007 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6008 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6009 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6010 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6011 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6012 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6013 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6014 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6015 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6016 | |
| 6017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6018 | if (!getDerived().AlwaysRebuild() && |
| 6019 | LHS.get() == E->getLHS() && |
| 6020 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6021 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6022 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6023 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6024 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6025 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6026 | E->getRBracketLoc()); |
| 6027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6028 | |
| 6029 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6030 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6031 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6032 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6033 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6034 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6035 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6036 | |
| 6037 | // Transform arguments. |
| 6038 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6039 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6040 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6041 | &ArgChanged)) |
| 6042 | return ExprError(); |
| 6043 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6044 | if (!getDerived().AlwaysRebuild() && |
| 6045 | Callee.get() == E->getCallee() && |
| 6046 | !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6047 | return SemaRef.Owned(E); |
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 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6050 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6051 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6052 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6053 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6054 | E->getRParenLoc()); |
| 6055 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6056 | |
| 6057 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6058 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6059 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6060 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6061 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6062 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6063 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6064 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6065 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6066 | QualifierLoc |
| 6067 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6068 | |
| 6069 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6070 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 6071 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6072 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 6073 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6074 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 6075 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6076 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6077 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6078 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6079 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 6080 | if (FoundDecl == E->getMemberDecl()) { |
| 6081 | FoundDecl = Member; |
| 6082 | } else { |
| 6083 | FoundDecl = cast_or_null<NamedDecl>( |
| 6084 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 6085 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6086 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6089 | if (!getDerived().AlwaysRebuild() && |
| 6090 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6091 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6092 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6093 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6094 | !E->hasExplicitTemplateArgs()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6095 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6096 | // Mark it referenced in the new context regardless. |
| 6097 | // FIXME: this is a bit instantiation-specific. |
| 6098 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6099 | return SemaRef.Owned(E); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 6100 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6101 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6102 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6103 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6104 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 6105 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6106 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6107 | E->getNumTemplateArgs(), |
| 6108 | TransArgs)) |
| 6109 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6110 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6112 | // FIXME: Bogus source location for the operator |
| 6113 | SourceLocation FakeOperatorLoc |
| 6114 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 6115 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6116 | // FIXME: to do this check properly, we will need to preserve the |
| 6117 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6118 | // base (and therefore couldn't do the check) and a |
| 6119 | // nested-name-qualifier (and therefore could do the lookup). |
| 6120 | NamedDecl *FirstQualifierInScope = 0; |
| 6121 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6122 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6123 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6124 | QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6125 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6126 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6127 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6128 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6129 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6130 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6133 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6134 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6135 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6136 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6137 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6138 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6139 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6140 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6141 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6142 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | if (!getDerived().AlwaysRebuild() && |
| 6145 | LHS.get() == E->getLHS() && |
| 6146 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6147 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6148 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6149 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6150 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6151 | } |
| 6152 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6153 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6154 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6155 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6156 | CompoundAssignOperator *E) { |
| 6157 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6158 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6159 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6160 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6161 | ExprResult TreeTransform<Derived>:: |
| 6162 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6163 | // Just rebuild the common and RHS expressions and see whether we |
| 6164 | // get any changes. |
| 6165 | |
| 6166 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6167 | if (commonExpr.isInvalid()) |
| 6168 | return ExprError(); |
| 6169 | |
| 6170 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6171 | if (rhs.isInvalid()) |
| 6172 | return ExprError(); |
| 6173 | |
| 6174 | if (!getDerived().AlwaysRebuild() && |
| 6175 | commonExpr.get() == e->getCommon() && |
| 6176 | rhs.get() == e->getFalseExpr()) |
| 6177 | return SemaRef.Owned(e); |
| 6178 | |
| 6179 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6180 | e->getQuestionLoc(), |
| 6181 | 0, |
| 6182 | e->getColonLoc(), |
| 6183 | rhs.get()); |
| 6184 | } |
| 6185 | |
| 6186 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6187 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6188 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6189 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6190 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6191 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6192 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6193 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6194 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6195 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6196 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6197 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6198 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6199 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6200 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6201 | if (!getDerived().AlwaysRebuild() && |
| 6202 | Cond.get() == E->getCond() && |
| 6203 | LHS.get() == E->getLHS() && |
| 6204 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6205 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6206 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6207 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6208 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6209 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6210 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6211 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6212 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6213 | |
| 6214 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6215 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6216 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6217 | // Implicit casts are eliminated during transformation, since they |
| 6218 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6219 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6220 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6222 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6223 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6224 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6225 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6226 | if (!Type) |
| 6227 | return ExprError(); |
| 6228 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6229 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6230 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6231 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6232 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6233 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6234 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6235 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6236 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6237 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6238 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6239 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6240 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6241 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6242 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6245 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6246 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6247 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6248 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6249 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6250 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6251 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6252 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6253 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6254 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6255 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6257 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6258 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6259 | Init.get() == E->getInitializer()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6260 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6261 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6262 | // Note: the expression type doesn't necessarily match the |
| 6263 | // type-as-written, but that's okay, because it should always be |
| 6264 | // derivable from the initializer. |
| 6265 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6266 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6267 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6268 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6269 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6271 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6272 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6273 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6274 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6275 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6276 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6277 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6278 | if (!getDerived().AlwaysRebuild() && |
| 6279 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6280 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6282 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6283 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6284 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6285 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6286 | E->getAccessorLoc(), |
| 6287 | E->getAccessor()); |
| 6288 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6290 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6291 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6292 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6293 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6295 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6296 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 6297 | Inits, &InitChanged)) |
| 6298 | return ExprError(); |
| 6299 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6300 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6301 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6302 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6303 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6304 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6305 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6306 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6307 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6308 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6309 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6310 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6311 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6312 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6313 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6314 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6315 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6316 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6317 | // transform the designators. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6318 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6319 | bool ExprChanged = false; |
| 6320 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6321 | DEnd = E->designators_end(); |
| 6322 | D != DEnd; ++D) { |
| 6323 | if (D->isFieldDesignator()) { |
| 6324 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6325 | D->getDotLoc(), |
| 6326 | D->getFieldLoc())); |
| 6327 | continue; |
| 6328 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6329 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6330 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6331 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6332 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6333 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6334 | |
| 6335 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6336 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6337 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6338 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6339 | ArrayExprs.push_back(Index.release()); |
| 6340 | continue; |
| 6341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6342 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6343 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6344 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6345 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6346 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6347 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6348 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6349 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6350 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6351 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6352 | |
| 6353 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6354 | End.get(), |
| 6355 | D->getLBracketLoc(), |
| 6356 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6357 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6358 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6359 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6360 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6361 | ArrayExprs.push_back(Start.release()); |
| 6362 | ArrayExprs.push_back(End.release()); |
| 6363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6364 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6365 | if (!getDerived().AlwaysRebuild() && |
| 6366 | Init.get() == E->getInit() && |
| 6367 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6368 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6369 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6370 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6371 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6372 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6373 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6374 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6375 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6376 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6377 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6378 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6379 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6380 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6381 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6382 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6383 | QualType T = getDerived().TransformType(E->getType()); |
| 6384 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6385 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6386 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6387 | if (!getDerived().AlwaysRebuild() && |
| 6388 | T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6389 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6390 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6391 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6392 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6393 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6394 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6395 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6396 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6397 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6398 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6399 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6400 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6401 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6402 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6403 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6404 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6405 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6406 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6407 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6408 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6409 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6410 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6411 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6415 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6416 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6417 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6418 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6419 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6420 | &ArgumentChanged)) |
| 6421 | return ExprError(); |
| 6422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6423 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6424 | move_arg(Inits), |
| 6425 | E->getRParenLoc()); |
| 6426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6428 | /// \brief Transform an address-of-label expression. |
| 6429 | /// |
| 6430 | /// By default, the transformation of an address-of-label expression always |
| 6431 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6432 | /// the corresponding label statement by semantic analysis. |
| 6433 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6434 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6435 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6436 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6437 | E->getLabel()); |
| 6438 | if (!LD) |
| 6439 | return ExprError(); |
| 6440 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6441 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6442 | cast<LabelDecl>(LD)); |
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 | |
| 6445 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6446 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6447 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6448 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6449 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 6450 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6451 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6452 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6453 | if (!getDerived().AlwaysRebuild() && |
| 6454 | SubStmt.get() == E->getSubStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6455 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6456 | |
| 6457 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6458 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | E->getRParenLoc()); |
| 6460 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6461 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6462 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6463 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6464 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6465 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6466 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6467 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6468 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6469 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6470 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6471 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6472 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6473 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6474 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6475 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6476 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6477 | if (!getDerived().AlwaysRebuild() && |
| 6478 | Cond.get() == E->getCond() && |
| 6479 | LHS.get() == E->getLHS() && |
| 6480 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6481 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6482 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6483 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6484 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6485 | E->getRParenLoc()); |
| 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 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6489 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6490 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6491 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6492 | } |
| 6493 | |
| 6494 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6495 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6496 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6497 | switch (E->getOperator()) { |
| 6498 | case OO_New: |
| 6499 | case OO_Delete: |
| 6500 | case OO_Array_New: |
| 6501 | case OO_Array_Delete: |
| 6502 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6503 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6504 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6505 | case OO_Call: { |
| 6506 | // This is a call to an object's operator(). |
| 6507 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6508 | |
| 6509 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6510 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6511 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6512 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6513 | |
| 6514 | // FIXME: Poor location information |
| 6515 | SourceLocation FakeLParenLoc |
| 6516 | = SemaRef.PP.getLocForEndOfToken( |
| 6517 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6518 | |
| 6519 | // Transform the call arguments. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6520 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6521 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6522 | Args)) |
| 6523 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6524 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6525 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6526 | move_arg(Args), |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6527 | E->getLocEnd()); |
| 6528 | } |
| 6529 | |
| 6530 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6531 | case OO_##Name: |
| 6532 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6533 | #include "clang/Basic/OperatorKinds.def" |
| 6534 | case OO_Subscript: |
| 6535 | // Handled below. |
| 6536 | break; |
| 6537 | |
| 6538 | case OO_Conditional: |
| 6539 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6540 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6541 | |
| 6542 | case OO_None: |
| 6543 | case NUM_OVERLOADED_OPERATORS: |
| 6544 | llvm_unreachable("not an overloaded operator?"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6545 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6546 | } |
| 6547 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6548 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6549 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6550 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6551 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6552 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6553 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6554 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6555 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6556 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6557 | if (E->getNumArgs() == 2) { |
| 6558 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6559 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6560 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6562 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6563 | if (!getDerived().AlwaysRebuild() && |
| 6564 | Callee.get() == E->getCallee() && |
| 6565 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6566 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6569 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6570 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6571 | Callee.get(), |
| 6572 | First.get(), |
| 6573 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6574 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6575 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6576 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6577 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6578 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6579 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6582 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6583 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6584 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6585 | // Transform the callee. |
| 6586 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6587 | if (Callee.isInvalid()) |
| 6588 | return ExprError(); |
| 6589 | |
| 6590 | // Transform exec config. |
| 6591 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6592 | if (EC.isInvalid()) |
| 6593 | return ExprError(); |
| 6594 | |
| 6595 | // Transform arguments. |
| 6596 | bool ArgChanged = false; |
| 6597 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6598 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6599 | &ArgChanged)) |
| 6600 | return ExprError(); |
| 6601 | |
| 6602 | if (!getDerived().AlwaysRebuild() && |
| 6603 | Callee.get() == E->getCallee() && |
| 6604 | !ArgChanged) |
| 6605 | return SemaRef.Owned(E); |
| 6606 | |
| 6607 | // FIXME: Wrong source location information for the '('. |
| 6608 | SourceLocation FakeLParenLoc |
| 6609 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6610 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6611 | move_arg(Args), |
| 6612 | E->getRParenLoc(), EC.get()); |
| 6613 | } |
| 6614 | |
| 6615 | template<typename Derived> |
| 6616 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6617 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6618 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6619 | if (!Type) |
| 6620 | return ExprError(); |
| 6621 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6622 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6623 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6624 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6625 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6626 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6627 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6628 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6629 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6630 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6632 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6633 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6634 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6635 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6636 | SourceLocation FakeRParenLoc |
| 6637 | = SemaRef.PP.getLocForEndOfToken( |
| 6638 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6639 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6640 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6641 | FakeLAngleLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6642 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6643 | FakeRAngleLoc, |
| 6644 | FakeRAngleLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6645 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6646 | FakeRParenLoc); |
| 6647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6648 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6649 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6650 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6651 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6652 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6654 | |
| 6655 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6656 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6657 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6658 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6659 | } |
| 6660 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6661 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6662 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6663 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6664 | CXXReinterpretCastExpr *E) { |
| 6665 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6666 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6667 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6668 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6669 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6670 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6671 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6673 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6674 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6675 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6676 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6677 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6678 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6679 | if (!Type) |
| 6680 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6681 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6682 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6683 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6684 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6685 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6686 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6687 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6688 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6689 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6690 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6691 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6692 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6693 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6694 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6695 | E->getRParenLoc()); |
| 6696 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6698 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6699 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6700 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6701 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6702 | TypeSourceInfo *TInfo |
| 6703 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6704 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6705 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6706 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6707 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6708 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6709 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6710 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6711 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6712 | E->getLocStart(), |
| 6713 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6714 | E->getLocEnd()); |
| 6715 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6716 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6717 | // We don't know whether the expression is potentially evaluated until |
| 6718 | // after we perform semantic analysis, so the expression is potentially |
| 6719 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6720 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6721 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6722 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6723 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6724 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6725 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6726 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6727 | if (!getDerived().AlwaysRebuild() && |
| 6728 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6729 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6730 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6731 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6732 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6733 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6734 | E->getLocEnd()); |
| 6735 | } |
| 6736 | |
| 6737 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6738 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6739 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6740 | if (E->isTypeOperand()) { |
| 6741 | TypeSourceInfo *TInfo |
| 6742 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6743 | if (!TInfo) |
| 6744 | return ExprError(); |
| 6745 | |
| 6746 | if (!getDerived().AlwaysRebuild() && |
| 6747 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6748 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6749 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 6750 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6751 | E->getLocStart(), |
| 6752 | TInfo, |
| 6753 | E->getLocEnd()); |
| 6754 | } |
| 6755 | |
| 6756 | // We don't know whether the expression is potentially evaluated until |
| 6757 | // after we perform semantic analysis, so the expression is potentially |
| 6758 | // potentially evaluated. |
| 6759 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6760 | |
| 6761 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6762 | if (SubExpr.isInvalid()) |
| 6763 | return ExprError(); |
| 6764 | |
| 6765 | if (!getDerived().AlwaysRebuild() && |
| 6766 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6767 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6768 | |
| 6769 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6770 | E->getLocStart(), |
| 6771 | SubExpr.get(), |
| 6772 | E->getLocEnd()); |
| 6773 | } |
| 6774 | |
| 6775 | template<typename Derived> |
| 6776 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6777 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6778 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6779 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6780 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6781 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6782 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6783 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6784 | CXXNullPtrLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6785 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6786 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6787 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6788 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6789 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6790 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6791 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 6792 | QualType T; |
| 6793 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 6794 | T = MD->getThisType(getSema().Context); |
| 6795 | else |
| 6796 | T = getSema().Context.getPointerType( |
| 6797 | getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6798 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6799 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6800 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6801 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6802 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6804 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6805 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6806 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6807 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6808 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6809 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6810 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6811 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6812 | if (!getDerived().AlwaysRebuild() && |
| 6813 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6814 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6815 | |
Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 6816 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 6817 | E->isThrownVariableInScope()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6819 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6820 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6821 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6822 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6823 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6824 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6825 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6826 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6827 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6828 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6829 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6830 | Param == E->getParam()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6831 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6832 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6833 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6834 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6835 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6836 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6837 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6838 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6839 | CXXScalarValueInitExpr *E) { |
| 6840 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6841 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6842 | return ExprError(); |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6844 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6845 | T == E->getTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6846 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6847 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6848 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6849 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6850 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6852 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6853 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6854 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6855 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6856 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6857 | TypeSourceInfo *AllocTypeInfo |
| 6858 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6859 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6860 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6862 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6863 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6864 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6865 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6866 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6867 | // Transform the placement arguments (if any). |
| 6868 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6869 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6870 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6871 | E->getNumPlacementArgs(), true, |
| 6872 | PlacementArgs, &ArgumentChanged)) |
| 6873 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6874 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6875 | // transform the constructor arguments (if any). |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6876 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6877 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6878 | ConstructorArgs, &ArgumentChanged)) |
| 6879 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6880 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6881 | // Transform constructor, new operator, and delete operator. |
| 6882 | CXXConstructorDecl *Constructor = 0; |
| 6883 | if (E->getConstructor()) { |
| 6884 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6885 | getDerived().TransformDecl(E->getLocStart(), |
| 6886 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6887 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6888 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | FunctionDecl *OperatorNew = 0; |
| 6892 | if (E->getOperatorNew()) { |
| 6893 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6894 | getDerived().TransformDecl(E->getLocStart(), |
| 6895 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6896 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6897 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | FunctionDecl *OperatorDelete = 0; |
| 6901 | if (E->getOperatorDelete()) { |
| 6902 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6903 | getDerived().TransformDecl(E->getLocStart(), |
| 6904 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6905 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6906 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6907 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6908 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6909 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6910 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6911 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6912 | Constructor == E->getConstructor() && |
| 6913 | OperatorNew == E->getOperatorNew() && |
| 6914 | OperatorDelete == E->getOperatorDelete() && |
| 6915 | !ArgumentChanged) { |
| 6916 | // Mark any declarations we need as referenced. |
| 6917 | // FIXME: instantiation-specific. |
| 6918 | if (Constructor) |
| 6919 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6920 | if (OperatorNew) |
| 6921 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6922 | if (OperatorDelete) |
| 6923 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 6924 | |
| 6925 | if (E->isArray() && Constructor && |
| 6926 | !E->getAllocatedType()->isDependentType()) { |
| 6927 | QualType ElementType |
| 6928 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 6929 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 6930 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 6931 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
| 6932 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor); |
| 6933 | } |
| 6934 | } |
| 6935 | } |
| 6936 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6937 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6939 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6940 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6941 | if (!ArraySize.get()) { |
| 6942 | // If no array size was specified, but the new expression was |
| 6943 | // instantiated with an array type (e.g., "new T" where T is |
| 6944 | // instantiated with "int[4]"), extract the outer bound from the |
| 6945 | // array type as our array size. We do this with constant and |
| 6946 | // dependently-sized array types. |
| 6947 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6948 | if (!ArrayT) { |
| 6949 | // Do nothing |
| 6950 | } else if (const ConstantArrayType *ConsArrayT |
| 6951 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6952 | ArraySize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6953 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6954 | ConsArrayT->getSize(), |
| 6955 | SemaRef.Context.getSizeType(), |
| 6956 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6957 | AllocType = ConsArrayT->getElementType(); |
| 6958 | } else if (const DependentSizedArrayType *DepArrayT |
| 6959 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6960 | if (DepArrayT->getSizeExpr()) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6961 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6962 | AllocType = DepArrayT->getElementType(); |
| 6963 | } |
| 6964 | } |
| 6965 | } |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6966 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6967 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6968 | E->isGlobalNew(), |
| 6969 | /*FIXME:*/E->getLocStart(), |
| 6970 | move_arg(PlacementArgs), |
| 6971 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6972 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6973 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6974 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6975 | ArraySize.get(), |
Douglas Gregor | 3bdcff5 | 2011-06-27 16:55:54 +0000 | [diff] [blame] | 6976 | /*FIXME:*/E->hasInitializer() |
| 6977 | ? E->getLocStart() |
| 6978 | : SourceLocation(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6979 | move_arg(ConstructorArgs), |
Douglas Gregor | 3bdcff5 | 2011-06-27 16:55:54 +0000 | [diff] [blame] | 6980 | /*FIXME:*/E->hasInitializer() |
| 6981 | ? E->getLocEnd() |
| 6982 | : SourceLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6983 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6984 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6985 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6986 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6987 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6988 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6989 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6990 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6991 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6992 | // Transform the delete operator, if known. |
| 6993 | FunctionDecl *OperatorDelete = 0; |
| 6994 | if (E->getOperatorDelete()) { |
| 6995 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6996 | getDerived().TransformDecl(E->getLocStart(), |
| 6997 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6998 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6999 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7000 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7001 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7002 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7003 | Operand.get() == E->getArgument() && |
| 7004 | OperatorDelete == E->getOperatorDelete()) { |
| 7005 | // Mark any declarations we need as referenced. |
| 7006 | // FIXME: instantiation-specific. |
| 7007 | if (OperatorDelete) |
| 7008 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 7009 | |
| 7010 | if (!E->getArgument()->isTypeDependent()) { |
| 7011 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 7012 | E->getDestroyedType()); |
| 7013 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 7014 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 7015 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 7016 | SemaRef.LookupDestructor(Record)); |
| 7017 | } |
| 7018 | } |
| 7019 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7020 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7023 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 7024 | E->isGlobalDelete(), |
| 7025 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7026 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7028 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7029 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7030 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7031 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7032 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7033 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7034 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7035 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7036 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7037 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7038 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7039 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7040 | E->getOperatorLoc(), |
| 7041 | E->isArrow()? tok::arrow : tok::period, |
| 7042 | ObjectTypePtr, |
| 7043 | MayBePseudoDestructor); |
| 7044 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7045 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7046 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7047 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7048 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 7049 | if (QualifierLoc) { |
| 7050 | QualifierLoc |
| 7051 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 7052 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7053 | return ExprError(); |
| 7054 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7055 | CXXScopeSpec SS; |
| 7056 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7057 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7058 | PseudoDestructorTypeStorage Destroyed; |
| 7059 | if (E->getDestroyedTypeInfo()) { |
| 7060 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7061 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 7062 | ObjectType, 0, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7063 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7064 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7065 | Destroyed = DestroyedTypeInfo; |
| 7066 | } else if (ObjectType->isDependentType()) { |
| 7067 | // We aren't likely to be able to resolve the identifier down to a type |
| 7068 | // now anyway, so just retain the identifier. |
| 7069 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 7070 | E->getDestroyedTypeLoc()); |
| 7071 | } else { |
| 7072 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7073 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7074 | *E->getDestroyedTypeIdentifier(), |
| 7075 | E->getDestroyedTypeLoc(), |
| 7076 | /*Scope=*/0, |
| 7077 | SS, ObjectTypePtr, |
| 7078 | false); |
| 7079 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7080 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7081 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7082 | Destroyed |
| 7083 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 7084 | E->getDestroyedTypeLoc()); |
| 7085 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7086 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7087 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 7088 | if (E->getScopeTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7089 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7090 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7091 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7092 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7093 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7094 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7095 | E->getOperatorLoc(), |
| 7096 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7097 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7098 | ScopeTypeInfo, |
| 7099 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7100 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7101 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7102 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7103 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7104 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7105 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7106 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7107 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7108 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 7109 | Sema::LookupOrdinaryName); |
| 7110 | |
| 7111 | // Transform all the decls. |
| 7112 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 7113 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7114 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7115 | getDerived().TransformDecl(Old->getNameLoc(), |
| 7116 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7117 | if (!InstD) { |
| 7118 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7119 | // This can happen because of dependent hiding. |
| 7120 | if (isa<UsingShadowDecl>(*I)) |
| 7121 | continue; |
| 7122 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7123 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7124 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7125 | |
| 7126 | // Expand using declarations. |
| 7127 | if (isa<UsingDecl>(InstD)) { |
| 7128 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7129 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7130 | E = UD->shadow_end(); I != E; ++I) |
| 7131 | R.addDecl(*I); |
| 7132 | continue; |
| 7133 | } |
| 7134 | |
| 7135 | R.addDecl(InstD); |
| 7136 | } |
| 7137 | |
| 7138 | // Resolve a kind, but don't do any further analysis. If it's |
| 7139 | // ambiguous, the callee needs to deal with it. |
| 7140 | R.resolveKind(); |
| 7141 | |
| 7142 | // Rebuild the nested-name qualifier, if present. |
| 7143 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7144 | if (Old->getQualifierLoc()) { |
| 7145 | NestedNameSpecifierLoc QualifierLoc |
| 7146 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7147 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7148 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7149 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7150 | SS.Adopt(QualifierLoc); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7151 | } |
| 7152 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7153 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7154 | CXXRecordDecl *NamingClass |
| 7155 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7156 | Old->getNameLoc(), |
| 7157 | Old->getNamingClass())); |
| 7158 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7159 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7160 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7161 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | // If we have no template arguments, it's a normal declaration name. |
| 7165 | if (!Old->hasExplicitTemplateArgs()) |
| 7166 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7167 | |
| 7168 | // If we have template arguments, rebuild them, then rebuild the |
| 7169 | // templateid expression. |
| 7170 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7171 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7172 | Old->getNumTemplateArgs(), |
| 7173 | TransArgs)) |
| 7174 | return ExprError(); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7175 | |
| 7176 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 7177 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7180 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7181 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7182 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7183 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7184 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7185 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7186 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7187 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7188 | T == E->getQueriedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7189 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7190 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7191 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7192 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7193 | T, |
| 7194 | E->getLocEnd()); |
| 7195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7197 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7198 | ExprResult |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7199 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7200 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7201 | if (!LhsT) |
| 7202 | return ExprError(); |
| 7203 | |
| 7204 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7205 | if (!RhsT) |
| 7206 | return ExprError(); |
| 7207 | |
| 7208 | if (!getDerived().AlwaysRebuild() && |
| 7209 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7210 | return SemaRef.Owned(E); |
| 7211 | |
| 7212 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7213 | E->getLocStart(), |
| 7214 | LhsT, RhsT, |
| 7215 | E->getLocEnd()); |
| 7216 | } |
| 7217 | |
| 7218 | template<typename Derived> |
| 7219 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7220 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7221 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7222 | if (!T) |
| 7223 | return ExprError(); |
| 7224 | |
| 7225 | if (!getDerived().AlwaysRebuild() && |
| 7226 | T == E->getQueriedTypeSourceInfo()) |
| 7227 | return SemaRef.Owned(E); |
| 7228 | |
| 7229 | ExprResult SubExpr; |
| 7230 | { |
| 7231 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7232 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7233 | if (SubExpr.isInvalid()) |
| 7234 | return ExprError(); |
| 7235 | |
| 7236 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 7237 | return SemaRef.Owned(E); |
| 7238 | } |
| 7239 | |
| 7240 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 7241 | E->getLocStart(), |
| 7242 | T, |
| 7243 | SubExpr.get(), |
| 7244 | E->getLocEnd()); |
| 7245 | } |
| 7246 | |
| 7247 | template<typename Derived> |
| 7248 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 7249 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 7250 | ExprResult SubExpr; |
| 7251 | { |
| 7252 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7253 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 7254 | if (SubExpr.isInvalid()) |
| 7255 | return ExprError(); |
| 7256 | |
| 7257 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 7258 | return SemaRef.Owned(E); |
| 7259 | } |
| 7260 | |
| 7261 | return getDerived().RebuildExpressionTrait( |
| 7262 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 7263 | } |
| 7264 | |
| 7265 | template<typename Derived> |
| 7266 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7267 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7268 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7269 | NestedNameSpecifierLoc QualifierLoc |
| 7270 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7271 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7272 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7273 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7274 | // TODO: If this is a conversion-function-id, verify that the |
| 7275 | // destination type name (if present) resolves the same way after |
| 7276 | // instantiation as it did in the local scope. |
| 7277 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7278 | DeclarationNameInfo NameInfo |
| 7279 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 7280 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7281 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7282 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7283 | if (!E->hasExplicitTemplateArgs()) { |
| 7284 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7285 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7286 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 7287 | // if name has not changed, DNLoc has not changed either. |
| 7288 | NameInfo.getName() == E->getDeclName()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7289 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7290 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7291 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7292 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7293 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 7294 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7295 | |
| 7296 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7297 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7298 | E->getNumTemplateArgs(), |
| 7299 | TransArgs)) |
| 7300 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7301 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7302 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7303 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7304 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7305 | } |
| 7306 | |
| 7307 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7308 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7309 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7310 | // CXXConstructExprs are always implicit, so when we have a |
| 7311 | // 1-argument construction we just transform that argument. |
| 7312 | if (E->getNumArgs() == 1 || |
| 7313 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 7314 | return getDerived().TransformExpr(E->getArg(0)); |
| 7315 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7316 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7317 | |
| 7318 | QualType T = getDerived().TransformType(E->getType()); |
| 7319 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7320 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7321 | |
| 7322 | CXXConstructorDecl *Constructor |
| 7323 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7324 | getDerived().TransformDecl(E->getLocStart(), |
| 7325 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7326 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7327 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7328 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7329 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7330 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7331 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7332 | &ArgumentChanged)) |
| 7333 | return ExprError(); |
| 7334 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7335 | if (!getDerived().AlwaysRebuild() && |
| 7336 | T == E->getType() && |
| 7337 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7338 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7339 | // Mark the constructor as referenced. |
| 7340 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7341 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7342 | return SemaRef.Owned(E); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7344 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7345 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7346 | Constructor, E->isElidable(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7347 | move_arg(Args), |
| 7348 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7349 | E->getConstructionKind(), |
| 7350 | E->getParenRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7352 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7353 | /// \brief Transform a C++ temporary-binding expression. |
| 7354 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7355 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7356 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7357 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7358 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7359 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7360 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7362 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7363 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7364 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7365 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7366 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7367 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7368 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7369 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7370 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7371 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7372 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7373 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7374 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7375 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7376 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7377 | CXXTemporaryObjectExpr *E) { |
| 7378 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7379 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7380 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7381 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7382 | CXXConstructorDecl *Constructor |
| 7383 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7384 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7385 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7386 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7387 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7388 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7389 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7390 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7391 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7392 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7393 | &ArgumentChanged)) |
| 7394 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7395 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7396 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7397 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7398 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7399 | !ArgumentChanged) { |
| 7400 | // FIXME: Instantiation-specific |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7401 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7402 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7403 | } |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7404 | |
| 7405 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7406 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7407 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7408 | E->getLocEnd()); |
| 7409 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7411 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7412 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7413 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7414 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7415 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7416 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7417 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7418 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7419 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7420 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7421 | Args.reserve(E->arg_size()); |
| 7422 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 7423 | &ArgumentChanged)) |
| 7424 | return ExprError(); |
| 7425 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7426 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7427 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7428 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7429 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7430 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7431 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7432 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7433 | E->getLParenLoc(), |
| 7434 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7435 | E->getRParenLoc()); |
| 7436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7438 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7439 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7440 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7441 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7442 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7443 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7444 | Expr *OldBase; |
| 7445 | QualType BaseType; |
| 7446 | QualType ObjectType; |
| 7447 | if (!E->isImplicitAccess()) { |
| 7448 | OldBase = E->getBase(); |
| 7449 | Base = getDerived().TransformExpr(OldBase); |
| 7450 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7451 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7452 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7453 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7454 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7455 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7456 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7457 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7458 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7459 | ObjectTy, |
| 7460 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7461 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7462 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7463 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7464 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7465 | BaseType = ((Expr*) Base.get())->getType(); |
| 7466 | } else { |
| 7467 | OldBase = 0; |
| 7468 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 7469 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 7470 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7471 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7472 | // Transform the first part of the nested-name-specifier that qualifies |
| 7473 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7474 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7475 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7476 | E->getFirstQualifierFoundInScope(), |
| 7477 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7478 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7479 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7480 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7481 | QualifierLoc |
| 7482 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 7483 | ObjectType, |
| 7484 | FirstQualifierInScope); |
| 7485 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7486 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7488 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7489 | // TODO: If this is a conversion-function-id, verify that the |
| 7490 | // destination type name (if present) resolves the same way after |
| 7491 | // instantiation as it did in the local scope. |
| 7492 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7493 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7494 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7495 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7496 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7497 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7498 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7499 | // This is a reference to a member without an explicitly-specified |
| 7500 | // template argument list. Optimize for this common case. |
| 7501 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7502 | Base.get() == OldBase && |
| 7503 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7504 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7505 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7506 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7507 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7508 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7509 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7510 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7511 | E->isArrow(), |
| 7512 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7513 | QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7514 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7515 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7516 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7517 | } |
| 7518 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7519 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7520 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7521 | E->getNumTemplateArgs(), |
| 7522 | TransArgs)) |
| 7523 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7524 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7525 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7526 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7527 | E->isArrow(), |
| 7528 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7529 | QualifierLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7530 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7531 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7532 | &TransArgs); |
| 7533 | } |
| 7534 | |
| 7535 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7536 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7537 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7538 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7539 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7540 | QualType BaseType; |
| 7541 | if (!Old->isImplicitAccess()) { |
| 7542 | Base = getDerived().TransformExpr(Old->getBase()); |
| 7543 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7544 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7545 | BaseType = ((Expr*) Base.get())->getType(); |
| 7546 | } else { |
| 7547 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 7548 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7549 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7550 | NestedNameSpecifierLoc QualifierLoc; |
| 7551 | if (Old->getQualifierLoc()) { |
| 7552 | QualifierLoc |
| 7553 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7554 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7555 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7556 | } |
| 7557 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7558 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7559 | Sema::LookupOrdinaryName); |
| 7560 | |
| 7561 | // Transform all the decls. |
| 7562 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 7563 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7564 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7565 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 7566 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7567 | if (!InstD) { |
| 7568 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7569 | // This can happen because of dependent hiding. |
| 7570 | if (isa<UsingShadowDecl>(*I)) |
| 7571 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 7572 | else { |
| 7573 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7574 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 7575 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7576 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7577 | |
| 7578 | // Expand using declarations. |
| 7579 | if (isa<UsingDecl>(InstD)) { |
| 7580 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7581 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7582 | E = UD->shadow_end(); I != E; ++I) |
| 7583 | R.addDecl(*I); |
| 7584 | continue; |
| 7585 | } |
| 7586 | |
| 7587 | R.addDecl(InstD); |
| 7588 | } |
| 7589 | |
| 7590 | R.resolveKind(); |
| 7591 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7592 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 7593 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7594 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7595 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7596 | Old->getMemberLoc(), |
| 7597 | Old->getNamingClass())); |
| 7598 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7599 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7600 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7601 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7602 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7603 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7604 | TemplateArgumentListInfo TransArgs; |
| 7605 | if (Old->hasExplicitTemplateArgs()) { |
| 7606 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 7607 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7608 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7609 | Old->getNumTemplateArgs(), |
| 7610 | TransArgs)) |
| 7611 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7612 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7613 | |
| 7614 | // FIXME: to do this check properly, we will need to preserve the |
| 7615 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7616 | // base (and therefore couldn't do the check) and a |
| 7617 | // nested-name-qualifier (and therefore could do the lookup). |
| 7618 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7619 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7620 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7621 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7622 | Old->getOperatorLoc(), |
| 7623 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7624 | QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7625 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7626 | R, |
| 7627 | (Old->hasExplicitTemplateArgs() |
| 7628 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7629 | } |
| 7630 | |
| 7631 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7632 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7633 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
Alexis Hunt | 414e3e3 | 2011-05-31 19:54:49 +0000 | [diff] [blame] | 7634 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7635 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 7636 | if (SubExpr.isInvalid()) |
| 7637 | return ExprError(); |
| 7638 | |
| 7639 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7640 | return SemaRef.Owned(E); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7641 | |
| 7642 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 7643 | } |
| 7644 | |
| 7645 | template<typename Derived> |
| 7646 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7647 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 7648 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 7649 | if (Pattern.isInvalid()) |
| 7650 | return ExprError(); |
| 7651 | |
| 7652 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 7653 | return SemaRef.Owned(E); |
| 7654 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 7655 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 7656 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7657 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7658 | |
| 7659 | template<typename Derived> |
| 7660 | ExprResult |
| 7661 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7662 | // If E is not value-dependent, then nothing will change when we transform it. |
| 7663 | // Note: This is an instantiation-centric view. |
| 7664 | if (!E->isValueDependent()) |
| 7665 | return SemaRef.Owned(E); |
| 7666 | |
| 7667 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 7668 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 7669 | // so |
| 7670 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 7671 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7672 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7673 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7674 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 7675 | Unexpanded, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7676 | ShouldExpand, RetainExpansion, |
| 7677 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7678 | return ExprError(); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7679 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7680 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7681 | return SemaRef.Owned(E); |
| 7682 | |
| 7683 | // We now know the length of the parameter pack, so build a new expression |
| 7684 | // that stores that length. |
| 7685 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 7686 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7687 | *NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7688 | } |
| 7689 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7690 | template<typename Derived> |
| 7691 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 7692 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 7693 | SubstNonTypeTemplateParmPackExpr *E) { |
| 7694 | // Default behavior is to do nothing with this transformation. |
| 7695 | return SemaRef.Owned(E); |
| 7696 | } |
| 7697 | |
| 7698 | template<typename Derived> |
| 7699 | ExprResult |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 7700 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 7701 | SubstNonTypeTemplateParmExpr *E) { |
| 7702 | // Default behavior is to do nothing with this transformation. |
| 7703 | return SemaRef.Owned(E); |
| 7704 | } |
| 7705 | |
| 7706 | template<typename Derived> |
| 7707 | ExprResult |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 7708 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 7709 | MaterializeTemporaryExpr *E) { |
| 7710 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 7711 | } |
| 7712 | |
| 7713 | template<typename Derived> |
| 7714 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7715 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7716 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7717 | } |
| 7718 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7719 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7720 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7721 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7722 | TypeSourceInfo *EncodedTypeInfo |
| 7723 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 7724 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7725 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7726 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7727 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7728 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7729 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7730 | |
| 7731 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7732 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7733 | E->getRParenLoc()); |
| 7734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7736 | template<typename Derived> |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7737 | ExprResult TreeTransform<Derived>:: |
| 7738 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 7739 | ExprResult result = getDerived().TransformExpr(E->getSubExpr()); |
| 7740 | if (result.isInvalid()) return ExprError(); |
| 7741 | Expr *subExpr = result.take(); |
| 7742 | |
| 7743 | if (!getDerived().AlwaysRebuild() && |
| 7744 | subExpr == E->getSubExpr()) |
| 7745 | return SemaRef.Owned(E); |
| 7746 | |
| 7747 | return SemaRef.Owned(new(SemaRef.Context) |
| 7748 | ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); |
| 7749 | } |
| 7750 | |
| 7751 | template<typename Derived> |
| 7752 | ExprResult TreeTransform<Derived>:: |
| 7753 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| 7754 | TypeSourceInfo *TSInfo |
| 7755 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 7756 | if (!TSInfo) |
| 7757 | return ExprError(); |
| 7758 | |
| 7759 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| 7760 | if (Result.isInvalid()) |
| 7761 | return ExprError(); |
| 7762 | |
| 7763 | if (!getDerived().AlwaysRebuild() && |
| 7764 | TSInfo == E->getTypeInfoAsWritten() && |
| 7765 | Result.get() == E->getSubExpr()) |
| 7766 | return SemaRef.Owned(E); |
| 7767 | |
| 7768 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| 7769 | E->getBridgeKeywordLoc(), TSInfo, |
| 7770 | Result.get()); |
| 7771 | } |
| 7772 | |
| 7773 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7774 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7775 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7776 | // Transform arguments. |
| 7777 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7778 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7779 | Args.reserve(E->getNumArgs()); |
| 7780 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 7781 | &ArgChanged)) |
| 7782 | return ExprError(); |
| 7783 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7784 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 7785 | // Class message: transform the receiver type. |
| 7786 | TypeSourceInfo *ReceiverTypeInfo |
| 7787 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 7788 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7789 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7790 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7791 | // If nothing changed, just retain the existing message send. |
| 7792 | if (!getDerived().AlwaysRebuild() && |
| 7793 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7794 | return SemaRef.Owned(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7795 | |
| 7796 | // Build a new class message send. |
| 7797 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7798 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7799 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7800 | E->getMethodDecl(), |
| 7801 | E->getLeftLoc(), |
| 7802 | move_arg(Args), |
| 7803 | E->getRightLoc()); |
| 7804 | } |
| 7805 | |
| 7806 | // Instance message: transform the receiver |
| 7807 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7808 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7809 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7810 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7811 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7812 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7813 | |
| 7814 | // If nothing changed, just retain the existing message send. |
| 7815 | if (!getDerived().AlwaysRebuild() && |
| 7816 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7817 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7818 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7819 | // Build a new instance message send. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7820 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7821 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7822 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7823 | E->getMethodDecl(), |
| 7824 | E->getLeftLoc(), |
| 7825 | move_arg(Args), |
| 7826 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7827 | } |
| 7828 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7829 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7830 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7831 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7832 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7833 | } |
| 7834 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7835 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7836 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7837 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7838 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7839 | } |
| 7840 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7841 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7842 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7843 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7844 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7845 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7846 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7847 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7848 | |
| 7849 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7850 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7851 | // If nothing changed, just retain the existing expression. |
| 7852 | if (!getDerived().AlwaysRebuild() && |
| 7853 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7854 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7855 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7856 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7857 | E->getLocation(), |
| 7858 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7859 | } |
| 7860 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7861 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7862 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7863 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7864 | // 'super' and types never change. Property never changes. Just |
| 7865 | // retain the existing expression. |
| 7866 | if (!E->isObjectReceiver()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7867 | return SemaRef.Owned(E); |
Fariborz Jahanian | 681c075 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7868 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7869 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7870 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7871 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7872 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7873 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7874 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7875 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7876 | // If nothing changed, just retain the existing expression. |
| 7877 | if (!getDerived().AlwaysRebuild() && |
| 7878 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7879 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7880 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7881 | if (E->isExplicitProperty()) |
| 7882 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7883 | E->getExplicitProperty(), |
| 7884 | E->getLocation()); |
| 7885 | |
| 7886 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7887 | E->getType(), |
| 7888 | E->getImplicitPropertyGetter(), |
| 7889 | E->getImplicitPropertySetter(), |
| 7890 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7891 | } |
| 7892 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7893 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7894 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7895 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7896 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7897 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7898 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7899 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7900 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7901 | // If nothing changed, just retain the existing expression. |
| 7902 | if (!getDerived().AlwaysRebuild() && |
| 7903 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7904 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7905 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7906 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7907 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7908 | } |
| 7909 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7910 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7911 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7912 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7913 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7914 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7915 | SubExprs.reserve(E->getNumSubExprs()); |
| 7916 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7917 | SubExprs, &ArgumentChanged)) |
| 7918 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7920 | if (!getDerived().AlwaysRebuild() && |
| 7921 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7922 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7923 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7924 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7925 | move_arg(SubExprs), |
| 7926 | E->getRParenLoc()); |
| 7927 | } |
| 7928 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7929 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7930 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7931 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7932 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7933 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7934 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7935 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7936 | |
| 7937 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 4cc5df7 | 2011-05-05 17:18:12 +0000 | [diff] [blame] | 7938 | // We built a new blockScopeInfo in call to ActOnBlockStart |
| 7939 | // in above, CapturesCXXThis need be set here from the block |
| 7940 | // expression. |
| 7941 | blockScope->CapturesCXXThis = oldBlock->capturesCXXThis(); |
| 7942 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7943 | SmallVector<ParmVarDecl*, 4> params; |
| 7944 | SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7945 | |
| 7946 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7947 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7948 | oldBlock->param_begin(), |
| 7949 | oldBlock->param_size(), |
| 7950 | 0, paramTypes, ¶ms)) |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7951 | return true; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7952 | |
| 7953 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7954 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7955 | if (!exprResultType.isNull()) { |
| 7956 | if (!exprResultType->isDependentType()) |
| 7957 | blockScope->ReturnType = exprResultType; |
| 7958 | else if (exprResultType != getSema().Context.DependentTy) |
| 7959 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7960 | } |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7961 | |
| 7962 | // If the return type has not been determined yet, leave it as a dependent |
| 7963 | // type; it'll get set when we process the body. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7964 | if (blockScope->ReturnType.isNull()) |
| 7965 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7966 | |
| 7967 | // Don't allow returning a objc interface by value. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7968 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7969 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7970 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7971 | << 0 << blockScope->ReturnType; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7972 | return ExprError(); |
| 7973 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7974 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7975 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7976 | blockScope->ReturnType, |
| 7977 | paramTypes.data(), |
| 7978 | paramTypes.size(), |
| 7979 | oldBlock->isVariadic(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7980 | 0, RQ_None, |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7981 | exprFunctionType->getExtInfo()); |
| 7982 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7983 | |
| 7984 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7985 | if (!params.empty()) |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 7986 | blockScope->TheDecl->setParams(params); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7987 | |
| 7988 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7989 | // dependent type (DependentTy); clear out the return type setting so |
| 7990 | // 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] | 7991 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7992 | blockScope->ReturnType = QualType(); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7993 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7994 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7995 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7996 | if (body.isInvalid()) |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7997 | return ExprError(); |
| 7998 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7999 | #ifndef NDEBUG |
| 8000 | // In builds with assertions, make sure that we captured everything we |
| 8001 | // captured before. |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8002 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 8003 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 8004 | e = oldBlock->capture_end(); i != e; ++i) { |
| 8005 | VarDecl *oldCapture = i->getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8006 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8007 | // Ignore parameter packs. |
| 8008 | if (isa<ParmVarDecl>(oldCapture) && |
| 8009 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 8010 | continue; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8011 | |
Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 8012 | VarDecl *newCapture = |
| 8013 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 8014 | oldCapture)); |
| 8015 | assert(blockScope->CaptureMap.count(newCapture)); |
| 8016 | } |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 8017 | } |
| 8018 | #endif |
| 8019 | |
| 8020 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 8021 | /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8022 | } |
| 8023 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8024 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8025 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8026 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8027 | ValueDecl *ND |
| 8028 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 8029 | E->getDecl())); |
| 8030 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8031 | return ExprError(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8032 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8033 | if (!getDerived().AlwaysRebuild() && |
| 8034 | ND == E->getDecl()) { |
| 8035 | // Mark it referenced in the new context regardless. |
| 8036 | // FIXME: this is a bit instantiation-specific. |
| 8037 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 8038 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 8039 | return SemaRef.Owned(E); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 8040 | } |
| 8041 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8042 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8043 | return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8044 | ND, NameInfo, 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8046 | |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8047 | template<typename Derived> |
| 8048 | ExprResult |
| 8049 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8050 | llvm_unreachable("Cannot transform asType expressions yet"); |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 8051 | } |
| 8052 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8053 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8054 | // Type reconstruction |
| 8055 | //===----------------------------------------------------------------------===// |
| 8056 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8057 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8058 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 8059 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8060 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8061 | getDerived().getBaseEntity()); |
| 8062 | } |
| 8063 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8064 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8065 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 8066 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8067 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8068 | getDerived().getBaseEntity()); |
| 8069 | } |
| 8070 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8071 | template<typename Derived> |
| 8072 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8073 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 8074 | bool WrittenAsLValue, |
| 8075 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8076 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8077 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8078 | } |
| 8079 | |
| 8080 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8081 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8082 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 8083 | QualType ClassType, |
| 8084 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 8085 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8086 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8087 | } |
| 8088 | |
| 8089 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8090 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8091 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 8092 | ArrayType::ArraySizeModifier SizeMod, |
| 8093 | const llvm::APInt *Size, |
| 8094 | Expr *SizeExpr, |
| 8095 | unsigned IndexTypeQuals, |
| 8096 | SourceRange BracketsRange) { |
| 8097 | if (SizeExpr || !Size) |
| 8098 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 8099 | IndexTypeQuals, BracketsRange, |
| 8100 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8101 | |
| 8102 | QualType Types[] = { |
| 8103 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 8104 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 8105 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8106 | }; |
| 8107 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 8108 | QualType SizeType; |
| 8109 | for (unsigned I = 0; I != NumTypes; ++I) |
| 8110 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 8111 | SizeType = Types[I]; |
| 8112 | break; |
| 8113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8114 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 8115 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 8116 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8117 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8118 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8119 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8121 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8122 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8123 | QualType |
| 8124 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8125 | ArrayType::ArraySizeModifier SizeMod, |
| 8126 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8127 | unsigned IndexTypeQuals, |
| 8128 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8129 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8130 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8131 | } |
| 8132 | |
| 8133 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8134 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8135 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8136 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8137 | unsigned IndexTypeQuals, |
| 8138 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8139 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 8140 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8142 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8143 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8144 | QualType |
| 8145 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8146 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8147 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8148 | unsigned IndexTypeQuals, |
| 8149 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8150 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8151 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8152 | IndexTypeQuals, BracketsRange); |
| 8153 | } |
| 8154 | |
| 8155 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8156 | QualType |
| 8157 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8158 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8159 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8160 | unsigned IndexTypeQuals, |
| 8161 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8162 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8163 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8164 | IndexTypeQuals, BracketsRange); |
| 8165 | } |
| 8166 | |
| 8167 | template<typename Derived> |
| 8168 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8169 | unsigned NumElements, |
| 8170 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8171 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 8172 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8173 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8174 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8175 | template<typename Derived> |
| 8176 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 8177 | unsigned NumElements, |
| 8178 | SourceLocation AttributeLoc) { |
| 8179 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 8180 | NumElements, true); |
| 8181 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 8182 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 8183 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8184 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8185 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8186 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8187 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8188 | QualType |
| 8189 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8190 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8191 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8192 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8194 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8195 | template<typename Derived> |
| 8196 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8197 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8198 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8199 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8200 | unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 8201 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8202 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8203 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 8204 | Quals, RefQualifier, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8205 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8206 | getDerived().getBaseEntity(), |
| 8207 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8209 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8210 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 8211 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 8212 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 8213 | } |
| 8214 | |
| 8215 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8216 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 8217 | assert(D && "no decl found"); |
| 8218 | if (D->isInvalidDecl()) return QualType(); |
| 8219 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8220 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8221 | TypeDecl *Ty; |
| 8222 | if (isa<UsingDecl>(D)) { |
| 8223 | UsingDecl *Using = cast<UsingDecl>(D); |
| 8224 | assert(Using->isTypeName() && |
| 8225 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 8226 | |
| 8227 | // A valid resolved using typename decl points to exactly one type decl. |
| 8228 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 8229 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8230 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8231 | } else { |
| 8232 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 8233 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 8234 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 8235 | } |
| 8236 | |
| 8237 | return SemaRef.Context.getTypeDeclType(Ty); |
| 8238 | } |
| 8239 | |
| 8240 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 8241 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 8242 | SourceLocation Loc) { |
| 8243 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8244 | } |
| 8245 | |
| 8246 | template<typename Derived> |
| 8247 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 8248 | return SemaRef.Context.getTypeOfType(Underlying); |
| 8249 | } |
| 8250 | |
| 8251 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 8252 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 8253 | SourceLocation Loc) { |
| 8254 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8255 | } |
| 8256 | |
| 8257 | template<typename Derived> |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 8258 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 8259 | UnaryTransformType::UTTKind UKind, |
| 8260 | SourceLocation Loc) { |
| 8261 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 8262 | } |
| 8263 | |
| 8264 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8265 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 8266 | TemplateName Template, |
| 8267 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 8268 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8269 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8270 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8271 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 8272 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8273 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8274 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8275 | bool TemplateKW, |
| 8276 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8277 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8278 | Template); |
| 8279 | } |
| 8280 | |
| 8281 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8282 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8283 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 8284 | const IdentifierInfo &Name, |
| 8285 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8286 | QualType ObjectType, |
| 8287 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8288 | UnqualifiedId TemplateName; |
| 8289 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8290 | Sema::TemplateTy Template; |
| 8291 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8292 | /*FIXME:*/SourceLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8293 | SS, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8294 | TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8295 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8296 | /*EnteringContext=*/false, |
| 8297 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8298 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8299 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8300 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8301 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8302 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8303 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8304 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8305 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8306 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8307 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8308 | // FIXME: Bogus location information. |
| 8309 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| 8310 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8311 | Sema::TemplateTy Template; |
| 8312 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8313 | /*FIXME:*/SourceLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8314 | SS, |
| 8315 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8316 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8317 | /*EnteringContext=*/false, |
| 8318 | Template); |
| 8319 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8320 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8321 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8322 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8323 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8324 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 8325 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8326 | Expr *OrigCallee, |
| 8327 | Expr *First, |
| 8328 | Expr *Second) { |
| 8329 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 8330 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8332 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8333 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8334 | if (!First->getType()->isOverloadableType() && |
| 8335 | !Second->getType()->isOverloadableType()) |
| 8336 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 8337 | Callee->getLocStart(), |
| 8338 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 8339 | } else if (Op == OO_Arrow) { |
| 8340 | // -> is never a builtin operation. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8341 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 8342 | } else if (Second == 0 || isPostIncDec) { |
| 8343 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8344 | // The argument is not of overloadable type, so try to create a |
| 8345 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8346 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8347 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8348 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8349 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8350 | } |
| 8351 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8352 | if (!First->getType()->isOverloadableType() && |
| 8353 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8354 | // Neither of the arguments is an overloadable type, so try to |
| 8355 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8356 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8357 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8358 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8359 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8360 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8361 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8362 | return move(Result); |
| 8363 | } |
| 8364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8365 | |
| 8366 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8367 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8368 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8369 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8370 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8371 | assert(ULE->requiresADL()); |
| 8372 | |
| 8373 | // FIXME: Do we have to check |
| 8374 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8375 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8376 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8377 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8379 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8380 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8381 | Expr *Args[2] = { First, Second }; |
| 8382 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8383 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8384 | // Create the overloaded operator invocation for unary operators. |
| 8385 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8386 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8387 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8388 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8389 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8390 | |
Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 8391 | if (Op == OO_Subscript) { |
| 8392 | SourceLocation LBrace; |
| 8393 | SourceLocation RBrace; |
| 8394 | |
| 8395 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 8396 | DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); |
| 8397 | LBrace = SourceLocation::getFromRawEncoding( |
| 8398 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 8399 | RBrace = SourceLocation::getFromRawEncoding( |
| 8400 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 8401 | } else { |
| 8402 | LBrace = Callee->getLocStart(); |
| 8403 | RBrace = OpLoc; |
| 8404 | } |
| 8405 | |
| 8406 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 8407 | First, Second); |
| 8408 | } |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8409 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8410 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8411 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8412 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8413 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 8414 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8415 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8416 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8417 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8418 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8419 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8420 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8421 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8422 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8423 | SourceLocation OperatorLoc, |
| 8424 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8425 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8426 | TypeSourceInfo *ScopeType, |
| 8427 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8428 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8429 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8430 | QualType BaseType = Base->getType(); |
| 8431 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8432 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8433 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 8434 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 8435 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8436 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8437 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8438 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8439 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8440 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8441 | /*FIXME?*/true); |
| 8442 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8443 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8444 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8445 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 8446 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 8447 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 8448 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 8449 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8450 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8451 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8452 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8453 | OperatorLoc, isArrow, |
| 8454 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8455 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8456 | /*TemplateArgs*/ 0); |
| 8457 | } |
| 8458 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8459 | } // end namespace clang |
| 8460 | |
| 8461 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |