Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
John McCall | 8302463 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 18 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
| 26 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/Stmt.h" |
| 28 | #include "clang/AST/StmtCXX.h" |
| 29 | #include "clang/AST/StmtObjC.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Ownership.h" |
| 31 | #include "clang/Sema/Designator.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 451d1b1 | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 34 | #include "TypeLocBuilder.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | |
| 37 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 38 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 40 | /// \brief A semantic tree transformation that allows one to transform one |
| 41 | /// abstract syntax tree into another. |
| 42 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 44 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 45 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 46 | /// instantiation is implemented as a tree transformation where the |
| 47 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 48 | /// template arguments for their corresponding template parameters; a similar |
| 49 | /// transformation is performed for non-type template parameters and |
| 50 | /// template template parameters. |
| 51 | /// |
| 52 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 54 | /// override any of the transformation or rebuild operators by providing an |
| 55 | /// operation with the same signature as the default implementation. The |
| 56 | /// overridding function should not be virtual. |
| 57 | /// |
| 58 | /// Semantic tree transformations are split into two stages, either of which |
| 59 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 60 | /// or the parts of an AST node using the various transformation functions, |
| 61 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 62 | /// node of the appropriate kind from the pieces. The default transformation |
| 63 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 64 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 65 | /// were changed by the transformation, invokes the rebuild operation to create |
| 66 | /// a new AST node. |
| 67 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 69 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 70 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 71 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 72 | /// new implementations. |
| 73 | /// |
| 74 | /// For more fine-grained transformations, subclasses can replace any of the |
| 75 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 76 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 77 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 78 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 80 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 81 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 82 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 83 | /// be able to use more efficient rebuild steps. |
| 84 | /// |
| 85 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 87 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 88 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 89 | /// default locations and entity names used for type-checking |
| 90 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 91 | template<typename Derived> |
| 92 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 93 | /// \brief Private RAII object that helps us forget and then re-remember |
| 94 | /// the template argument corresponding to a partially-substituted parameter |
| 95 | /// pack. |
| 96 | class ForgetPartiallySubstitutedPackRAII { |
| 97 | Derived &Self; |
| 98 | TemplateArgument Old; |
| 99 | |
| 100 | public: |
| 101 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 102 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 103 | } |
| 104 | |
| 105 | ~ForgetPartiallySubstitutedPackRAII() { |
| 106 | Self.RememberPartiallySubstitutedPack(Old); |
| 107 | } |
| 108 | }; |
| 109 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 110 | protected: |
| 111 | Sema &SemaRef; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 112 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 114 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 115 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 117 | /// \brief Retrieves a reference to the derived class. |
| 118 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 119 | |
| 120 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | const Derived &getDerived() const { |
| 122 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 123 | } |
| 124 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 125 | static inline ExprResult Owned(Expr *E) { return E; } |
| 126 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 128 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 129 | /// this tree transform. |
| 130 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 131 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 132 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 133 | /// if none of the children have changed. |
| 134 | /// |
| 135 | /// Subclasses may override this function to specify when the transformation |
| 136 | /// should rebuild all AST nodes. |
| 137 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 139 | /// \brief Returns the location of the entity being transformed, if that |
| 140 | /// information was not available elsewhere in the AST. |
| 141 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 143 | /// provide an alternative implementation that provides better location |
| 144 | /// information. |
| 145 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 147 | /// \brief Returns the name of the entity being transformed, if that |
| 148 | /// information was not available elsewhere in the AST. |
| 149 | /// |
| 150 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 151 | /// implementation with a more precise name. |
| 152 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | /// \brief Sets the "base" location and entity when that |
| 155 | /// information is known based on another transformation. |
| 156 | /// |
| 157 | /// By default, the source location and entity are ignored. Subclasses can |
| 158 | /// override this function to provide a customized implementation. |
| 159 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 161 | /// \brief RAII object that temporarily sets the base location and entity |
| 162 | /// used for reporting diagnostics in types. |
| 163 | class TemporaryBase { |
| 164 | TreeTransform &Self; |
| 165 | SourceLocation OldLocation; |
| 166 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 168 | public: |
| 169 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 171 | OldLocation = Self.getDerived().getBaseLocation(); |
| 172 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 173 | |
| 174 | if (Location.isValid()) |
| 175 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 178 | ~TemporaryBase() { |
| 179 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 180 | } |
| 181 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | |
| 183 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 184 | /// transformed. |
| 185 | /// |
| 186 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 188 | /// not change. For example, template instantiation need not traverse |
| 189 | /// non-dependent types. |
| 190 | bool AlreadyTransformed(QualType T) { |
| 191 | return T.isNull(); |
| 192 | } |
| 193 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 194 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 195 | /// because it is a default argument. |
| 196 | /// |
| 197 | /// Subclasses can provide an alternative implementation of this routine to |
| 198 | /// determine which kinds of call arguments get dropped. By default, |
| 199 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 200 | bool DropCallArgument(Expr *E) { |
| 201 | return E->isDefaultArgument(); |
| 202 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 203 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 204 | /// \brief Determine whether we should expand a pack expansion with the |
| 205 | /// given set of parameter packs into separate arguments by repeatedly |
| 206 | /// transforming the pattern. |
| 207 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 208 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 209 | /// Subclasses can override this routine to provide different behavior. |
| 210 | /// |
| 211 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 212 | /// pack expansion. |
| 213 | /// |
| 214 | /// \param PatternRange The source range that covers the entire pattern of |
| 215 | /// the pack expansion. |
| 216 | /// |
| 217 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 218 | /// pattern. |
| 219 | /// |
| 220 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 221 | /// \p Unexpanded. |
| 222 | /// |
| 223 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 224 | /// expand the corresponding pack expansions into separate arguments. When |
| 225 | /// set, \c NumExpansions must also be set. |
| 226 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 227 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 228 | /// pack expansion after all of the expanded arguments. This is used |
| 229 | /// when extending explicitly-specified template argument packs per |
| 230 | /// C++0x [temp.arg.explicit]p9. |
| 231 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 232 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 233 | /// the expanded form of the corresponding pack expansion. This is both an |
| 234 | /// input and an output parameter, which can be set by the caller if the |
| 235 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 236 | /// and will be set by the callee when the number of expansions is known. |
| 237 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 238 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 239 | /// |
| 240 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 241 | /// are to be instantiated with arguments of different lengths), false |
| 242 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 243 | /// must be set. |
| 244 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 245 | SourceRange PatternRange, |
| 246 | const UnexpandedParameterPack *Unexpanded, |
| 247 | unsigned NumUnexpanded, |
| 248 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 249 | bool &RetainExpansion, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 250 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | ShouldExpand = false; |
| 252 | return false; |
| 253 | } |
| 254 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 255 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 256 | /// when performing an instantiation that must preserve the parameter pack |
| 257 | /// use. |
| 258 | /// |
| 259 | /// This routine is meant to be overridden by the template instantiator. |
| 260 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 261 | return TemplateArgument(); |
| 262 | } |
| 263 | |
| 264 | /// \brief "Remember" the partially-substituted pack template argument |
| 265 | /// after performing an instantiation that must preserve the parameter pack |
| 266 | /// use. |
| 267 | /// |
| 268 | /// This routine is meant to be overridden by the template instantiator. |
| 269 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 270 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 271 | /// \brief Note to the derived class when a function parameter pack is |
| 272 | /// being expanded. |
| 273 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 274 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 275 | /// \brief Transforms the given type into another type. |
| 276 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 277 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 278 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 279 | /// function. This is expensive, but we don't mind, because |
| 280 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 281 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// |
| 283 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 284 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 286 | /// \brief Transforms the given type-with-location into a new |
| 287 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 288 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 289 | /// By default, this routine transforms a type by delegating to the |
| 290 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 291 | /// may override this function (to take over all type |
| 292 | /// transformations) or some set of the TransformXXXType functions |
| 293 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 294 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 295 | |
| 296 | /// \brief Transform the given type-with-location into a new |
| 297 | /// type, collecting location information in the given builder |
| 298 | /// as necessary. |
| 299 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 300 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 302 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 303 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 305 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 306 | /// statement or the TransformExpr() function to transform an expression. |
| 307 | /// Subclasses may override this function to transform statements using some |
| 308 | /// other mechanism. |
| 309 | /// |
| 310 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 311 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 313 | /// \brief Transform the given expression. |
| 314 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 315 | /// By default, this routine transforms an expression by delegating to the |
| 316 | /// appropriate TransformXXXExpr function to build a new expression. |
| 317 | /// Subclasses may override this function to transform expressions using some |
| 318 | /// other mechanism. |
| 319 | /// |
| 320 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 321 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 323 | /// \brief Transform the given list of expressions. |
| 324 | /// |
| 325 | /// This routine transforms a list of expressions by invoking |
| 326 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 327 | /// support for variadic templates by expanding any pack expansions (if the |
| 328 | /// derived class permits such expansion) along the way. When pack expansions |
| 329 | /// are present, the number of outputs may not equal the number of inputs. |
| 330 | /// |
| 331 | /// \param Inputs The set of expressions to be transformed. |
| 332 | /// |
| 333 | /// \param NumInputs The number of expressions in \c Inputs. |
| 334 | /// |
| 335 | /// \param IsCall If \c true, then this transform is being performed on |
| 336 | /// function-call arguments, and any arguments that should be dropped, will |
| 337 | /// be. |
| 338 | /// |
| 339 | /// \param Outputs The transformed input expressions will be added to this |
| 340 | /// vector. |
| 341 | /// |
| 342 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 343 | /// due to transformation. |
| 344 | /// |
| 345 | /// \returns true if an error occurred, false otherwise. |
| 346 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
| 347 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 348 | bool *ArgChanged = 0); |
| 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Transform the given declaration, which is referenced from a type |
| 351 | /// or expression. |
| 352 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 353 | /// By default, acts as the identity function on declarations. Subclasses |
| 354 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 355 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 356 | |
| 357 | /// \brief Transform the definition of the given declaration. |
| 358 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 360 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 361 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 362 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 365 | /// \brief Transform the given declaration, which was the first part of a |
| 366 | /// nested-name-specifier in a member access expression. |
| 367 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 368 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 369 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 370 | /// the \c T in \c x->T::member |
| 371 | /// |
| 372 | /// By default, invokes TransformDecl() to transform the declaration. |
| 373 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 374 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 375 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 376 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 377 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 378 | /// \brief Transform the given nested-name-specifier. |
| 379 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 381 | /// nested-name-specifier. Subclasses may override this function to provide |
| 382 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 384 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 385 | QualType ObjectType = QualType(), |
| 386 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 388 | /// \brief Transform the given nested-name-specifier with source-location |
| 389 | /// information. |
| 390 | /// |
| 391 | /// By default, transforms all of the types and declarations within the |
| 392 | /// nested-name-specifier. Subclasses may override this function to provide |
| 393 | /// alternate behavior. |
| 394 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 395 | NestedNameSpecifierLoc NNS, |
| 396 | QualType ObjectType = QualType(), |
| 397 | NamedDecl *FirstQualifierInScope = 0); |
| 398 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 399 | /// \brief Transform the given declaration name. |
| 400 | /// |
| 401 | /// By default, transforms the types of conversion function, constructor, |
| 402 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 403 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 404 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 405 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 406 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 407 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 408 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 410 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 412 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 413 | TemplateName TransformTemplateName(TemplateName Name, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 414 | QualType ObjectType = QualType(), |
| 415 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 417 | /// \brief Transform the given template argument. |
| 418 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | /// By default, this operation transforms the type, expression, or |
| 420 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 421 | /// new template argument from the transformed result. Subclasses may |
| 422 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 423 | /// |
| 424 | /// Returns true if there was an error. |
| 425 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 426 | TemplateArgumentLoc &Output); |
| 427 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 428 | /// \brief Transform the given set of template arguments. |
| 429 | /// |
| 430 | /// By default, this operation transforms all of the template arguments |
| 431 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 432 | /// the transformed arguments to the output list. |
| 433 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 434 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 435 | /// a convenience function. Subclasses that wish to override this behavior |
| 436 | /// should override the iterator-based member template version. |
| 437 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 438 | /// \param Inputs The set of template arguments to be transformed. |
| 439 | /// |
| 440 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 441 | /// |
| 442 | /// \param Outputs The set of transformed template arguments output by this |
| 443 | /// routine. |
| 444 | /// |
| 445 | /// Returns true if an error occurred. |
| 446 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 447 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 448 | TemplateArgumentListInfo &Outputs) { |
| 449 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 450 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 451 | |
| 452 | /// \brief Transform the given set of template arguments. |
| 453 | /// |
| 454 | /// By default, this operation transforms all of the template arguments |
| 455 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 456 | /// the transformed arguments to the output list. |
| 457 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 458 | /// \param First An iterator to the first template argument. |
| 459 | /// |
| 460 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 461 | /// |
| 462 | /// \param Outputs The set of transformed template arguments output by this |
| 463 | /// routine. |
| 464 | /// |
| 465 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 466 | template<typename InputIterator> |
| 467 | bool TransformTemplateArguments(InputIterator First, |
| 468 | InputIterator Last, |
| 469 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 470 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 471 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 472 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 473 | TemplateArgumentLoc &ArgLoc); |
| 474 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 475 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 476 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 477 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 478 | getDerived().getBaseLocation()); |
| 479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 481 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 482 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 483 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 484 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 485 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 486 | QualType |
| 487 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 488 | TemplateSpecializationTypeLoc TL, |
| 489 | TemplateName Template); |
| 490 | |
| 491 | QualType |
| 492 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 493 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 494 | TemplateName Template); |
| 495 | |
| 496 | QualType |
| 497 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 498 | DependentTemplateSpecializationTypeLoc TL, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 499 | NestedNameSpecifier *Prefix); |
| 500 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 501 | /// \brief Transforms the parameters of a function type into the |
| 502 | /// given vectors. |
| 503 | /// |
| 504 | /// The result vectors should be kept in sync; null entries in the |
| 505 | /// variables vector are acceptable. |
| 506 | /// |
| 507 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 508 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 509 | ParmVarDecl **Params, unsigned NumParams, |
| 510 | const QualType *ParamTypes, |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 511 | llvm::SmallVectorImpl<QualType> &PTypes, |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 512 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 513 | |
| 514 | /// \brief Transforms a single function-type parameter. Return null |
| 515 | /// on error. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 516 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 517 | llvm::Optional<unsigned> NumExpansions); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 518 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 519 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 520 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 521 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 522 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 524 | #define STMT(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 525 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 526 | #define EXPR(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 527 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 528 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 529 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | /// \brief Build a new pointer type given its pointee type. |
| 532 | /// |
| 533 | /// By default, performs semantic analysis when building the pointer type. |
| 534 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 535 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | |
| 537 | /// \brief Build a new block pointer type given its pointee type. |
| 538 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 541 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 542 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 543 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 544 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 545 | /// By default, performs semantic analysis when building the |
| 546 | /// reference type. Subclasses may override this routine to provide |
| 547 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 548 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 549 | /// \param LValue whether the type was written with an lvalue sigil |
| 550 | /// or an rvalue sigil. |
| 551 | QualType RebuildReferenceType(QualType ReferentType, |
| 552 | bool LValue, |
| 553 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 555 | /// \brief Build a new member pointer type given the pointee type and the |
| 556 | /// class type it refers into. |
| 557 | /// |
| 558 | /// By default, performs semantic analysis when building the member pointer |
| 559 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 560 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 561 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 563 | /// \brief Build a new array type given the element type, size |
| 564 | /// modifier, size of the array (if known), size expression, and index type |
| 565 | /// qualifiers. |
| 566 | /// |
| 567 | /// By default, performs semantic analysis when building the array type. |
| 568 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 570 | QualType RebuildArrayType(QualType ElementType, |
| 571 | ArrayType::ArraySizeModifier SizeMod, |
| 572 | const llvm::APInt *Size, |
| 573 | Expr *SizeExpr, |
| 574 | unsigned IndexTypeQuals, |
| 575 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 576 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 577 | /// \brief Build a new constant array type given the element type, size |
| 578 | /// modifier, (known) size of the array, and index type qualifiers. |
| 579 | /// |
| 580 | /// By default, performs semantic analysis when building the array type. |
| 581 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 583 | ArrayType::ArraySizeModifier SizeMod, |
| 584 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 585 | unsigned IndexTypeQuals, |
| 586 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 587 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 588 | /// \brief Build a new incomplete array type given the element type, size |
| 589 | /// modifier, and index type qualifiers. |
| 590 | /// |
| 591 | /// By default, performs semantic analysis when building the array type. |
| 592 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 594 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 595 | unsigned IndexTypeQuals, |
| 596 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 597 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 599 | /// size modifier, size expression, and index type qualifiers. |
| 600 | /// |
| 601 | /// By default, performs semantic analysis when building the array type. |
| 602 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 604 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 605 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 606 | unsigned IndexTypeQuals, |
| 607 | SourceRange BracketsRange); |
| 608 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 610 | /// size modifier, size expression, and index type qualifiers. |
| 611 | /// |
| 612 | /// By default, performs semantic analysis when building the array type. |
| 613 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 615 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 616 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 617 | unsigned IndexTypeQuals, |
| 618 | SourceRange BracketsRange); |
| 619 | |
| 620 | /// \brief Build a new vector type given the element type and |
| 621 | /// number of elements. |
| 622 | /// |
| 623 | /// By default, performs semantic analysis when building the vector type. |
| 624 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 625 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 626 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 628 | /// \brief Build a new extended vector type given the element type and |
| 629 | /// number of elements. |
| 630 | /// |
| 631 | /// By default, performs semantic analysis when building the vector type. |
| 632 | /// Subclasses may override this routine to provide different behavior. |
| 633 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 634 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
| 636 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 637 | /// given the element type and 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. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 642 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 643 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 645 | /// \brief Build a new function type. |
| 646 | /// |
| 647 | /// By default, performs semantic analysis when building the function type. |
| 648 | /// Subclasses may override this routine to provide different behavior. |
| 649 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 651 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 652 | bool Variadic, unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 653 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 654 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 656 | /// \brief Build a new unprototyped function type. |
| 657 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 658 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 659 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 660 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 661 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 662 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 663 | /// \brief Build a new typedef type. |
| 664 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 665 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 666 | } |
| 667 | |
| 668 | /// \brief Build a new class/struct/union type. |
| 669 | QualType RebuildRecordType(RecordDecl *Record) { |
| 670 | return SemaRef.Context.getTypeDeclType(Record); |
| 671 | } |
| 672 | |
| 673 | /// \brief Build a new Enum type. |
| 674 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 675 | return SemaRef.Context.getTypeDeclType(Enum); |
| 676 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 677 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 678 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 679 | /// |
| 680 | /// By default, performs semantic analysis when building the typeof type. |
| 681 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 682 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 683 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 685 | /// |
| 686 | /// By default, builds a new TypeOfType with the given underlying type. |
| 687 | QualType RebuildTypeOfType(QualType Underlying); |
| 688 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 690 | /// |
| 691 | /// By default, performs semantic analysis when building the decltype type. |
| 692 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 693 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 695 | /// \brief Build a new C++0x auto type. |
| 696 | /// |
| 697 | /// By default, builds a new AutoType with the given deduced type. |
| 698 | QualType RebuildAutoType(QualType Deduced) { |
| 699 | return SemaRef.Context.getAutoType(Deduced); |
| 700 | } |
| 701 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 702 | /// \brief Build a new template specialization type. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis when building the template |
| 705 | /// specialization type. Subclasses may override this routine to provide |
| 706 | /// different behavior. |
| 707 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 708 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 709 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 711 | /// \brief Build a new parenthesized type. |
| 712 | /// |
| 713 | /// By default, builds a new ParenType type from the inner type. |
| 714 | /// Subclasses may override this routine to provide different behavior. |
| 715 | QualType RebuildParenType(QualType InnerType) { |
| 716 | return SemaRef.Context.getParenType(InnerType); |
| 717 | } |
| 718 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 719 | /// \brief Build a new qualified name type. |
| 720 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 721 | /// By default, builds a new ElaboratedType type from the keyword, |
| 722 | /// the nested-name-specifier and the named type. |
| 723 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 724 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 725 | ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 726 | NestedNameSpecifier *NNS, QualType Named) { |
| 727 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 729 | |
| 730 | /// \brief Build a new typename type that refers to a template-id. |
| 731 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 732 | /// By default, builds a new DependentNameType type from the |
| 733 | /// nested-name-specifier and the given type. Subclasses may override |
| 734 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 735 | QualType RebuildDependentTemplateSpecializationType( |
| 736 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 737 | NestedNameSpecifier *Qualifier, |
| 738 | SourceRange QualifierRange, |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 739 | const IdentifierInfo *Name, |
| 740 | SourceLocation NameLoc, |
| 741 | const TemplateArgumentListInfo &Args) { |
| 742 | // Rebuild the template name. |
| 743 | // TODO: avoid TemplateName abstraction |
| 744 | TemplateName InstName = |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 745 | getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 746 | QualType(), 0); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | 7ba0c3f | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 748 | if (InstName.isNull()) |
| 749 | return QualType(); |
| 750 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 751 | // If it's still dependent, make a dependent specialization. |
| 752 | if (InstName.getAsDependentTemplateName()) |
| 753 | return SemaRef.Context.getDependentTemplateSpecializationType( |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 754 | Keyword, Qualifier, Name, Args); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 755 | |
| 756 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 757 | // specialization. |
| 758 | QualType T = |
| 759 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 760 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 762 | if (Keyword == ETK_None && Qualifier == 0) |
Douglas Gregor | 6e06801 | 2011-02-28 00:04:36 +0000 | [diff] [blame] | 763 | return T; |
| 764 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 765 | return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 767 | |
| 768 | /// \brief Build a new typename type that refers to an identifier. |
| 769 | /// |
| 770 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 771 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 772 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 773 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 774 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 775 | NestedNameSpecifierLoc QualifierLoc, |
| 776 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 777 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 778 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 779 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 780 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 781 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 782 | // If the name is still dependent, just build a new dependent name type. |
| 783 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 784 | return SemaRef.Context.getDependentNameType(Keyword, |
| 785 | QualifierLoc.getNestedNameSpecifier(), |
| 786 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 789 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 790 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 791 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 792 | |
| 793 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 794 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 795 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 796 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 797 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 798 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 799 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 800 | if (!DC) |
| 801 | return QualType(); |
| 802 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 803 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 804 | return QualType(); |
| 805 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 806 | TagDecl *Tag = 0; |
| 807 | SemaRef.LookupQualifiedName(Result, DC); |
| 808 | switch (Result.getResultKind()) { |
| 809 | case LookupResult::NotFound: |
| 810 | case LookupResult::NotFoundInCurrentInstantiation: |
| 811 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 812 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 813 | case LookupResult::Found: |
| 814 | Tag = Result.getAsSingle<TagDecl>(); |
| 815 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 817 | case LookupResult::FoundOverloaded: |
| 818 | case LookupResult::FoundUnresolvedValue: |
| 819 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 820 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 821 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 822 | case LookupResult::Ambiguous: |
| 823 | // Let the LookupResult structure handle ambiguities. |
| 824 | return QualType(); |
| 825 | } |
| 826 | |
| 827 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 828 | // Check where the name exists but isn't a tag type and use that to emit |
| 829 | // better diagnostics. |
| 830 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 831 | SemaRef.LookupQualifiedName(Result, DC); |
| 832 | switch (Result.getResultKind()) { |
| 833 | case LookupResult::Found: |
| 834 | case LookupResult::FoundOverloaded: |
| 835 | case LookupResult::FoundUnresolvedValue: { |
| 836 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| 837 | unsigned Kind = 0; |
| 838 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
| 839 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2; |
| 840 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 841 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 842 | break; |
| 843 | } |
| 844 | default: |
| 845 | // FIXME: Would be nice to highlight just the source range. |
| 846 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 847 | << Kind << Id << DC; |
| 848 | break; |
| 849 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 850 | return QualType(); |
| 851 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 852 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 853 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 854 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 855 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 856 | return QualType(); |
| 857 | } |
| 858 | |
| 859 | // Build the elaborated-type-specifier type. |
| 860 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 861 | return SemaRef.Context.getElaboratedType(Keyword, |
| 862 | QualifierLoc.getNestedNameSpecifier(), |
| 863 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 864 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 865 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 866 | /// \brief Build a new pack expansion type. |
| 867 | /// |
| 868 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 869 | /// Subclasses may override this routine to provide different behavior. |
| 870 | QualType RebuildPackExpansionType(QualType Pattern, |
| 871 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 872 | SourceLocation EllipsisLoc, |
| 873 | llvm::Optional<unsigned> NumExpansions) { |
| 874 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 875 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 876 | } |
| 877 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 878 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 879 | /// identifier that names the next step in the nested-name-specifier. |
| 880 | /// |
| 881 | /// By default, performs semantic analysis when building the new |
| 882 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 883 | /// different behavior. |
| 884 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 885 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 886 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 887 | QualType ObjectType, |
| 888 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 889 | |
| 890 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 891 | /// namespace named in the next step in the nested-name-specifier. |
| 892 | /// |
| 893 | /// By default, performs semantic analysis when building the new |
| 894 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 895 | /// different behavior. |
| 896 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 897 | SourceRange Range, |
| 898 | NamespaceDecl *NS); |
| 899 | |
| 900 | /// \brief Build a new nested-name-specifier given the prefix and the |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 901 | /// namespace alias named in the next step in the nested-name-specifier. |
| 902 | /// |
| 903 | /// By default, performs semantic analysis when building the new |
| 904 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 905 | /// different behavior. |
| 906 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 907 | SourceRange Range, |
| 908 | NamespaceAliasDecl *Alias); |
| 909 | |
| 910 | /// \brief Build a new nested-name-specifier given the prefix and the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 911 | /// type named in the next step in the nested-name-specifier. |
| 912 | /// |
| 913 | /// By default, performs semantic analysis when building the new |
| 914 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 915 | /// different behavior. |
| 916 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 917 | SourceRange Range, |
| 918 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 919 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 920 | |
| 921 | /// \brief Build a new template name given a nested name specifier, a flag |
| 922 | /// indicating whether the "template" keyword was provided, and the template |
| 923 | /// that the template name refers to. |
| 924 | /// |
| 925 | /// By default, builds the new template name directly. Subclasses may override |
| 926 | /// this routine to provide different behavior. |
| 927 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 928 | bool TemplateKW, |
| 929 | TemplateDecl *Template); |
| 930 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 931 | /// \brief Build a new template name given a nested name specifier and the |
| 932 | /// 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. |
| 938 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 939 | SourceRange QualifierRange, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 940 | const IdentifierInfo &II, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 941 | QualType ObjectType, |
| 942 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 944 | /// \brief Build a new template name given a nested name specifier and the |
| 945 | /// overloaded operator name that is referred to as a template. |
| 946 | /// |
| 947 | /// By default, performs semantic analysis to determine whether the name can |
| 948 | /// be resolved to a specific template, then builds the appropriate kind of |
| 949 | /// template name. Subclasses may override this routine to provide different |
| 950 | /// behavior. |
| 951 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 952 | OverloadedOperatorKind Operator, |
| 953 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 954 | |
| 955 | /// \brief Build a new template name given a template template parameter pack |
| 956 | /// and the |
| 957 | /// |
| 958 | /// By default, performs semantic analysis to determine whether the name can |
| 959 | /// be resolved to a specific template, then builds the appropriate kind of |
| 960 | /// template name. Subclasses may override this routine to provide different |
| 961 | /// behavior. |
| 962 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 963 | const TemplateArgument &ArgPack) { |
| 964 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 965 | } |
| 966 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 967 | /// \brief Build a new compound 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 RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 972 | MultiStmtArg Statements, |
| 973 | SourceLocation RBraceLoc, |
| 974 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 975 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 976 | IsStmtExpr); |
| 977 | } |
| 978 | |
| 979 | /// \brief Build a new case statement. |
| 980 | /// |
| 981 | /// By default, performs semantic analysis to build the new statement. |
| 982 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 983 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 984 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 985 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 986 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 987 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 988 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 989 | ColonLoc); |
| 990 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 992 | /// \brief Attach the body to a new case statement. |
| 993 | /// |
| 994 | /// By default, performs semantic analysis to build the new statement. |
| 995 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 996 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 997 | getSema().ActOnCaseStmtBody(S, Body); |
| 998 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1001 | /// \brief Build a new default statement. |
| 1002 | /// |
| 1003 | /// By default, performs semantic analysis to build the new statement. |
| 1004 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1005 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1006 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1007 | Stmt *SubStmt) { |
| 1008 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1009 | /*CurScope=*/0); |
| 1010 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1012 | /// \brief Build a new label statement. |
| 1013 | /// |
| 1014 | /// By default, performs semantic analysis to build the new statement. |
| 1015 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1016 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1017 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1018 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1019 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1021 | /// \brief Build a new "if" statement. |
| 1022 | /// |
| 1023 | /// By default, performs semantic analysis to build the new statement. |
| 1024 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1025 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1026 | VarDecl *CondVar, Stmt *Then, |
| 1027 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1028 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1029 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1031 | /// \brief Start building a new switch statement. |
| 1032 | /// |
| 1033 | /// By default, performs semantic analysis to build the new statement. |
| 1034 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1035 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1036 | Expr *Cond, VarDecl *CondVar) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1037 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1038 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1039 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1041 | /// \brief Attach the body to the switch statement. |
| 1042 | /// |
| 1043 | /// By default, performs semantic analysis to build the new statement. |
| 1044 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1045 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1046 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1047 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /// \brief Build a new while statement. |
| 1051 | /// |
| 1052 | /// By default, performs semantic analysis to build the new statement. |
| 1053 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1054 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1055 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1056 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1058 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | /// \brief Build a new do-while statement. |
| 1060 | /// |
| 1061 | /// By default, performs semantic analysis to build the new statement. |
| 1062 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1063 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1064 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1065 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1066 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1067 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /// \brief Build a new for 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 RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1075 | Stmt *Init, Sema::FullExprArg Cond, |
| 1076 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1077 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1078 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1079 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1082 | /// \brief Build a new goto statement. |
| 1083 | /// |
| 1084 | /// By default, performs semantic analysis to build the new statement. |
| 1085 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1086 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1087 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1088 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | /// \brief Build a new indirect goto statement. |
| 1092 | /// |
| 1093 | /// By default, performs semantic analysis to build the new statement. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1095 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1096 | SourceLocation StarLoc, |
| 1097 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1098 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1099 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1101 | /// \brief Build a new return statement. |
| 1102 | /// |
| 1103 | /// By default, performs semantic analysis to build the new statement. |
| 1104 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1105 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1106 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1107 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | /// \brief Build a new declaration statement. |
| 1110 | /// |
| 1111 | /// By default, performs semantic analysis to build the new statement. |
| 1112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1113 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1115 | SourceLocation EndLoc) { |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1116 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1117 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1118 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1120 | /// \brief Build a new inline asm statement. |
| 1121 | /// |
| 1122 | /// By default, performs semantic analysis to build the new statement. |
| 1123 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1124 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1125 | bool IsSimple, |
| 1126 | bool IsVolatile, |
| 1127 | unsigned NumOutputs, |
| 1128 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1129 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1130 | MultiExprArg Constraints, |
| 1131 | MultiExprArg Exprs, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1132 | Expr *AsmString, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1133 | MultiExprArg Clobbers, |
| 1134 | SourceLocation RParenLoc, |
| 1135 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1136 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1137 | NumInputs, Names, move(Constraints), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1138 | Exprs, AsmString, Clobbers, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1139 | RParenLoc, MSAsm); |
| 1140 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1141 | |
| 1142 | /// \brief Build a new Objective-C @try statement. |
| 1143 | /// |
| 1144 | /// By default, performs semantic analysis to build the new statement. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1146 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1147 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1148 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1149 | Stmt *Finally) { |
| 1150 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1151 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1154 | /// \brief Rebuild an Objective-C exception declaration. |
| 1155 | /// |
| 1156 | /// By default, performs semantic analysis to build the new declaration. |
| 1157 | /// Subclasses may override this routine to provide different behavior. |
| 1158 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1159 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1160 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1161 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1162 | ExceptionDecl->getLocation()); |
| 1163 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1164 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1165 | /// \brief Build a new Objective-C @catch statement. |
| 1166 | /// |
| 1167 | /// By default, performs semantic analysis to build the new statement. |
| 1168 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1169 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1170 | SourceLocation RParenLoc, |
| 1171 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1172 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1173 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1174 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1175 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1176 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1177 | /// \brief Build a new Objective-C @finally statement. |
| 1178 | /// |
| 1179 | /// By default, performs semantic analysis to build the new statement. |
| 1180 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1181 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1182 | Stmt *Body) { |
| 1183 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1184 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1185 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1186 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1187 | /// |
| 1188 | /// By default, performs semantic analysis to build the new statement. |
| 1189 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1190 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1191 | Expr *Operand) { |
| 1192 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1193 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1194 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1195 | /// \brief Build a new Objective-C @synchronized statement. |
| 1196 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1197 | /// By default, performs semantic analysis to build the new statement. |
| 1198 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1199 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1200 | Expr *Object, |
| 1201 | Stmt *Body) { |
| 1202 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, |
| 1203 | Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1204 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1205 | |
| 1206 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1207 | /// |
| 1208 | /// By default, performs semantic analysis to build the new statement. |
| 1209 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1210 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1211 | SourceLocation LParenLoc, |
| 1212 | Stmt *Element, |
| 1213 | Expr *Collection, |
| 1214 | SourceLocation RParenLoc, |
| 1215 | Stmt *Body) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1216 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1217 | Element, |
| 1218 | Collection, |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1219 | RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1220 | Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1221 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1222 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1223 | /// \brief Build a new C++ exception declaration. |
| 1224 | /// |
| 1225 | /// By default, performs semantic analysis to build the new decaration. |
| 1226 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1227 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1228 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1229 | IdentifierInfo *Name, |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1230 | SourceLocation Loc) { |
| 1231 | return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | /// \brief Build a new C++ catch statement. |
| 1235 | /// |
| 1236 | /// By default, performs semantic analysis to build the new statement. |
| 1237 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1238 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1239 | VarDecl *ExceptionDecl, |
| 1240 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1241 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1242 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1245 | /// \brief Build a new C++ try statement. |
| 1246 | /// |
| 1247 | /// By default, performs semantic analysis to build the new statement. |
| 1248 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1249 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1250 | Stmt *TryBlock, |
| 1251 | MultiStmtArg Handlers) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1252 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1255 | /// \brief Build a new expression that references a declaration. |
| 1256 | /// |
| 1257 | /// By default, performs semantic analysis to build the new expression. |
| 1258 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1259 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1260 | LookupResult &R, |
| 1261 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1262 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1263 | } |
| 1264 | |
| 1265 | |
| 1266 | /// \brief Build a new expression that references a declaration. |
| 1267 | /// |
| 1268 | /// By default, performs semantic analysis to build the new expression. |
| 1269 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1270 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1271 | ValueDecl *VD, |
| 1272 | const DeclarationNameInfo &NameInfo, |
| 1273 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1274 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1275 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1276 | |
| 1277 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1278 | |
| 1279 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1282 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1283 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1284 | /// By default, performs semantic analysis to build the new expression. |
| 1285 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1286 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1287 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1288 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1291 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1293 | /// By default, performs semantic analysis to build the new expression. |
| 1294 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1295 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1296 | SourceLocation OperatorLoc, |
| 1297 | bool isArrow, |
| 1298 | CXXScopeSpec &SS, |
| 1299 | TypeSourceInfo *ScopeType, |
| 1300 | SourceLocation CCLoc, |
| 1301 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1302 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1305 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1306 | /// By default, performs semantic analysis to build the new expression. |
| 1307 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1308 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1309 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1310 | Expr *SubExpr) { |
| 1311 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1314 | /// \brief Build a new builtin offsetof expression. |
| 1315 | /// |
| 1316 | /// By default, performs semantic analysis to build the new expression. |
| 1317 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1318 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1319 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1320 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1321 | unsigned NumComponents, |
| 1322 | SourceLocation RParenLoc) { |
| 1323 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1324 | NumComponents, RParenLoc); |
| 1325 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1326 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1327 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | /// By default, performs semantic analysis to build the new expression. |
| 1330 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1331 | ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1332 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1333 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1334 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1339 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1340 | /// By default, performs semantic analysis to build the new expression. |
| 1341 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1342 | ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | bool isSizeOf, SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1344 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1345 | = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1346 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1347 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | return move(Result); |
| 1350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1351 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1352 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1354 | /// By default, performs semantic analysis to build the new expression. |
| 1355 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1356 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1357 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1358 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1359 | SourceLocation RBracketLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1360 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1361 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1362 | RBracketLoc); |
| 1363 | } |
| 1364 | |
| 1365 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1366 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1367 | /// By default, performs semantic analysis to build the new expression. |
| 1368 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1369 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1370 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1371 | SourceLocation RParenLoc, |
| 1372 | Expr *ExecConfig = 0) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1373 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1374 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | /// By default, performs semantic analysis to build the new expression. |
| 1380 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1381 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1382 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1383 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1384 | const DeclarationNameInfo &MemberNameInfo, |
| 1385 | ValueDecl *Member, |
| 1386 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1387 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1388 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1389 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1390 | // We have a reference to an unnamed field. This is always the |
| 1391 | // base of an anonymous struct/union member access, i.e. the |
| 1392 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1393 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1394 | assert(Member->getType()->isRecordType() && |
| 1395 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1397 | if (getSema().PerformObjectMemberConversion(Base, |
| 1398 | QualifierLoc.getNestedNameSpecifier(), |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1399 | FoundDecl, Member)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1400 | return ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1401 | |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1402 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1404 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1405 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1406 | cast<FieldDecl>(Member)->getType(), |
| 1407 | VK, OK_Ordinary); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1408 | return getSema().Owned(ME); |
| 1409 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1411 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1412 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1413 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1414 | getSema().DefaultFunctionArrayConversion(Base); |
| 1415 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1416 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1417 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1418 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1419 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1420 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1421 | R.resolveKind(); |
| 1422 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1423 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1424 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1425 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | /// \brief Build a new binary operator 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 RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1433 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1434 | Expr *LHS, Expr *RHS) { |
| 1435 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1440 | /// By default, performs semantic analysis to build the new expression. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1442 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1443 | SourceLocation QuestionLoc, |
| 1444 | Expr *LHS, |
| 1445 | SourceLocation ColonLoc, |
| 1446 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1447 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1448 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1452 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1453 | /// By default, performs semantic analysis to build the new expression. |
| 1454 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1455 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1456 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1458 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1459 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1460 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1461 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1462 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1463 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1464 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1465 | /// By default, performs semantic analysis to build the new expression. |
| 1466 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1467 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1468 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1470 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1471 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1472 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1473 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1476 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1479 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | SourceLocation OpLoc, |
| 1481 | SourceLocation AccessorLoc, |
| 1482 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1483 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1484 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1485 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1486 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1487 | OpLoc, /*IsArrow*/ false, |
| 1488 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1489 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1490 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1497 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1499 | SourceLocation RBraceLoc, |
| 1500 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1501 | ExprResult Result |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1502 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1503 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1504 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1505 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1506 | // Patch in the result type we were given, which may have been computed |
| 1507 | // when the initial InitListExpr was built. |
| 1508 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1509 | ILE->setType(ResultTy); |
| 1510 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1515 | /// By default, performs semantic analysis to build the new expression. |
| 1516 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1517 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | MultiExprArg ArrayExprs, |
| 1519 | SourceLocation EqualOrColonLoc, |
| 1520 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1521 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1522 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1523 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1524 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1526 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1527 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1528 | ArrayExprs.release(); |
| 1529 | return move(Result); |
| 1530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1531 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1532 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | /// By default, builds the implicit value initialization without performing |
| 1535 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1536 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1537 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1538 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1539 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1540 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1541 | /// \brief Build a new \c va_arg expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1544 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1545 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1546 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1547 | SourceLocation RParenLoc) { |
| 1548 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1549 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1550 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1554 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | /// By default, performs semantic analysis to build the new expression. |
| 1556 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1557 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | MultiExprArg SubExprs, |
| 1559 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1560 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1561 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1562 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1564 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1565 | /// |
| 1566 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1567 | /// rather than attempting to map the label statement itself. |
| 1568 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1569 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1570 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1571 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1572 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1575 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1576 | /// By default, performs semantic analysis to build the new expression. |
| 1577 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1578 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1579 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1580 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1581 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1584 | /// \brief Build a new __builtin_choose_expr expression. |
| 1585 | /// |
| 1586 | /// By default, performs semantic analysis to build the new expression. |
| 1587 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1588 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1589 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1590 | SourceLocation RParenLoc) { |
| 1591 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1592 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | RParenLoc); |
| 1594 | } |
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 | /// \brief Build a new overloaded operator call expression. |
| 1597 | /// |
| 1598 | /// By default, performs semantic analysis to build the new expression. |
| 1599 | /// The semantic analysis provides the behavior of template instantiation, |
| 1600 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1602 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1603 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1604 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1605 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1606 | Expr *Callee, |
| 1607 | Expr *First, |
| 1608 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | |
| 1610 | /// \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] | 1611 | /// reinterpret_cast. |
| 1612 | /// |
| 1613 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1614 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1615 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1616 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | Stmt::StmtClass Class, |
| 1618 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1619 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1620 | SourceLocation RAngleLoc, |
| 1621 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1622 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1623 | SourceLocation RParenLoc) { |
| 1624 | switch (Class) { |
| 1625 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1626 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1627 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1628 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1629 | |
| 1630 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1631 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1632 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1633 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1636 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1638 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1639 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1641 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1642 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1644 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | default: |
| 1647 | assert(false && "Invalid C++ named cast"); |
| 1648 | break; |
| 1649 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1651 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | /// \brief Build a new C++ static_cast expression. |
| 1655 | /// |
| 1656 | /// By default, performs semantic analysis to build the new expression. |
| 1657 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1658 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1659 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1660 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | SourceLocation RAngleLoc, |
| 1662 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1663 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1664 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1665 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1666 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1667 | SourceRange(LAngleLoc, RAngleLoc), |
| 1668 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /// \brief Build a new C++ dynamic_cast expression. |
| 1672 | /// |
| 1673 | /// By default, performs semantic analysis to build the new expression. |
| 1674 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1675 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1676 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1677 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | SourceLocation RAngleLoc, |
| 1679 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1680 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1682 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1683 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1684 | SourceRange(LAngleLoc, RAngleLoc), |
| 1685 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1689 | /// |
| 1690 | /// By default, performs semantic analysis to build the new expression. |
| 1691 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1692 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1694 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | SourceLocation RAngleLoc, |
| 1696 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1697 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1699 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1700 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1701 | SourceRange(LAngleLoc, RAngleLoc), |
| 1702 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /// \brief Build a new C++ const_cast expression. |
| 1706 | /// |
| 1707 | /// By default, performs semantic analysis to build the new expression. |
| 1708 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1709 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1711 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | SourceLocation RAngleLoc, |
| 1713 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1714 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1715 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1716 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1717 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1718 | SourceRange(LAngleLoc, RAngleLoc), |
| 1719 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1720 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | /// \brief Build a new C++ functional-style cast expression. |
| 1723 | /// |
| 1724 | /// By default, performs semantic analysis to build the new expression. |
| 1725 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1726 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1727 | SourceLocation LParenLoc, |
| 1728 | Expr *Sub, |
| 1729 | SourceLocation RParenLoc) { |
| 1730 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1731 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | RParenLoc); |
| 1733 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1735 | /// \brief Build a new C++ typeid(type) expression. |
| 1736 | /// |
| 1737 | /// By default, performs semantic analysis to build the new expression. |
| 1738 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1739 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1740 | SourceLocation TypeidLoc, |
| 1741 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1743 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1744 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1748 | /// \brief Build a new C++ typeid(expr) expression. |
| 1749 | /// |
| 1750 | /// By default, performs semantic analysis to build the new expression. |
| 1751 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1752 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1753 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1754 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1755 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1756 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1757 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1760 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1761 | /// |
| 1762 | /// By default, performs semantic analysis to build the new expression. |
| 1763 | /// Subclasses may override this routine to provide different behavior. |
| 1764 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1765 | SourceLocation TypeidLoc, |
| 1766 | TypeSourceInfo *Operand, |
| 1767 | SourceLocation RParenLoc) { |
| 1768 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1769 | RParenLoc); |
| 1770 | } |
| 1771 | |
| 1772 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1773 | /// |
| 1774 | /// By default, performs semantic analysis to build the new expression. |
| 1775 | /// Subclasses may override this routine to provide different behavior. |
| 1776 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1777 | SourceLocation TypeidLoc, |
| 1778 | Expr *Operand, |
| 1779 | SourceLocation RParenLoc) { |
| 1780 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1781 | RParenLoc); |
| 1782 | } |
| 1783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1784 | /// \brief Build a new C++ "this" expression. |
| 1785 | /// |
| 1786 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1787 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1789 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1790 | QualType ThisType, |
| 1791 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1792 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1793 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1794 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | /// \brief Build a new C++ throw expression. |
| 1798 | /// |
| 1799 | /// By default, performs semantic analysis to build the new expression. |
| 1800 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1801 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1802 | return getSema().ActOnCXXThrow(ThrowLoc, Sub); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | /// \brief Build a new C++ default-argument expression. |
| 1806 | /// |
| 1807 | /// By default, builds a new default-argument expression, which does not |
| 1808 | /// require any semantic analysis. Subclasses may override this routine to |
| 1809 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1810 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1811 | ParmVarDecl *Param) { |
| 1812 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1813 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | /// \brief Build a new C++ zero-initialization expression. |
| 1817 | /// |
| 1818 | /// By default, performs semantic analysis to build the new expression. |
| 1819 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1820 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1821 | SourceLocation LParenLoc, |
| 1822 | SourceLocation RParenLoc) { |
| 1823 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1825 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1826 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1827 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1828 | /// \brief Build a new C++ "new" expression. |
| 1829 | /// |
| 1830 | /// By default, performs semantic analysis to build the new expression. |
| 1831 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1832 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1833 | bool UseGlobal, |
| 1834 | SourceLocation PlacementLParen, |
| 1835 | MultiExprArg PlacementArgs, |
| 1836 | SourceLocation PlacementRParen, |
| 1837 | SourceRange TypeIdParens, |
| 1838 | QualType AllocatedType, |
| 1839 | TypeSourceInfo *AllocatedTypeInfo, |
| 1840 | Expr *ArraySize, |
| 1841 | SourceLocation ConstructorLParen, |
| 1842 | MultiExprArg ConstructorArgs, |
| 1843 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1845 | PlacementLParen, |
| 1846 | move(PlacementArgs), |
| 1847 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1848 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1849 | AllocatedType, |
| 1850 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1851 | ArraySize, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1852 | ConstructorLParen, |
| 1853 | move(ConstructorArgs), |
| 1854 | ConstructorRParen); |
| 1855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1857 | /// \brief Build a new C++ "delete" expression. |
| 1858 | /// |
| 1859 | /// By default, performs semantic analysis to build the new expression. |
| 1860 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1861 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1862 | bool IsGlobalDelete, |
| 1863 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1864 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1865 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1866 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1867 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1869 | /// \brief Build a new unary type trait expression. |
| 1870 | /// |
| 1871 | /// By default, performs semantic analysis to build the new expression. |
| 1872 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1873 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1874 | SourceLocation StartLoc, |
| 1875 | TypeSourceInfo *T, |
| 1876 | SourceLocation RParenLoc) { |
| 1877 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1880 | /// \brief Build a new binary type trait expression. |
| 1881 | /// |
| 1882 | /// By default, performs semantic analysis to build the new expression. |
| 1883 | /// Subclasses may override this routine to provide different behavior. |
| 1884 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1885 | SourceLocation StartLoc, |
| 1886 | TypeSourceInfo *LhsT, |
| 1887 | TypeSourceInfo *RhsT, |
| 1888 | SourceLocation RParenLoc) { |
| 1889 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1890 | } |
| 1891 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1893 | /// expression. |
| 1894 | /// |
| 1895 | /// By default, performs semantic analysis to build the new expression. |
| 1896 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1897 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 1898 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1899 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1900 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1901 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1902 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1903 | |
| 1904 | if (TemplateArgs) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1905 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1906 | *TemplateArgs); |
| 1907 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1908 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | /// \brief Build a new template-id expression. |
| 1912 | /// |
| 1913 | /// By default, performs semantic analysis to build the new expression. |
| 1914 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1915 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1916 | LookupResult &R, |
| 1917 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1918 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1919 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | /// \brief Build a new object-construction expression. |
| 1923 | /// |
| 1924 | /// By default, performs semantic analysis to build the new expression. |
| 1925 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1926 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1927 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1928 | CXXConstructorDecl *Constructor, |
| 1929 | bool IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1930 | MultiExprArg Args, |
| 1931 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1932 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 1933 | SourceRange ParenRange) { |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1934 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1935 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1936 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1937 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1938 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1939 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1940 | move_arg(ConvertedArgs), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1941 | RequiresZeroInit, ConstructKind, |
| 1942 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /// \brief Build a new object-construction expression. |
| 1946 | /// |
| 1947 | /// By default, performs semantic analysis to build the new expression. |
| 1948 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1949 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 1950 | SourceLocation LParenLoc, |
| 1951 | MultiExprArg Args, |
| 1952 | SourceLocation RParenLoc) { |
| 1953 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1954 | LParenLoc, |
| 1955 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1956 | RParenLoc); |
| 1957 | } |
| 1958 | |
| 1959 | /// \brief Build a new object-construction expression. |
| 1960 | /// |
| 1961 | /// By default, performs semantic analysis to build the new expression. |
| 1962 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1963 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 1964 | SourceLocation LParenLoc, |
| 1965 | MultiExprArg Args, |
| 1966 | SourceLocation RParenLoc) { |
| 1967 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1968 | LParenLoc, |
| 1969 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1970 | RParenLoc); |
| 1971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1973 | /// \brief Build a new member reference expression. |
| 1974 | /// |
| 1975 | /// By default, performs semantic analysis to build the new expression. |
| 1976 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1977 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1978 | QualType BaseType, |
| 1979 | bool IsArrow, |
| 1980 | SourceLocation OperatorLoc, |
| 1981 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1982 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1983 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1984 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1985 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1986 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1988 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1989 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1990 | SS, FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1991 | MemberNameInfo, |
| 1992 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1995 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1996 | /// |
| 1997 | /// By default, performs semantic analysis to build the new expression. |
| 1998 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1999 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2000 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2001 | SourceLocation OperatorLoc, |
| 2002 | bool IsArrow, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2003 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2004 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2005 | LookupResult &R, |
| 2006 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2007 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2008 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2010 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2011 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2012 | SS, FirstQualifierInScope, |
| 2013 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2016 | /// \brief Build a new noexcept expression. |
| 2017 | /// |
| 2018 | /// By default, performs semantic analysis to build the new expression. |
| 2019 | /// Subclasses may override this routine to provide different behavior. |
| 2020 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2021 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2022 | } |
| 2023 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2024 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2025 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2026 | SourceLocation PackLoc, |
| 2027 | SourceLocation RParenLoc, |
| 2028 | unsigned Length) { |
| 2029 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2030 | OperatorLoc, Pack, PackLoc, |
| 2031 | RParenLoc, Length); |
| 2032 | } |
| 2033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2034 | /// \brief Build a new Objective-C @encode expression. |
| 2035 | /// |
| 2036 | /// By default, performs semantic analysis to build the new expression. |
| 2037 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2038 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2039 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2040 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2041 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2042 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2043 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2045 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2046 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2047 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2048 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2049 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2050 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2051 | MultiExprArg Args, |
| 2052 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2053 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2054 | ReceiverTypeInfo->getType(), |
| 2055 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2056 | Sel, Method, LBracLoc, SelectorLoc, |
| 2057 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2061 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2062 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2063 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2064 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2065 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2066 | MultiExprArg Args, |
| 2067 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2068 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2069 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2070 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2071 | Sel, Method, LBracLoc, SelectorLoc, |
| 2072 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2075 | /// \brief Build a new Objective-C ivar reference expression. |
| 2076 | /// |
| 2077 | /// By default, performs semantic analysis to build the new expression. |
| 2078 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2079 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2080 | SourceLocation IvarLoc, |
| 2081 | bool IsArrow, bool IsFreeIvar) { |
| 2082 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2083 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2084 | Expr *Base = BaseArg; |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2085 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2086 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2087 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2088 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2089 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2090 | false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2091 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2092 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2093 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2094 | if (Result.get()) |
| 2095 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2096 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2097 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2098 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2099 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2100 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2101 | /*TemplateArgs=*/0); |
| 2102 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2103 | |
| 2104 | /// \brief Build a new Objective-C property reference expression. |
| 2105 | /// |
| 2106 | /// By default, performs semantic analysis to build the new expression. |
| 2107 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2108 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2109 | ObjCPropertyDecl *Property, |
| 2110 | SourceLocation PropertyLoc) { |
| 2111 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2112 | Expr *Base = BaseArg; |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2113 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2114 | Sema::LookupMemberName); |
| 2115 | bool IsArrow = false; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2116 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2117 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2118 | SS, 0, false); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2119 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2120 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2121 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2122 | if (Result.get()) |
| 2123 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2124 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2125 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2126 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2127 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2128 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2129 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2130 | /*TemplateArgs=*/0); |
| 2131 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2132 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2133 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2134 | /// |
| 2135 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2136 | /// Subclasses may override this routine to provide different behavior. |
| 2137 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2138 | ObjCMethodDecl *Getter, |
| 2139 | ObjCMethodDecl *Setter, |
| 2140 | SourceLocation PropertyLoc) { |
| 2141 | // Since these expressions can only be value-dependent, we do not |
| 2142 | // need to perform semantic analysis again. |
| 2143 | return Owned( |
| 2144 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2145 | VK_LValue, OK_ObjCProperty, |
| 2146 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2149 | /// \brief Build a new Objective-C "isa" expression. |
| 2150 | /// |
| 2151 | /// By default, performs semantic analysis to build the new expression. |
| 2152 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2153 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2154 | bool IsArrow) { |
| 2155 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2156 | Expr *Base = BaseArg; |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2157 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2158 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2159 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2160 | /*FIME:*/IsaLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2161 | SS, 0, false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2162 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2163 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2164 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2165 | if (Result.get()) |
| 2166 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2167 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2168 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2169 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2170 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2171 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2172 | /*TemplateArgs=*/0); |
| 2173 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2174 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2175 | /// \brief Build a new shuffle vector expression. |
| 2176 | /// |
| 2177 | /// By default, performs semantic analysis to build the new expression. |
| 2178 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2179 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2180 | MultiExprArg SubExprs, |
| 2181 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2182 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2184 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2185 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2186 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2187 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2188 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2189 | // Build a reference to the __builtin_shufflevector builtin |
| 2190 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2192 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2193 | VK_LValue, BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2194 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2195 | |
| 2196 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2197 | unsigned NumSubExprs = SubExprs.size(); |
| 2198 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2199 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 2200 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2201 | Builtin->getCallResultType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2202 | Expr::getValueKindForType(Builtin->getResultType()), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2203 | RParenLoc); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2204 | ExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2206 | // Type-check the __builtin_shufflevector expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2207 | ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2208 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2209 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2211 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2213 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2214 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2215 | /// \brief Build a new template argument pack expansion. |
| 2216 | /// |
| 2217 | /// By default, performs semantic analysis to build a new pack expansion |
| 2218 | /// for a template argument. Subclasses may override this routine to provide |
| 2219 | /// different behavior. |
| 2220 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2221 | SourceLocation EllipsisLoc, |
| 2222 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2223 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2224 | case TemplateArgument::Expression: { |
| 2225 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2226 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2227 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2228 | if (Result.isInvalid()) |
| 2229 | return TemplateArgumentLoc(); |
| 2230 | |
| 2231 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2232 | } |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2233 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2234 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2235 | return TemplateArgumentLoc(TemplateArgument( |
| 2236 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2237 | NumExpansions), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2238 | Pattern.getTemplateQualifierRange(), |
| 2239 | Pattern.getTemplateNameLoc(), |
| 2240 | EllipsisLoc); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2241 | |
| 2242 | case TemplateArgument::Null: |
| 2243 | case TemplateArgument::Integral: |
| 2244 | case TemplateArgument::Declaration: |
| 2245 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2246 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2247 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2248 | |
| 2249 | case TemplateArgument::Type: |
| 2250 | if (TypeSourceInfo *Expansion |
| 2251 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2252 | EllipsisLoc, |
| 2253 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2254 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2255 | Expansion); |
| 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | return TemplateArgumentLoc(); |
| 2260 | } |
| 2261 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2262 | /// \brief Build a new expression pack expansion. |
| 2263 | /// |
| 2264 | /// By default, performs semantic analysis to build a new pack expansion |
| 2265 | /// for an expression. Subclasses may override this routine to provide |
| 2266 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2267 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2268 | llvm::Optional<unsigned> NumExpansions) { |
| 2269 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2272 | private: |
| 2273 | QualType TransformTypeInObjectScope(QualType T, |
| 2274 | QualType ObjectType, |
| 2275 | NamedDecl *FirstQualifierInScope, |
| 2276 | NestedNameSpecifier *Prefix); |
| 2277 | |
| 2278 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T, |
| 2279 | QualType ObjectType, |
| 2280 | NamedDecl *FirstQualifierInScope, |
| 2281 | NestedNameSpecifier *Prefix); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2282 | |
| 2283 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2284 | QualType ObjectType, |
| 2285 | NamedDecl *FirstQualifierInScope, |
| 2286 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2287 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2288 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2289 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2290 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2291 | if (!S) |
| 2292 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2293 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2294 | switch (S->getStmtClass()) { |
| 2295 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2296 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2297 | // Transform individual statement nodes |
| 2298 | #define STMT(Node, Parent) \ |
| 2299 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2300 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2301 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2302 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2304 | // Transform expressions by calling TransformExpr. |
| 2305 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2306 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2307 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2308 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2309 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2310 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2311 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2312 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2313 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2314 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2315 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2318 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2319 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2320 | |
| 2321 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2322 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2323 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2324 | if (!E) |
| 2325 | return SemaRef.Owned(E); |
| 2326 | |
| 2327 | switch (E->getStmtClass()) { |
| 2328 | case Stmt::NoStmtClass: break; |
| 2329 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2330 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2331 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2332 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2333 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2336 | return SemaRef.Owned(E); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | template<typename Derived> |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2340 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2341 | unsigned NumInputs, |
| 2342 | bool IsCall, |
| 2343 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 2344 | bool *ArgChanged) { |
| 2345 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2346 | // If requested, drop call arguments that need to be dropped. |
| 2347 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2348 | if (ArgChanged) |
| 2349 | *ArgChanged = true; |
| 2350 | |
| 2351 | break; |
| 2352 | } |
| 2353 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2354 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2355 | Expr *Pattern = Expansion->getPattern(); |
| 2356 | |
| 2357 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2358 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2359 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2360 | |
| 2361 | // Determine whether the set of unexpanded parameter packs can and should |
| 2362 | // be expanded. |
| 2363 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2364 | bool RetainExpansion = false; |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2365 | llvm::Optional<unsigned> OrigNumExpansions |
| 2366 | = Expansion->getNumExpansions(); |
| 2367 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2368 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2369 | Pattern->getSourceRange(), |
| 2370 | Unexpanded.data(), |
| 2371 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2372 | Expand, RetainExpansion, |
| 2373 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2374 | return true; |
| 2375 | |
| 2376 | if (!Expand) { |
| 2377 | // The transform has determined that we should perform a simple |
| 2378 | // transformation on the pack expansion, producing another pack |
| 2379 | // expansion. |
| 2380 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2381 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2382 | if (OutPattern.isInvalid()) |
| 2383 | return true; |
| 2384 | |
| 2385 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2386 | Expansion->getEllipsisLoc(), |
| 2387 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2388 | if (Out.isInvalid()) |
| 2389 | return true; |
| 2390 | |
| 2391 | if (ArgChanged) |
| 2392 | *ArgChanged = true; |
| 2393 | Outputs.push_back(Out.get()); |
| 2394 | continue; |
| 2395 | } |
| 2396 | |
| 2397 | // The transform has determined that we should perform an elementwise |
| 2398 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2399 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2400 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2401 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2402 | if (Out.isInvalid()) |
| 2403 | return true; |
| 2404 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2405 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2406 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2407 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2408 | if (Out.isInvalid()) |
| 2409 | return true; |
| 2410 | } |
| 2411 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2412 | if (ArgChanged) |
| 2413 | *ArgChanged = true; |
| 2414 | Outputs.push_back(Out.get()); |
| 2415 | } |
| 2416 | |
| 2417 | continue; |
| 2418 | } |
| 2419 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2420 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2421 | if (Result.isInvalid()) |
| 2422 | return true; |
| 2423 | |
| 2424 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2425 | *ArgChanged = true; |
| 2426 | |
| 2427 | Outputs.push_back(Result.get()); |
| 2428 | } |
| 2429 | |
| 2430 | return false; |
| 2431 | } |
| 2432 | |
| 2433 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2434 | NestedNameSpecifier * |
| 2435 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2436 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2437 | QualType ObjectType, |
| 2438 | NamedDecl *FirstQualifierInScope) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2439 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2441 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2442 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2444 | ObjectType, |
| 2445 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2446 | if (!Prefix) |
| 2447 | return 0; |
| 2448 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2449 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2450 | switch (NNS->getKind()) { |
| 2451 | case NestedNameSpecifier::Identifier: |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2452 | if (Prefix) { |
| 2453 | // The object type and qualifier-in-scope really apply to the |
| 2454 | // leftmost entity. |
| 2455 | ObjectType = QualType(); |
| 2456 | FirstQualifierInScope = 0; |
| 2457 | } |
| 2458 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2459 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2460 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2461 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2462 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2463 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2464 | |
| 2465 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2466 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2467 | ObjectType, |
| 2468 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2469 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2470 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2471 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2472 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2473 | getDerived().TransformDecl(Range.getBegin(), |
| 2474 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2475 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2476 | Prefix == NNS->getPrefix() && |
| 2477 | NS == NNS->getAsNamespace()) |
| 2478 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2479 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2480 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2482 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 2483 | case NestedNameSpecifier::NamespaceAlias: { |
| 2484 | NamespaceAliasDecl *Alias |
| 2485 | = cast_or_null<NamespaceAliasDecl>( |
| 2486 | getDerived().TransformDecl(Range.getBegin(), |
| 2487 | NNS->getAsNamespaceAlias())); |
| 2488 | if (!getDerived().AlwaysRebuild() && |
| 2489 | Prefix == NNS->getPrefix() && |
| 2490 | Alias == NNS->getAsNamespaceAlias()) |
| 2491 | return NNS; |
| 2492 | |
| 2493 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias); |
| 2494 | } |
| 2495 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2496 | case NestedNameSpecifier::Global: |
| 2497 | // There is no meaningful transformation that one could perform on the |
| 2498 | // global scope. |
| 2499 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2500 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2501 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2502 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2503 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2504 | QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0), |
| 2505 | ObjectType, |
| 2506 | FirstQualifierInScope, |
| 2507 | Prefix); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2508 | if (T.isNull()) |
| 2509 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2510 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2511 | if (!getDerived().AlwaysRebuild() && |
| 2512 | Prefix == NNS->getPrefix() && |
| 2513 | T == QualType(NNS->getAsType(), 0)) |
| 2514 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2515 | |
| 2516 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2517 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2518 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2519 | } |
| 2520 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2521 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2522 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2523 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2527 | NestedNameSpecifierLoc |
| 2528 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2529 | NestedNameSpecifierLoc NNS, |
| 2530 | QualType ObjectType, |
| 2531 | NamedDecl *FirstQualifierInScope) { |
| 2532 | llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 2533 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2534 | Qualifier = Qualifier.getPrefix()) |
| 2535 | Qualifiers.push_back(Qualifier); |
| 2536 | |
| 2537 | CXXScopeSpec SS; |
| 2538 | while (!Qualifiers.empty()) { |
| 2539 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2540 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2541 | |
| 2542 | switch (QNNS->getKind()) { |
| 2543 | case NestedNameSpecifier::Identifier: |
| 2544 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2545 | *QNNS->getAsIdentifier(), |
| 2546 | Q.getLocalBeginLoc(), |
| 2547 | Q.getLocalEndLoc(), |
| 2548 | ObjectType, false, SS, |
| 2549 | FirstQualifierInScope, false)) |
| 2550 | return NestedNameSpecifierLoc(); |
| 2551 | |
| 2552 | break; |
| 2553 | |
| 2554 | case NestedNameSpecifier::Namespace: { |
| 2555 | NamespaceDecl *NS |
| 2556 | = cast_or_null<NamespaceDecl>( |
| 2557 | getDerived().TransformDecl( |
| 2558 | Q.getLocalBeginLoc(), |
| 2559 | QNNS->getAsNamespace())); |
| 2560 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2561 | break; |
| 2562 | } |
| 2563 | |
| 2564 | case NestedNameSpecifier::NamespaceAlias: { |
| 2565 | NamespaceAliasDecl *Alias |
| 2566 | = cast_or_null<NamespaceAliasDecl>( |
| 2567 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2568 | QNNS->getAsNamespaceAlias())); |
| 2569 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2570 | Q.getLocalEndLoc()); |
| 2571 | break; |
| 2572 | } |
| 2573 | |
| 2574 | case NestedNameSpecifier::Global: |
| 2575 | // There is no meaningful transformation that one could perform on the |
| 2576 | // global scope. |
| 2577 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2578 | break; |
| 2579 | |
| 2580 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2581 | case NestedNameSpecifier::TypeSpec: { |
| 2582 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2583 | FirstQualifierInScope, SS); |
| 2584 | |
| 2585 | if (!TL) |
| 2586 | return NestedNameSpecifierLoc(); |
| 2587 | |
| 2588 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 2589 | (SemaRef.getLangOptions().CPlusPlus0x && |
| 2590 | TL.getType()->isEnumeralType())) { |
| 2591 | assert(!TL.getType().hasLocalQualifiers() && |
| 2592 | "Can't get cv-qualifiers here"); |
| 2593 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2594 | Q.getLocalEndLoc()); |
| 2595 | break; |
| 2596 | } |
| 2597 | |
| 2598 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2599 | << TL.getType() << SS.getRange(); |
| 2600 | return NestedNameSpecifierLoc(); |
| 2601 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2602 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2603 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2604 | // 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] | 2605 | FirstQualifierInScope = 0; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2606 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2610 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2611 | !getDerived().AlwaysRebuild()) |
| 2612 | return NNS; |
| 2613 | |
| 2614 | // If we can re-use the source-location data from the original |
| 2615 | // nested-name-specifier, do so. |
| 2616 | if (SS.location_size() == NNS.getDataLength() && |
| 2617 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2618 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2619 | |
| 2620 | // Allocate new nested-name-specifier location information. |
| 2621 | return SS.getWithLocInContext(SemaRef.Context); |
| 2622 | } |
| 2623 | |
| 2624 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2625 | DeclarationNameInfo |
| 2626 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2627 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2628 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2629 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2630 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2631 | |
| 2632 | switch (Name.getNameKind()) { |
| 2633 | case DeclarationName::Identifier: |
| 2634 | case DeclarationName::ObjCZeroArgSelector: |
| 2635 | case DeclarationName::ObjCOneArgSelector: |
| 2636 | case DeclarationName::ObjCMultiArgSelector: |
| 2637 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2638 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2639 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2640 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2641 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2642 | case DeclarationName::CXXConstructorName: |
| 2643 | case DeclarationName::CXXDestructorName: |
| 2644 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2645 | TypeSourceInfo *NewTInfo; |
| 2646 | CanQualType NewCanTy; |
| 2647 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2648 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2649 | if (!NewTInfo) |
| 2650 | return DeclarationNameInfo(); |
| 2651 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2652 | } |
| 2653 | else { |
| 2654 | NewTInfo = 0; |
| 2655 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2656 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2657 | if (NewT.isNull()) |
| 2658 | return DeclarationNameInfo(); |
| 2659 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2661 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2662 | DeclarationName NewName |
| 2663 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2664 | NewCanTy); |
| 2665 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2666 | NewNameInfo.setName(NewName); |
| 2667 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2668 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | } |
| 2671 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2672 | assert(0 && "Unknown name kind."); |
| 2673 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2677 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2678 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2679 | QualType ObjectType, |
| 2680 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2681 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2682 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2683 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2684 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2685 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2686 | /*FIXME*/ SourceRange(Loc), |
| 2687 | ObjectType, |
| 2688 | FirstQualifierInScope); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2689 | if (!NNS) |
| 2690 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2692 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2693 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2694 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2695 | if (!TransTemplate) |
| 2696 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2698 | if (!getDerived().AlwaysRebuild() && |
| 2699 | NNS == QTN->getQualifier() && |
| 2700 | TransTemplate == Template) |
| 2701 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2703 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2704 | TransTemplate); |
| 2705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2706 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2707 | // These should be getting filtered out before they make it into the AST. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2708 | llvm_unreachable("overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2710 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2711 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2712 | NestedNameSpecifier *NNS = DTN->getQualifier(); |
| 2713 | if (NNS) { |
| 2714 | NNS = getDerived().TransformNestedNameSpecifier(NNS, |
| 2715 | /*FIXME:*/SourceRange(Loc), |
| 2716 | ObjectType, |
| 2717 | FirstQualifierInScope); |
| 2718 | if (!NNS) return TemplateName(); |
| 2719 | |
| 2720 | // These apply to the scope specifier, not the template. |
| 2721 | ObjectType = QualType(); |
| 2722 | FirstQualifierInScope = 0; |
| 2723 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2724 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2725 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2726 | NNS == DTN->getQualifier() && |
| 2727 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2728 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2729 | |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2730 | if (DTN->isIdentifier()) { |
| 2731 | // FIXME: Bad range |
| 2732 | SourceRange QualifierRange(getDerived().getBaseLocation()); |
| 2733 | return getDerived().RebuildTemplateName(NNS, QualifierRange, |
| 2734 | *DTN->getIdentifier(), |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2735 | ObjectType, |
| 2736 | FirstQualifierInScope); |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 2737 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2738 | |
| 2739 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2740 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2741 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2743 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2744 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2745 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2746 | if (!TransTemplate) |
| 2747 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2749 | if (!getDerived().AlwaysRebuild() && |
| 2750 | TransTemplate == Template) |
| 2751 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2752 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2753 | return TemplateName(TransTemplate); |
| 2754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2755 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 2756 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2757 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2758 | TemplateTemplateParmDecl *TransParam |
| 2759 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2760 | getDerived().TransformDecl(Loc, SubstPack->getParameterPack())); |
| 2761 | if (!TransParam) |
| 2762 | return TemplateName(); |
| 2763 | |
| 2764 | if (!getDerived().AlwaysRebuild() && |
| 2765 | TransParam == SubstPack->getParameterPack()) |
| 2766 | return Name; |
| 2767 | |
| 2768 | return getDerived().RebuildTemplateName(TransParam, |
| 2769 | SubstPack->getArgumentPack()); |
| 2770 | } |
| 2771 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2772 | // These should be getting filtered out before they reach the AST. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2773 | llvm_unreachable("overloaded function decl survived to here"); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2774 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2778 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2779 | const TemplateArgument &Arg, |
| 2780 | TemplateArgumentLoc &Output) { |
| 2781 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2782 | switch (Arg.getKind()) { |
| 2783 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2784 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2785 | break; |
| 2786 | |
| 2787 | case TemplateArgument::Type: |
| 2788 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2789 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2790 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2791 | break; |
| 2792 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2793 | case TemplateArgument::Template: |
| 2794 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2795 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2796 | |
| 2797 | case TemplateArgument::TemplateExpansion: |
| 2798 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc); |
| 2799 | break; |
| 2800 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2801 | case TemplateArgument::Expression: |
| 2802 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2803 | break; |
| 2804 | |
| 2805 | case TemplateArgument::Declaration: |
| 2806 | case TemplateArgument::Integral: |
| 2807 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2808 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | template<typename Derived> |
| 2814 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2815 | const TemplateArgumentLoc &Input, |
| 2816 | TemplateArgumentLoc &Output) { |
| 2817 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2818 | switch (Arg.getKind()) { |
| 2819 | case TemplateArgument::Null: |
| 2820 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2821 | Output = Input; |
| 2822 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2823 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2824 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2825 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2826 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2827 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2828 | |
| 2829 | DI = getDerived().TransformType(DI); |
| 2830 | if (!DI) return true; |
| 2831 | |
| 2832 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2833 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2834 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2836 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2837 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2838 | DeclarationName Name; |
| 2839 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2840 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2841 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2842 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2843 | if (!D) return true; |
| 2844 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2845 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2846 | if (SourceExpr) { |
| 2847 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2848 | Sema::Unevaluated); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2849 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2850 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2854 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2857 | case TemplateArgument::Template: { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2858 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2859 | TemplateName Template |
| 2860 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2861 | if (Template.isNull()) |
| 2862 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2863 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2864 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2865 | Input.getTemplateQualifierRange(), |
| 2866 | Input.getTemplateNameLoc()); |
| 2867 | return false; |
| 2868 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2869 | |
| 2870 | case TemplateArgument::TemplateExpansion: |
| 2871 | llvm_unreachable("Caller should expand pack expansions"); |
| 2872 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2873 | case TemplateArgument::Expression: { |
| 2874 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2875 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2876 | Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2878 | Expr *InputExpr = Input.getSourceExpression(); |
| 2879 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2880 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2881 | ExprResult E |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2882 | = getDerived().TransformExpr(InputExpr); |
| 2883 | if (E.isInvalid()) return true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2884 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2885 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2886 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2887 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2888 | case TemplateArgument::Pack: { |
| 2889 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2890 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2891 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2892 | AEnd = Arg.pack_end(); |
| 2893 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2894 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2895 | // FIXME: preserve source information here when we start |
| 2896 | // caring about parameter packs. |
| 2897 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2898 | TemplateArgumentLoc InputArg; |
| 2899 | TemplateArgumentLoc OutputArg; |
| 2900 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2901 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2902 | return true; |
| 2903 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2904 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2905 | } |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2906 | |
| 2907 | TemplateArgument *TransformedArgsPtr |
| 2908 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2909 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2910 | TransformedArgsPtr); |
| 2911 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2912 | TransformedArgs.size()), |
| 2913 | Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2914 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2915 | } |
| 2916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2917 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2918 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2919 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2920 | } |
| 2921 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2922 | /// \brief Iterator adaptor that invents template argument location information |
| 2923 | /// for each of the template arguments in its underlying iterator. |
| 2924 | template<typename Derived, typename InputIterator> |
| 2925 | class TemplateArgumentLocInventIterator { |
| 2926 | TreeTransform<Derived> &Self; |
| 2927 | InputIterator Iter; |
| 2928 | |
| 2929 | public: |
| 2930 | typedef TemplateArgumentLoc value_type; |
| 2931 | typedef TemplateArgumentLoc reference; |
| 2932 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2933 | difference_type; |
| 2934 | typedef std::input_iterator_tag iterator_category; |
| 2935 | |
| 2936 | class pointer { |
| 2937 | TemplateArgumentLoc Arg; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2938 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2939 | public: |
| 2940 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2941 | |
| 2942 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2943 | }; |
| 2944 | |
| 2945 | TemplateArgumentLocInventIterator() { } |
| 2946 | |
| 2947 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2948 | InputIterator Iter) |
| 2949 | : Self(Self), Iter(Iter) { } |
| 2950 | |
| 2951 | TemplateArgumentLocInventIterator &operator++() { |
| 2952 | ++Iter; |
| 2953 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2956 | TemplateArgumentLocInventIterator operator++(int) { |
| 2957 | TemplateArgumentLocInventIterator Old(*this); |
| 2958 | ++(*this); |
| 2959 | return Old; |
| 2960 | } |
| 2961 | |
| 2962 | reference operator*() const { |
| 2963 | TemplateArgumentLoc Result; |
| 2964 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 2965 | return Result; |
| 2966 | } |
| 2967 | |
| 2968 | pointer operator->() const { return pointer(**this); } |
| 2969 | |
| 2970 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 2971 | const TemplateArgumentLocInventIterator &Y) { |
| 2972 | return X.Iter == Y.Iter; |
| 2973 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2975 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 2976 | const TemplateArgumentLocInventIterator &Y) { |
| 2977 | return X.Iter != Y.Iter; |
| 2978 | } |
| 2979 | }; |
| 2980 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2981 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2982 | template<typename InputIterator> |
| 2983 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 2984 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2985 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2986 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2987 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2988 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2989 | |
| 2990 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 2991 | // Unpack argument packs, which we translate them into separate |
| 2992 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2993 | // FIXME: We could do much better if we could guarantee that the |
| 2994 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 2995 | // all of the template arguments in the argument pack. |
| 2996 | typedef TemplateArgumentLocInventIterator<Derived, |
| 2997 | TemplateArgument::pack_iterator> |
| 2998 | PackLocIterator; |
| 2999 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 3000 | In.getArgument().pack_begin()), |
| 3001 | PackLocIterator(*this, |
| 3002 | In.getArgument().pack_end()), |
| 3003 | Outputs)) |
| 3004 | return true; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3005 | |
| 3006 | continue; |
| 3007 | } |
| 3008 | |
| 3009 | if (In.getArgument().isPackExpansion()) { |
| 3010 | // We have a pack expansion, for which we will be substituting into |
| 3011 | // the pattern. |
| 3012 | SourceLocation Ellipsis; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3013 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3014 | TemplateArgumentLoc Pattern |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3015 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 3016 | getSema().Context); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3017 | |
| 3018 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3019 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3020 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 3021 | |
| 3022 | // Determine whether the set of unexpanded parameter packs can and should |
| 3023 | // be expanded. |
| 3024 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3025 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3026 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3027 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3028 | Pattern.getSourceRange(), |
| 3029 | Unexpanded.data(), |
| 3030 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3031 | Expand, |
| 3032 | RetainExpansion, |
| 3033 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3034 | return true; |
| 3035 | |
| 3036 | if (!Expand) { |
| 3037 | // The transform has determined that we should perform a simple |
| 3038 | // transformation on the pack expansion, producing another pack |
| 3039 | // expansion. |
| 3040 | TemplateArgumentLoc OutPattern; |
| 3041 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3042 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3043 | return true; |
| 3044 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3045 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3046 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3047 | if (Out.getArgument().isNull()) |
| 3048 | return true; |
| 3049 | |
| 3050 | Outputs.addArgument(Out); |
| 3051 | continue; |
| 3052 | } |
| 3053 | |
| 3054 | // The transform has determined that we should perform an elementwise |
| 3055 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3056 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3057 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3058 | |
| 3059 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3060 | return true; |
| 3061 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3062 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3063 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3064 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3065 | if (Out.getArgument().isNull()) |
| 3066 | return true; |
| 3067 | } |
| 3068 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3069 | Outputs.addArgument(Out); |
| 3070 | } |
| 3071 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3072 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3073 | // forgetting the partially-substituted parameter pack. |
| 3074 | if (RetainExpansion) { |
| 3075 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3076 | |
| 3077 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3078 | return true; |
| 3079 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3080 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3081 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3082 | if (Out.getArgument().isNull()) |
| 3083 | return true; |
| 3084 | |
| 3085 | Outputs.addArgument(Out); |
| 3086 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3088 | continue; |
| 3089 | } |
| 3090 | |
| 3091 | // The simple case: |
| 3092 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3093 | return true; |
| 3094 | |
| 3095 | Outputs.addArgument(Out); |
| 3096 | } |
| 3097 | |
| 3098 | return false; |
| 3099 | |
| 3100 | } |
| 3101 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3102 | //===----------------------------------------------------------------------===// |
| 3103 | // Type transformation |
| 3104 | //===----------------------------------------------------------------------===// |
| 3105 | |
| 3106 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3107 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3108 | if (getDerived().AlreadyTransformed(T)) |
| 3109 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3110 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3111 | // Temporary workaround. All of these transformations should |
| 3112 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3113 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3114 | getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3115 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3116 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3117 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3118 | if (!NewDI) |
| 3119 | return QualType(); |
| 3120 | |
| 3121 | return NewDI->getType(); |
| 3122 | } |
| 3123 | |
| 3124 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3125 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3126 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3127 | return DI; |
| 3128 | |
| 3129 | TypeLocBuilder TLB; |
| 3130 | |
| 3131 | TypeLoc TL = DI->getTypeLoc(); |
| 3132 | TLB.reserve(TL.getFullDataSize()); |
| 3133 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3134 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3135 | if (Result.isNull()) |
| 3136 | return 0; |
| 3137 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3138 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | template<typename Derived> |
| 3142 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3143 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3144 | switch (T.getTypeLocClass()) { |
| 3145 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3146 | #define TYPELOC(CLASS, PARENT) \ |
| 3147 | case TypeLoc::CLASS: \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3148 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3149 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3151 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3152 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3153 | return QualType(); |
| 3154 | } |
| 3155 | |
| 3156 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3157 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3158 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3159 | /// types). This is the right thing for template instantiation, but |
| 3160 | /// probably not for other clients. |
| 3161 | template<typename Derived> |
| 3162 | QualType |
| 3163 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3164 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3165 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3166 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3167 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3168 | if (Result.isNull()) |
| 3169 | return QualType(); |
| 3170 | |
| 3171 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3172 | // FIXME: this is the right thing for template instantiation, but |
| 3173 | // probably not for other clients. |
| 3174 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3175 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3176 | |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3177 | if (!Quals.empty()) { |
| 3178 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3179 | TLB.push<QualifiedTypeLoc>(Result); |
| 3180 | // No location information to preserve. |
| 3181 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3182 | |
| 3183 | return Result; |
| 3184 | } |
| 3185 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3186 | /// \brief Transforms a type that was written in a scope specifier, |
| 3187 | /// given an object type, the results of unqualified lookup, and |
| 3188 | /// an already-instantiated prefix. |
| 3189 | /// |
| 3190 | /// The object type is provided iff the scope specifier qualifies the |
| 3191 | /// member of a dependent member-access expression. The prefix is |
| 3192 | /// provided iff the the scope specifier in which this appears has a |
| 3193 | /// prefix. |
| 3194 | /// |
| 3195 | /// This is private to TreeTransform. |
| 3196 | template<typename Derived> |
| 3197 | QualType |
| 3198 | TreeTransform<Derived>::TransformTypeInObjectScope(QualType T, |
| 3199 | QualType ObjectType, |
| 3200 | NamedDecl *UnqualLookup, |
| 3201 | NestedNameSpecifier *Prefix) { |
| 3202 | if (getDerived().AlreadyTransformed(T)) |
| 3203 | return T; |
| 3204 | |
| 3205 | TypeSourceInfo *TSI = |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3206 | SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation()); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3207 | |
| 3208 | TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType, |
| 3209 | UnqualLookup, Prefix); |
| 3210 | if (!TSI) return QualType(); |
| 3211 | return TSI->getType(); |
| 3212 | } |
| 3213 | |
| 3214 | template<typename Derived> |
| 3215 | TypeSourceInfo * |
| 3216 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI, |
| 3217 | QualType ObjectType, |
| 3218 | NamedDecl *UnqualLookup, |
| 3219 | NestedNameSpecifier *Prefix) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3220 | // TODO: in some cases, we might have some verification to do here. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3221 | if (ObjectType.isNull()) |
| 3222 | return getDerived().TransformType(TSI); |
| 3223 | |
| 3224 | QualType T = TSI->getType(); |
| 3225 | if (getDerived().AlreadyTransformed(T)) |
| 3226 | return TSI; |
| 3227 | |
| 3228 | TypeLocBuilder TLB; |
| 3229 | QualType Result; |
| 3230 | |
| 3231 | if (isa<TemplateSpecializationType>(T)) { |
| 3232 | TemplateSpecializationTypeLoc TL |
| 3233 | = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3234 | |
| 3235 | TemplateName Template = |
| 3236 | getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(), |
| 3237 | ObjectType, UnqualLookup); |
| 3238 | if (Template.isNull()) return 0; |
| 3239 | |
| 3240 | Result = getDerived() |
| 3241 | .TransformTemplateSpecializationType(TLB, TL, Template); |
| 3242 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3243 | DependentTemplateSpecializationTypeLoc TL |
| 3244 | = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 3245 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3246 | TemplateName Template |
| 3247 | = SemaRef.Context.getDependentTemplateName( |
| 3248 | TL.getTypePtr()->getQualifier(), |
| 3249 | TL.getTypePtr()->getIdentifier()); |
| 3250 | |
| 3251 | Template = getDerived().TransformTemplateName(Template, ObjectType, |
| 3252 | UnqualLookup); |
| 3253 | if (Template.isNull()) |
| 3254 | return 0; |
| 3255 | |
| 3256 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL, |
| 3257 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3258 | } else { |
| 3259 | // Nothing special needs to be done for these. |
| 3260 | Result = getDerived().TransformType(TLB, TSI->getTypeLoc()); |
| 3261 | } |
| 3262 | |
| 3263 | if (Result.isNull()) return 0; |
| 3264 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3265 | } |
| 3266 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3267 | template<typename Derived> |
| 3268 | TypeLoc |
| 3269 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3270 | QualType ObjectType, |
| 3271 | NamedDecl *UnqualLookup, |
| 3272 | CXXScopeSpec &SS) { |
| 3273 | // FIXME: Painfully copy-paste from the above! |
| 3274 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3275 | QualType T = TL.getType(); |
| 3276 | if (getDerived().AlreadyTransformed(T)) |
| 3277 | return TL; |
| 3278 | |
| 3279 | TypeLocBuilder TLB; |
| 3280 | QualType Result; |
| 3281 | |
| 3282 | if (isa<TemplateSpecializationType>(T)) { |
| 3283 | TemplateSpecializationTypeLoc SpecTL |
| 3284 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3285 | |
| 3286 | TemplateName Template = |
| 3287 | getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(), |
| 3288 | ObjectType, UnqualLookup); |
| 3289 | if (Template.isNull()) |
| 3290 | return TypeLoc(); |
| 3291 | |
| 3292 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3293 | Template); |
| 3294 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3295 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3296 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3297 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3298 | TemplateName Template |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3299 | = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(), |
| 3300 | *SpecTL.getTypePtr()->getIdentifier(), |
| 3301 | ObjectType, UnqualLookup); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3302 | if (Template.isNull()) |
| 3303 | return TypeLoc(); |
| 3304 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3305 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3306 | SpecTL, |
| 3307 | Template); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3308 | } else { |
| 3309 | // Nothing special needs to be done for these. |
| 3310 | Result = getDerived().TransformType(TLB, TL); |
| 3311 | } |
| 3312 | |
| 3313 | if (Result.isNull()) |
| 3314 | return TypeLoc(); |
| 3315 | |
| 3316 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3317 | } |
| 3318 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3319 | template <class TyLoc> static inline |
| 3320 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3321 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3322 | NewT.setNameLoc(T.getNameLoc()); |
| 3323 | return T.getType(); |
| 3324 | } |
| 3325 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3326 | template<typename Derived> |
| 3327 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3328 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3329 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3330 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3331 | if (T.needsExtraLocalData()) |
| 3332 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3333 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3334 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3335 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3336 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3337 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3338 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3339 | // FIXME: recurse? |
| 3340 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3343 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3344 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3345 | PointerTypeLoc TL) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3346 | QualType PointeeType |
| 3347 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3348 | if (PointeeType.isNull()) |
| 3349 | return QualType(); |
| 3350 | |
| 3351 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3352 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3353 | // A dependent pointer type 'T *' has is being transformed such |
| 3354 | // that an Objective-C class type is being replaced for 'T'. The |
| 3355 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3356 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3357 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3358 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3359 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3360 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3361 | return Result; |
| 3362 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3363 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3364 | if (getDerived().AlwaysRebuild() || |
| 3365 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3366 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3367 | if (Result.isNull()) |
| 3368 | return QualType(); |
| 3369 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3370 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3371 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3372 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3373 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3374 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3375 | |
| 3376 | template<typename Derived> |
| 3377 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3378 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3379 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3380 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3381 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3382 | if (PointeeType.isNull()) |
| 3383 | return QualType(); |
| 3384 | |
| 3385 | QualType Result = TL.getType(); |
| 3386 | if (getDerived().AlwaysRebuild() || |
| 3387 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3388 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3389 | TL.getSigilLoc()); |
| 3390 | if (Result.isNull()) |
| 3391 | return QualType(); |
| 3392 | } |
| 3393 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3394 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3395 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3396 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3399 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3400 | /// don't care whether the type itself is an l-value type or an r-value |
| 3401 | /// type; we only care if the type was *written* as an l-value type |
| 3402 | /// or an r-value type. |
| 3403 | template<typename Derived> |
| 3404 | QualType |
| 3405 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3406 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3407 | const ReferenceType *T = TL.getTypePtr(); |
| 3408 | |
| 3409 | // Note that this works with the pointee-as-written. |
| 3410 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3411 | if (PointeeType.isNull()) |
| 3412 | return QualType(); |
| 3413 | |
| 3414 | QualType Result = TL.getType(); |
| 3415 | if (getDerived().AlwaysRebuild() || |
| 3416 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3417 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3418 | T->isSpelledAsLValue(), |
| 3419 | TL.getSigilLoc()); |
| 3420 | if (Result.isNull()) |
| 3421 | return QualType(); |
| 3422 | } |
| 3423 | |
| 3424 | // r-value references can be rebuilt as l-value references. |
| 3425 | ReferenceTypeLoc NewTL; |
| 3426 | if (isa<LValueReferenceType>(Result)) |
| 3427 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3428 | else |
| 3429 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3430 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3431 | |
| 3432 | return Result; |
| 3433 | } |
| 3434 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | template<typename Derived> |
| 3436 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3437 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3438 | LValueReferenceTypeLoc TL) { |
| 3439 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | template<typename Derived> |
| 3443 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3444 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3445 | RValueReferenceTypeLoc TL) { |
| 3446 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3447 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3449 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3451 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3452 | MemberPointerTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3453 | const MemberPointerType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3454 | |
| 3455 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3456 | if (PointeeType.isNull()) |
| 3457 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3459 | // TODO: preserve source information for this. |
| 3460 | QualType ClassType |
| 3461 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3462 | if (ClassType.isNull()) |
| 3463 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3465 | QualType Result = TL.getType(); |
| 3466 | if (getDerived().AlwaysRebuild() || |
| 3467 | PointeeType != T->getPointeeType() || |
| 3468 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3469 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 3470 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3471 | if (Result.isNull()) |
| 3472 | return QualType(); |
| 3473 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3474 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3475 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3476 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3477 | |
| 3478 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3481 | template<typename Derived> |
| 3482 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3483 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3484 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3485 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3486 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3487 | if (ElementType.isNull()) |
| 3488 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3490 | QualType Result = TL.getType(); |
| 3491 | if (getDerived().AlwaysRebuild() || |
| 3492 | ElementType != T->getElementType()) { |
| 3493 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3494 | T->getSizeModifier(), |
| 3495 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3496 | T->getIndexTypeCVRQualifiers(), |
| 3497 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3498 | if (Result.isNull()) |
| 3499 | return QualType(); |
| 3500 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3501 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3502 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3503 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3504 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3506 | Expr *Size = TL.getSizeExpr(); |
| 3507 | if (Size) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3508 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3509 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3510 | } |
| 3511 | NewTL.setSizeExpr(Size); |
| 3512 | |
| 3513 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3514 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3515 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3516 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3517 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3518 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3519 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3520 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3521 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3522 | if (ElementType.isNull()) |
| 3523 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3524 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3525 | QualType Result = TL.getType(); |
| 3526 | if (getDerived().AlwaysRebuild() || |
| 3527 | ElementType != T->getElementType()) { |
| 3528 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3529 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3530 | T->getIndexTypeCVRQualifiers(), |
| 3531 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3532 | if (Result.isNull()) |
| 3533 | return QualType(); |
| 3534 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3535 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3536 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3537 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3538 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3539 | NewTL.setSizeExpr(0); |
| 3540 | |
| 3541 | return Result; |
| 3542 | } |
| 3543 | |
| 3544 | template<typename Derived> |
| 3545 | QualType |
| 3546 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3547 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3548 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3549 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3550 | if (ElementType.isNull()) |
| 3551 | return QualType(); |
| 3552 | |
| 3553 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3554 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3555 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3556 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3557 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3558 | if (SizeResult.isInvalid()) |
| 3559 | return QualType(); |
| 3560 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3561 | Expr *Size = SizeResult.take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3562 | |
| 3563 | QualType Result = TL.getType(); |
| 3564 | if (getDerived().AlwaysRebuild() || |
| 3565 | ElementType != T->getElementType() || |
| 3566 | Size != T->getSizeExpr()) { |
| 3567 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3568 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3569 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3570 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3571 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3572 | if (Result.isNull()) |
| 3573 | return QualType(); |
| 3574 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3575 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3576 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3577 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3578 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3579 | NewTL.setSizeExpr(Size); |
| 3580 | |
| 3581 | return Result; |
| 3582 | } |
| 3583 | |
| 3584 | template<typename Derived> |
| 3585 | QualType |
| 3586 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3587 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3588 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3589 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3590 | if (ElementType.isNull()) |
| 3591 | return QualType(); |
| 3592 | |
| 3593 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3594 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3595 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3596 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3597 | Expr *origSize = TL.getSizeExpr(); |
| 3598 | if (!origSize) origSize = T->getSizeExpr(); |
| 3599 | |
| 3600 | ExprResult sizeResult |
| 3601 | = getDerived().TransformExpr(origSize); |
| 3602 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3603 | return QualType(); |
| 3604 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3605 | Expr *size = sizeResult.get(); |
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() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3610 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3611 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3612 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +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 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3619 | |
| 3620 | // We might have any sort of array type now, but fortunately they |
| 3621 | // all have the same location layout. |
| 3622 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3623 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3624 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3625 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3626 | |
| 3627 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3628 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3629 | |
| 3630 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3631 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3632 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3633 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3634 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3635 | |
| 3636 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3637 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3638 | if (ElementType.isNull()) |
| 3639 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3641 | // Vector sizes are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3642 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3643 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3644 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3645 | if (Size.isInvalid()) |
| 3646 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3648 | QualType Result = TL.getType(); |
| 3649 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3650 | ElementType != T->getElementType() || |
| 3651 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3652 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3653 | Size.take(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3654 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3655 | if (Result.isNull()) |
| 3656 | return QualType(); |
| 3657 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3658 | |
| 3659 | // Result might be dependent or not. |
| 3660 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3661 | DependentSizedExtVectorTypeLoc NewTL |
| 3662 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3663 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3664 | } else { |
| 3665 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3666 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3667 | } |
| 3668 | |
| 3669 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3670 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3671 | |
| 3672 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3673 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3674 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3675 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3676 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3677 | if (ElementType.isNull()) |
| 3678 | return QualType(); |
| 3679 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3680 | QualType Result = TL.getType(); |
| 3681 | if (getDerived().AlwaysRebuild() || |
| 3682 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3683 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3684 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3685 | if (Result.isNull()) |
| 3686 | return QualType(); |
| 3687 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3688 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3689 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3690 | NewTL.setNameLoc(TL.getNameLoc()); |
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 | return Result; |
| 3693 | } |
| 3694 | |
| 3695 | template<typename Derived> |
| 3696 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3697 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3698 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3699 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3700 | if (ElementType.isNull()) |
| 3701 | return QualType(); |
| 3702 | |
| 3703 | QualType Result = TL.getType(); |
| 3704 | if (getDerived().AlwaysRebuild() || |
| 3705 | ElementType != T->getElementType()) { |
| 3706 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3707 | T->getNumElements(), |
| 3708 | /*FIXME*/ SourceLocation()); |
| 3709 | if (Result.isNull()) |
| 3710 | return QualType(); |
| 3711 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3712 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3713 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3714 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3715 | |
| 3716 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3717 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | |
| 3719 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3720 | ParmVarDecl * |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3721 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 3722 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3723 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3724 | TypeSourceInfo *NewDI = 0; |
| 3725 | |
| 3726 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3727 | // If we're substituting into a pack expansion type and we know the |
| 3728 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3729 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3730 | |
| 3731 | TypeLocBuilder TLB; |
| 3732 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3733 | TLB.reserve(NewTL.getFullDataSize()); |
| 3734 | |
| 3735 | QualType Result = getDerived().TransformType(TLB, |
| 3736 | OldExpansionTL.getPatternLoc()); |
| 3737 | if (Result.isNull()) |
| 3738 | return 0; |
| 3739 | |
| 3740 | Result = RebuildPackExpansionType(Result, |
| 3741 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3742 | OldExpansionTL.getEllipsisLoc(), |
| 3743 | NumExpansions); |
| 3744 | if (Result.isNull()) |
| 3745 | return 0; |
| 3746 | |
| 3747 | PackExpansionTypeLoc NewExpansionTL |
| 3748 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3749 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3750 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3751 | } else |
| 3752 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3753 | if (!NewDI) |
| 3754 | return 0; |
| 3755 | |
| 3756 | if (NewDI == OldDI) |
| 3757 | return OldParm; |
| 3758 | else |
| 3759 | return ParmVarDecl::Create(SemaRef.Context, |
| 3760 | OldParm->getDeclContext(), |
| 3761 | OldParm->getLocation(), |
| 3762 | OldParm->getIdentifier(), |
| 3763 | NewDI->getType(), |
| 3764 | NewDI, |
| 3765 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 3766 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3767 | /* DefArg */ NULL); |
| 3768 | } |
| 3769 | |
| 3770 | template<typename Derived> |
| 3771 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3772 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3773 | ParmVarDecl **Params, unsigned NumParams, |
| 3774 | const QualType *ParamTypes, |
| 3775 | llvm::SmallVectorImpl<QualType> &OutParamTypes, |
| 3776 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { |
| 3777 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3778 | if (ParmVarDecl *OldParm = Params[i]) { |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3779 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3780 | if (OldParm->isParameterPack()) { |
| 3781 | // We have a function parameter pack that may need to be expanded. |
| 3782 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3783 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3784 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3785 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3786 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3787 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3788 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3789 | |
| 3790 | // Determine whether we should expand the parameter packs. |
| 3791 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3792 | bool RetainExpansion = false; |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3793 | llvm::Optional<unsigned> OrigNumExpansions |
| 3794 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3795 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3796 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3797 | Pattern.getSourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3798 | Unexpanded.data(), |
| 3799 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3800 | ShouldExpand, |
| 3801 | RetainExpansion, |
| 3802 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3803 | return true; |
| 3804 | } |
| 3805 | |
| 3806 | if (ShouldExpand) { |
| 3807 | // Expand the function parameter pack into multiple, separate |
| 3808 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3809 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3810 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3811 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3812 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3813 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3814 | OrigNumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3815 | if (!NewParm) |
| 3816 | return true; |
| 3817 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3818 | OutParamTypes.push_back(NewParm->getType()); |
| 3819 | if (PVars) |
| 3820 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3821 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3822 | |
| 3823 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3824 | // forgetting the partially-substituted parameter pack. |
| 3825 | if (RetainExpansion) { |
| 3826 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3827 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3828 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3829 | OrigNumExpansions); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3830 | if (!NewParm) |
| 3831 | return true; |
| 3832 | |
| 3833 | OutParamTypes.push_back(NewParm->getType()); |
| 3834 | if (PVars) |
| 3835 | PVars->push_back(NewParm); |
| 3836 | } |
| 3837 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3838 | // We're done with the pack expansion. |
| 3839 | continue; |
| 3840 | } |
| 3841 | |
| 3842 | // We'll substitute the parameter now without expanding the pack |
| 3843 | // expansion. |
| 3844 | } |
| 3845 | |
| 3846 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3847 | ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3848 | NumExpansions); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3849 | if (!NewParm) |
| 3850 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3851 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3852 | OutParamTypes.push_back(NewParm->getType()); |
| 3853 | if (PVars) |
| 3854 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3855 | continue; |
| 3856 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3857 | |
| 3858 | // Deal with the possibility that we don't have a parameter |
| 3859 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3860 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3861 | bool IsPackExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3862 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3863 | if (const PackExpansionType *Expansion |
| 3864 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3865 | // We have a function parameter pack that may need to be expanded. |
| 3866 | QualType Pattern = Expansion->getPattern(); |
| 3867 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3868 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3869 | |
| 3870 | // Determine whether we should expand the parameter packs. |
| 3871 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3872 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3873 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3874 | Unexpanded.data(), |
| 3875 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3876 | ShouldExpand, |
| 3877 | RetainExpansion, |
| 3878 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3879 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | if (ShouldExpand) { |
| 3883 | // Expand the function parameter pack into multiple, separate |
| 3884 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3885 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3886 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3887 | QualType NewType = getDerived().TransformType(Pattern); |
| 3888 | if (NewType.isNull()) |
| 3889 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3890 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3891 | OutParamTypes.push_back(NewType); |
| 3892 | if (PVars) |
| 3893 | PVars->push_back(0); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | // We're done with the pack expansion. |
| 3897 | continue; |
| 3898 | } |
| 3899 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3900 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3901 | // forgetting the partially-substituted parameter pack. |
| 3902 | if (RetainExpansion) { |
| 3903 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3904 | QualType NewType = getDerived().TransformType(Pattern); |
| 3905 | if (NewType.isNull()) |
| 3906 | return true; |
| 3907 | |
| 3908 | OutParamTypes.push_back(NewType); |
| 3909 | if (PVars) |
| 3910 | PVars->push_back(0); |
| 3911 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3912 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3913 | // We'll substitute the parameter now without expanding the pack |
| 3914 | // expansion. |
| 3915 | OldType = Expansion->getPattern(); |
| 3916 | IsPackExpansion = true; |
| 3917 | } |
| 3918 | |
| 3919 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3920 | QualType NewType = getDerived().TransformType(OldType); |
| 3921 | if (NewType.isNull()) |
| 3922 | return true; |
| 3923 | |
| 3924 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3925 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3926 | NumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3927 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3928 | OutParamTypes.push_back(NewType); |
| 3929 | if (PVars) |
| 3930 | PVars->push_back(0); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | return false; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3934 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3935 | |
| 3936 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3938 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3939 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3940 | // Transform the parameters and return type. |
| 3941 | // |
| 3942 | // We instantiate in source order, with the return type first followed by |
| 3943 | // the parameters, because users tend to expect this (even if they shouldn't |
| 3944 | // rely on it!). |
| 3945 | // |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3946 | // When the function has a trailing return type, we instantiate the |
| 3947 | // parameters before the return type, since the return type can then refer |
| 3948 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 3949 | // |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3950 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3951 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3952 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3953 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3954 | QualType ResultType; |
| 3955 | |
| 3956 | if (TL.getTrailingReturn()) { |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3957 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3958 | TL.getParmArray(), |
| 3959 | TL.getNumArgs(), |
| 3960 | TL.getTypePtr()->arg_type_begin(), |
| 3961 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3962 | return QualType(); |
| 3963 | |
| 3964 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3965 | if (ResultType.isNull()) |
| 3966 | return QualType(); |
| 3967 | } |
| 3968 | else { |
| 3969 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3970 | if (ResultType.isNull()) |
| 3971 | return QualType(); |
| 3972 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3973 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3974 | TL.getParmArray(), |
| 3975 | TL.getNumArgs(), |
| 3976 | TL.getTypePtr()->arg_type_begin(), |
| 3977 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3978 | return QualType(); |
| 3979 | } |
| 3980 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3981 | QualType Result = TL.getType(); |
| 3982 | if (getDerived().AlwaysRebuild() || |
| 3983 | ResultType != T->getResultType() || |
Douglas Gregor | 9f627df | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 3984 | T->getNumArgs() != ParamTypes.size() || |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3985 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 3986 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 3987 | ParamTypes.data(), |
| 3988 | ParamTypes.size(), |
| 3989 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3990 | T->getTypeQuals(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3991 | T->getRefQualifier(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3992 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3993 | if (Result.isNull()) |
| 3994 | return QualType(); |
| 3995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3996 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3997 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 3998 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3999 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4000 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4001 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4002 | NewTL.setArg(i, ParamDecls[i]); |
| 4003 | |
| 4004 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4005 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4006 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4007 | template<typename Derived> |
| 4008 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4009 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4010 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4011 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4012 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4013 | if (ResultType.isNull()) |
| 4014 | return QualType(); |
| 4015 | |
| 4016 | QualType Result = TL.getType(); |
| 4017 | if (getDerived().AlwaysRebuild() || |
| 4018 | ResultType != T->getResultType()) |
| 4019 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4020 | |
| 4021 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 4022 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4023 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4024 | NewTL.setTrailingReturn(false); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4025 | |
| 4026 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4029 | template<typename Derived> QualType |
| 4030 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4031 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4032 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4033 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4034 | if (!D) |
| 4035 | return QualType(); |
| 4036 | |
| 4037 | QualType Result = TL.getType(); |
| 4038 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4039 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4040 | if (Result.isNull()) |
| 4041 | return QualType(); |
| 4042 | } |
| 4043 | |
| 4044 | // We might get an arbitrary type spec type back. We should at |
| 4045 | // least always get a type spec type, though. |
| 4046 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4047 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4048 | |
| 4049 | return Result; |
| 4050 | } |
| 4051 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4052 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4053 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4054 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4055 | const TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4056 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4057 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4058 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4059 | if (!Typedef) |
| 4060 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4061 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4062 | QualType Result = TL.getType(); |
| 4063 | if (getDerived().AlwaysRebuild() || |
| 4064 | Typedef != T->getDecl()) { |
| 4065 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4066 | if (Result.isNull()) |
| 4067 | return QualType(); |
| 4068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4070 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4071 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4072 | |
| 4073 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4074 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4076 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4077 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4078 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4079 | // typeof expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4080 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4082 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4083 | if (E.isInvalid()) |
| 4084 | return QualType(); |
| 4085 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4086 | QualType Result = TL.getType(); |
| 4087 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4088 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4089 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4090 | if (Result.isNull()) |
| 4091 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4092 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4093 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4094 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4095 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4096 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4097 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4098 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4099 | |
| 4100 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4101 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4102 | |
| 4103 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4104 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4105 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4106 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4107 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4108 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4109 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4111 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4112 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4113 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4114 | if (Result.isNull()) |
| 4115 | return QualType(); |
| 4116 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4118 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4119 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4120 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4121 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4122 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4123 | |
| 4124 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | |
| 4127 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4128 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4129 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4130 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4132 | // decltype expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4133 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4134 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4135 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4136 | if (E.isInvalid()) |
| 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 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4142 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4143 | if (Result.isNull()) |
| 4144 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4145 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4146 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4148 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4149 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4150 | |
| 4151 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4155 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4156 | AutoTypeLoc TL) { |
| 4157 | const AutoType *T = TL.getTypePtr(); |
| 4158 | QualType OldDeduced = T->getDeducedType(); |
| 4159 | QualType NewDeduced; |
| 4160 | if (!OldDeduced.isNull()) { |
| 4161 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4162 | if (NewDeduced.isNull()) |
| 4163 | return QualType(); |
| 4164 | } |
| 4165 | |
| 4166 | QualType Result = TL.getType(); |
| 4167 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4168 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4169 | if (Result.isNull()) |
| 4170 | return QualType(); |
| 4171 | } |
| 4172 | |
| 4173 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4174 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4175 | |
| 4176 | return Result; |
| 4177 | } |
| 4178 | |
| 4179 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4180 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4181 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4182 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4183 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4184 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4185 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4186 | if (!Record) |
| 4187 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4189 | QualType Result = TL.getType(); |
| 4190 | if (getDerived().AlwaysRebuild() || |
| 4191 | Record != T->getDecl()) { |
| 4192 | Result = getDerived().RebuildRecordType(Record); |
| 4193 | if (Result.isNull()) |
| 4194 | return QualType(); |
| 4195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4197 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4198 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4199 | |
| 4200 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4202 | |
| 4203 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4204 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4205 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4206 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4207 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4208 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4209 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4210 | if (!Enum) |
| 4211 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4213 | QualType Result = TL.getType(); |
| 4214 | if (getDerived().AlwaysRebuild() || |
| 4215 | Enum != T->getDecl()) { |
| 4216 | Result = getDerived().RebuildEnumType(Enum); |
| 4217 | if (Result.isNull()) |
| 4218 | return QualType(); |
| 4219 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4220 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4221 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4222 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4223 | |
| 4224 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4225 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4226 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4227 | template<typename Derived> |
| 4228 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4229 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4230 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4231 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4232 | TL.getTypePtr()->getDecl()); |
| 4233 | if (!D) return QualType(); |
| 4234 | |
| 4235 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4236 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4237 | return T; |
| 4238 | } |
| 4239 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4240 | template<typename Derived> |
| 4241 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4242 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4243 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4244 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4245 | } |
| 4246 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4248 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4249 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4250 | SubstTemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4251 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4255 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4256 | TypeLocBuilder &TLB, |
| 4257 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4258 | return TransformTypeSpecType(TLB, TL); |
| 4259 | } |
| 4260 | |
| 4261 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4262 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4263 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4264 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4265 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4266 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4267 | TemplateName Template |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4268 | = getDerived().TransformTemplateName(T->getTemplateName()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4269 | if (Template.isNull()) |
| 4270 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4272 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4273 | } |
| 4274 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4275 | namespace { |
| 4276 | /// \brief Simple iterator that traverses the template arguments in a |
| 4277 | /// container that provides a \c getArgLoc() member function. |
| 4278 | /// |
| 4279 | /// This iterator is intended to be used with the iterator form of |
| 4280 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4281 | template<typename ArgLocContainer> |
| 4282 | class TemplateArgumentLocContainerIterator { |
| 4283 | ArgLocContainer *Container; |
| 4284 | unsigned Index; |
| 4285 | |
| 4286 | public: |
| 4287 | typedef TemplateArgumentLoc value_type; |
| 4288 | typedef TemplateArgumentLoc reference; |
| 4289 | typedef int difference_type; |
| 4290 | typedef std::input_iterator_tag iterator_category; |
| 4291 | |
| 4292 | class pointer { |
| 4293 | TemplateArgumentLoc Arg; |
| 4294 | |
| 4295 | public: |
| 4296 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4297 | |
| 4298 | const TemplateArgumentLoc *operator->() const { |
| 4299 | return &Arg; |
| 4300 | } |
| 4301 | }; |
| 4302 | |
| 4303 | |
| 4304 | TemplateArgumentLocContainerIterator() {} |
| 4305 | |
| 4306 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4307 | unsigned Index) |
| 4308 | : Container(&Container), Index(Index) { } |
| 4309 | |
| 4310 | TemplateArgumentLocContainerIterator &operator++() { |
| 4311 | ++Index; |
| 4312 | return *this; |
| 4313 | } |
| 4314 | |
| 4315 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4316 | TemplateArgumentLocContainerIterator Old(*this); |
| 4317 | ++(*this); |
| 4318 | return Old; |
| 4319 | } |
| 4320 | |
| 4321 | TemplateArgumentLoc operator*() const { |
| 4322 | return Container->getArgLoc(Index); |
| 4323 | } |
| 4324 | |
| 4325 | pointer operator->() const { |
| 4326 | return pointer(Container->getArgLoc(Index)); |
| 4327 | } |
| 4328 | |
| 4329 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4330 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4331 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4332 | } |
| 4333 | |
| 4334 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4335 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4336 | return !(X == Y); |
| 4337 | } |
| 4338 | }; |
| 4339 | } |
| 4340 | |
| 4341 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4342 | template <typename Derived> |
| 4343 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4344 | TypeLocBuilder &TLB, |
| 4345 | TemplateSpecializationTypeLoc TL, |
| 4346 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4347 | TemplateArgumentListInfo NewTemplateArgs; |
| 4348 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4349 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4350 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4351 | ArgIterator; |
| 4352 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4353 | ArgIterator(TL, TL.getNumArgs()), |
| 4354 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4355 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4356 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4357 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4358 | |
| 4359 | QualType Result = |
| 4360 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4361 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4362 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4363 | |
| 4364 | if (!Result.isNull()) { |
| 4365 | TemplateSpecializationTypeLoc NewTL |
| 4366 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4367 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4368 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4369 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4370 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4371 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4372 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4374 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4375 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4376 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4377 | template <typename Derived> |
| 4378 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4379 | TypeLocBuilder &TLB, |
| 4380 | DependentTemplateSpecializationTypeLoc TL, |
| 4381 | TemplateName Template) { |
| 4382 | TemplateArgumentListInfo NewTemplateArgs; |
| 4383 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4384 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4385 | typedef TemplateArgumentLocContainerIterator< |
| 4386 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4387 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4388 | ArgIterator(TL, TL.getNumArgs()), |
| 4389 | NewTemplateArgs)) |
| 4390 | return QualType(); |
| 4391 | |
| 4392 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4393 | |
| 4394 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4395 | QualType Result |
| 4396 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4397 | TL.getTypePtr()->getKeyword(), |
| 4398 | DTN->getQualifier(), |
| 4399 | DTN->getIdentifier(), |
| 4400 | NewTemplateArgs); |
| 4401 | |
| 4402 | DependentTemplateSpecializationTypeLoc NewTL |
| 4403 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4404 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4405 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 4406 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4407 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4408 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4409 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4410 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4411 | return Result; |
| 4412 | } |
| 4413 | |
| 4414 | QualType Result |
| 4415 | = getDerived().RebuildTemplateSpecializationType(Template, |
| 4416 | TL.getNameLoc(), |
| 4417 | NewTemplateArgs); |
| 4418 | |
| 4419 | if (!Result.isNull()) { |
| 4420 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4421 | TemplateSpecializationTypeLoc NewTL |
| 4422 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4423 | NewTL.setTemplateNameLoc(TL.getNameLoc()); |
| 4424 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4425 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4426 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4427 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4428 | } |
| 4429 | |
| 4430 | return Result; |
| 4431 | } |
| 4432 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4434 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4435 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4436 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4437 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4438 | |
| 4439 | NestedNameSpecifier *NNS = 0; |
| 4440 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 4441 | if (T->getQualifier() != 0) { |
| 4442 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4443 | TL.getQualifierRange()); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4444 | if (!NNS) |
| 4445 | return QualType(); |
| 4446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4448 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4449 | if (NamedT.isNull()) |
| 4450 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4451 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4452 | QualType Result = TL.getType(); |
| 4453 | if (getDerived().AlwaysRebuild() || |
| 4454 | NNS != T->getQualifier() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4455 | NamedT != T->getNamedType()) { |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4456 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
| 4457 | T->getKeyword(), NNS, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4458 | if (Result.isNull()) |
| 4459 | return QualType(); |
| 4460 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4461 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4462 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4463 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4464 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4465 | |
| 4466 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4467 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4468 | |
| 4469 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4470 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4471 | TypeLocBuilder &TLB, |
| 4472 | AttributedTypeLoc TL) { |
| 4473 | const AttributedType *oldType = TL.getTypePtr(); |
| 4474 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4475 | if (modifiedType.isNull()) |
| 4476 | return QualType(); |
| 4477 | |
| 4478 | QualType result = TL.getType(); |
| 4479 | |
| 4480 | // FIXME: dependent operand expressions? |
| 4481 | if (getDerived().AlwaysRebuild() || |
| 4482 | modifiedType != oldType->getModifiedType()) { |
| 4483 | // TODO: this is really lame; we should really be rebuilding the |
| 4484 | // equivalent type from first principles. |
| 4485 | QualType equivalentType |
| 4486 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4487 | if (equivalentType.isNull()) |
| 4488 | return QualType(); |
| 4489 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4490 | modifiedType, |
| 4491 | equivalentType); |
| 4492 | } |
| 4493 | |
| 4494 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4495 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4496 | if (TL.hasAttrOperand()) |
| 4497 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4498 | if (TL.hasAttrExprOperand()) |
| 4499 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4500 | else if (TL.hasAttrEnumOperand()) |
| 4501 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4502 | |
| 4503 | return result; |
| 4504 | } |
| 4505 | |
| 4506 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4507 | QualType |
| 4508 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4509 | ParenTypeLoc TL) { |
| 4510 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4511 | if (Inner.isNull()) |
| 4512 | return QualType(); |
| 4513 | |
| 4514 | QualType Result = TL.getType(); |
| 4515 | if (getDerived().AlwaysRebuild() || |
| 4516 | Inner != TL.getInnerLoc().getType()) { |
| 4517 | Result = getDerived().RebuildParenType(Inner); |
| 4518 | if (Result.isNull()) |
| 4519 | return QualType(); |
| 4520 | } |
| 4521 | |
| 4522 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4523 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4524 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4525 | return Result; |
| 4526 | } |
| 4527 | |
| 4528 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4529 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4530 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4531 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 4533 | NestedNameSpecifierLoc QualifierLoc |
| 4534 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4535 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4536 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4537 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4538 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 4539 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4540 | TL.getKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 4541 | QualifierLoc, |
| 4542 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4543 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4544 | if (Result.isNull()) |
| 4545 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4546 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4547 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4548 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4549 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4550 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4551 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4552 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 4553 | NewTL.setQualifierRange(QualifierLoc.getSourceRange()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4554 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4555 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4556 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame^] | 4557 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4558 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4559 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4560 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4563 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4564 | QualType TreeTransform<Derived>:: |
| 4565 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4566 | DependentTemplateSpecializationTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4567 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4568 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4569 | NestedNameSpecifier *NNS = 0; |
| 4570 | if (T->getQualifier()) { |
| 4571 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 4572 | TL.getQualifierRange()); |
| 4573 | if (!NNS) |
| 4574 | return QualType(); |
| 4575 | } |
| 4576 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4577 | return getDerived() |
| 4578 | .TransformDependentTemplateSpecializationType(TLB, TL, NNS); |
| 4579 | } |
| 4580 | |
| 4581 | template<typename Derived> |
| 4582 | QualType TreeTransform<Derived>:: |
| 4583 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4584 | DependentTemplateSpecializationTypeLoc TL, |
| 4585 | NestedNameSpecifier *NNS) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4586 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4587 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4588 | TemplateArgumentListInfo NewTemplateArgs; |
| 4589 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4590 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4591 | |
| 4592 | // FIXME: Nested-name-specifier source location info! |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4593 | typedef TemplateArgumentLocContainerIterator< |
| 4594 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4595 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4596 | ArgIterator(TL, TL.getNumArgs()), |
| 4597 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4598 | return QualType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4599 | |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4600 | QualType Result |
| 4601 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4602 | NNS, |
| 4603 | TL.getQualifierRange(), |
| 4604 | T->getIdentifier(), |
| 4605 | TL.getNameLoc(), |
| 4606 | NewTemplateArgs); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4607 | if (Result.isNull()) |
| 4608 | return QualType(); |
| 4609 | |
| 4610 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4611 | QualType NamedT = ElabT->getNamedType(); |
| 4612 | |
| 4613 | // Copy information relevant to the template specialization. |
| 4614 | TemplateSpecializationTypeLoc NamedTL |
| 4615 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4616 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4617 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4618 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4619 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4620 | |
| 4621 | // Copy information relevant to the elaborated type. |
| 4622 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4623 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4624 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 4625 | } else { |
Douglas Gregor | ffa2039 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 4626 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4627 | TLB.pushFullCopy(NewTL); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4628 | } |
| 4629 | return Result; |
| 4630 | } |
| 4631 | |
| 4632 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4633 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4634 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4635 | QualType Pattern |
| 4636 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4637 | if (Pattern.isNull()) |
| 4638 | return QualType(); |
| 4639 | |
| 4640 | QualType Result = TL.getType(); |
| 4641 | if (getDerived().AlwaysRebuild() || |
| 4642 | Pattern != TL.getPatternLoc().getType()) { |
| 4643 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4644 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4645 | TL.getEllipsisLoc(), |
| 4646 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4647 | if (Result.isNull()) |
| 4648 | return QualType(); |
| 4649 | } |
| 4650 | |
| 4651 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4652 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4653 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4657 | QualType |
| 4658 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4659 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4660 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4661 | TLB.pushFullCopy(TL); |
| 4662 | return TL.getType(); |
| 4663 | } |
| 4664 | |
| 4665 | template<typename Derived> |
| 4666 | QualType |
| 4667 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4668 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4669 | // ObjCObjectType is never dependent. |
| 4670 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4671 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | |
| 4674 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4675 | QualType |
| 4676 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4677 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4678 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4679 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4680 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4681 | } |
| 4682 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4683 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4684 | // Statement transformation |
| 4685 | //===----------------------------------------------------------------------===// |
| 4686 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4687 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4689 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4693 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4694 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4695 | return getDerived().TransformCompoundStmt(S, false); |
| 4696 | } |
| 4697 | |
| 4698 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4699 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4701 | bool IsStmtExpr) { |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4702 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4703 | bool SubStmtChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4704 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4705 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4706 | B != BEnd; ++B) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4707 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4708 | if (Result.isInvalid()) { |
| 4709 | // Immediately fail if this was a DeclStmt, since it's very |
| 4710 | // likely that this will cause problems for future statements. |
| 4711 | if (isa<DeclStmt>(*B)) |
| 4712 | return StmtError(); |
| 4713 | |
| 4714 | // Otherwise, just keep processing substatements and fail later. |
| 4715 | SubStmtInvalid = true; |
| 4716 | continue; |
| 4717 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4719 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4720 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4721 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4722 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4723 | if (SubStmtInvalid) |
| 4724 | return StmtError(); |
| 4725 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4726 | if (!getDerived().AlwaysRebuild() && |
| 4727 | !SubStmtChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4728 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4729 | |
| 4730 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4731 | move_arg(Statements), |
| 4732 | S->getRBracLoc(), |
| 4733 | IsStmtExpr); |
| 4734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4736 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4737 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4739 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4740 | { |
| 4741 | // The case value expressions are not potentially evaluated. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4742 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4743 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4744 | // Transform the left-hand case value. |
| 4745 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4746 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4747 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4748 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4749 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4750 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4751 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4752 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4755 | // Build the case statement. |
| 4756 | // Case statements are always rebuilt so that they will attached to their |
| 4757 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4758 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4759 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4760 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4761 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4762 | S->getColonLoc()); |
| 4763 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4764 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4766 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4767 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4768 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4769 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4771 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4772 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4776 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4778 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4779 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4780 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4781 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4783 | // Default statements are always rebuilt |
| 4784 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4785 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4786 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4788 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4789 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4791 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4792 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4793 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4795 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 4796 | S->getDecl()); |
| 4797 | if (!LD) |
| 4798 | return StmtError(); |
| 4799 | |
| 4800 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4801 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 4802 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4803 | cast<LabelDecl>(LD), SourceLocation(), |
| 4804 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4807 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4808 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4809 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4810 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4811 | ExprResult Cond; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4812 | VarDecl *ConditionVar = 0; |
| 4813 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4814 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4815 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4816 | getDerived().TransformDefinition( |
| 4817 | S->getConditionVariable()->getLocation(), |
| 4818 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4819 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4820 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4821 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4822 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4823 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4824 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4825 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4826 | |
| 4827 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4828 | if (S->getCond()) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4829 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 4830 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4831 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4832 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4833 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4834 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4835 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4836 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4837 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4838 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4839 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4840 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4841 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4842 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4843 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4844 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4845 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4846 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4847 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4848 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4849 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4850 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4851 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4852 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4853 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4854 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4855 | Then.get() == S->getThen() && |
| 4856 | Else.get() == S->getElse()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4857 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4859 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 4860 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4861 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4865 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4866 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4867 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4868 | ExprResult Cond; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4869 | VarDecl *ConditionVar = 0; |
| 4870 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4871 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4872 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4873 | getDerived().TransformDefinition( |
| 4874 | S->getConditionVariable()->getLocation(), |
| 4875 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4876 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4877 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4878 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4879 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4880 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4881 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4882 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4884 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4885 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4886 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4887 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 4888 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4889 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4890 | return StmtError(); |
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 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4893 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4894 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4895 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4896 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4897 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4898 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 4899 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4902 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4903 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4905 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4906 | ExprResult Cond; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4907 | VarDecl *ConditionVar = 0; |
| 4908 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4909 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4910 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4911 | getDerived().TransformDefinition( |
| 4912 | S->getConditionVariable()->getLocation(), |
| 4913 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4914 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4915 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4916 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4917 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4918 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4919 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4920 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4921 | |
| 4922 | if (S->getCond()) { |
| 4923 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4924 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 4925 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4926 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4927 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4928 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4929 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4930 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4931 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4932 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4933 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4934 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4935 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4936 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4937 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4938 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4939 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4941 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4942 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4943 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4944 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4945 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4947 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4948 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4951 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4952 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4953 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4954 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4955 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4956 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4957 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4959 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4960 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4961 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4962 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4963 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4964 | if (!getDerived().AlwaysRebuild() && |
| 4965 | Cond.get() == S->getCond() && |
| 4966 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4967 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4969 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 4970 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4971 | S->getRParenLoc()); |
| 4972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4973 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4974 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4975 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4976 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4977 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4978 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4979 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4980 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4981 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4982 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4983 | ExprResult Cond; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4984 | VarDecl *ConditionVar = 0; |
| 4985 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4986 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4987 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4988 | getDerived().TransformDefinition( |
| 4989 | S->getConditionVariable()->getLocation(), |
| 4990 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4991 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4992 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4993 | } else { |
| 4994 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4995 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4996 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4997 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4998 | |
| 4999 | if (S->getCond()) { |
| 5000 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5001 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 5002 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5003 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5004 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5005 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5006 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5007 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5009 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5010 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5011 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5012 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5013 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5014 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5015 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5016 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5017 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5018 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5019 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5020 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5021 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5022 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5023 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5024 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5025 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5026 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5027 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5028 | if (!getDerived().AlwaysRebuild() && |
| 5029 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5030 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5031 | Inc.get() == S->getInc() && |
| 5032 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5033 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5034 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5035 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5036 | Init.get(), FullCond, ConditionVar, |
| 5037 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5041 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5042 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5043 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5044 | S->getLabel()); |
| 5045 | if (!LD) |
| 5046 | return StmtError(); |
| 5047 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5048 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5050 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5054 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5056 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5057 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5058 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5060 | if (!getDerived().AlwaysRebuild() && |
| 5061 | Target.get() == S->getTarget()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5062 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5063 | |
| 5064 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5065 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5069 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5070 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5071 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5074 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5075 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5076 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5077 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5078 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5080 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5081 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5082 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5083 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5084 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5085 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5086 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5088 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5089 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5090 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5092 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5093 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5095 | bool DeclChanged = false; |
| 5096 | llvm::SmallVector<Decl *, 4> Decls; |
| 5097 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5098 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5099 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5100 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5101 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5102 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5103 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5104 | if (Transformed != *D) |
| 5105 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5106 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5107 | Decls.push_back(Transformed); |
| 5108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5110 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5111 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5112 | |
| 5113 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5114 | S->getStartLoc(), S->getEndLoc()); |
| 5115 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5117 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5118 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5119 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5120 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5121 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5122 | ASTOwningVector<Expr*> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5123 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5124 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5125 | ExprResult AsmString; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5126 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5127 | |
| 5128 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5129 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5130 | // Go through the outputs. |
| 5131 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5132 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5133 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5134 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5135 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5136 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5137 | // Transform the output expr. |
| 5138 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5139 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5140 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5141 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5142 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5143 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5144 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5145 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5146 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5147 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5148 | // Go through the inputs. |
| 5149 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5150 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5151 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5152 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5153 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5154 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5155 | // Transform the input expr. |
| 5156 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5157 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5158 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5159 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5160 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5161 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5162 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5163 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5164 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5165 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5166 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5167 | return SemaRef.Owned(S); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5168 | |
| 5169 | // Go through the clobbers. |
| 5170 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5171 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5172 | |
| 5173 | // No need to transform the asm string literal. |
| 5174 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5175 | |
| 5176 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5177 | S->isSimple(), |
| 5178 | S->isVolatile(), |
| 5179 | S->getNumOutputs(), |
| 5180 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5181 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5182 | move_arg(Constraints), |
| 5183 | move_arg(Exprs), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5184 | AsmString.get(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5185 | move_arg(Clobbers), |
| 5186 | S->getRParenLoc(), |
| 5187 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | |
| 5191 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5192 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5194 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5195 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5196 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5197 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5198 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5199 | // Transform the @catch statements (if present). |
| 5200 | bool AnyCatchChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5201 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5202 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5203 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5204 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5205 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5206 | if (Catch.get() != S->getCatchStmt(I)) |
| 5207 | AnyCatchChanged = true; |
| 5208 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5209 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5210 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5211 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5212 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5213 | if (S->getFinallyStmt()) { |
| 5214 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5215 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5216 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | // If nothing changed, just retain this statement. |
| 5220 | if (!getDerived().AlwaysRebuild() && |
| 5221 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5222 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5223 | Finally.get() == S->getFinallyStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5224 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5225 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5226 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5227 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5228 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5231 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5232 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5233 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5234 | // Transform the @catch parameter, if there is one. |
| 5235 | VarDecl *Var = 0; |
| 5236 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5237 | TypeSourceInfo *TSInfo = 0; |
| 5238 | if (FromVar->getTypeSourceInfo()) { |
| 5239 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5240 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5241 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5242 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5243 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5244 | QualType T; |
| 5245 | if (TSInfo) |
| 5246 | T = TSInfo->getType(); |
| 5247 | else { |
| 5248 | T = getDerived().TransformType(FromVar->getType()); |
| 5249 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5250 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5251 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5252 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5253 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5254 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5255 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5256 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5257 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5258 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5259 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5260 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5261 | |
| 5262 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5263 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5264 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5265 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5267 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5268 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5269 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5270 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5271 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5272 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5273 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5274 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5275 | // If nothing changed, just retain this statement. |
| 5276 | if (!getDerived().AlwaysRebuild() && |
| 5277 | Body.get() == S->getFinallyBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5278 | return SemaRef.Owned(S); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5279 | |
| 5280 | // Build a new statement. |
| 5281 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5282 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5285 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5286 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5288 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5289 | if (S->getThrowExpr()) { |
| 5290 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5291 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5292 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5293 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5294 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5295 | if (!getDerived().AlwaysRebuild() && |
| 5296 | Operand.get() == S->getThrowExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5297 | return getSema().Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5298 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5299 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5301 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5302 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5303 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5304 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5306 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5307 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5308 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5309 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5310 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5311 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5312 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5313 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5314 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5315 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5316 | // If nothing change, just retain the current statement. |
| 5317 | if (!getDerived().AlwaysRebuild() && |
| 5318 | Object.get() == S->getSynchExpr() && |
| 5319 | Body.get() == S->getSynchBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5320 | return SemaRef.Owned(S); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5321 | |
| 5322 | // Build a new statement. |
| 5323 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5324 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5328 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5329 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5330 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5331 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5332 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5333 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5334 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5335 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5336 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5337 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5338 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5339 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5340 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5341 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5342 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5343 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5344 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5345 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5346 | // If nothing changed, just retain this statement. |
| 5347 | if (!getDerived().AlwaysRebuild() && |
| 5348 | Element.get() == S->getElement() && |
| 5349 | Collection.get() == S->getCollection() && |
| 5350 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5351 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5352 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5353 | // Build a new statement. |
| 5354 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5355 | /*FIXME:*/S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5356 | Element.get(), |
| 5357 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5358 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5359 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | |
| 5363 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5364 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5365 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5366 | // Transform the exception declaration, if any. |
| 5367 | VarDecl *Var = 0; |
| 5368 | if (S->getExceptionDecl()) { |
| 5369 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5370 | TypeSourceInfo *T = getDerived().TransformType( |
| 5371 | ExceptionDecl->getTypeSourceInfo()); |
| 5372 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5373 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5375 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5376 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5377 | ExceptionDecl->getLocation()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5378 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5379 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5382 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5383 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5384 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5385 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5386 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5387 | if (!getDerived().AlwaysRebuild() && |
| 5388 | !Var && |
| 5389 | Handler.get() == S->getHandlerBlock()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5390 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5391 | |
| 5392 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5393 | Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5394 | Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5396 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5397 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5398 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5399 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5400 | // Transform the try block itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5401 | StmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5402 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5403 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5404 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5406 | // Transform the handlers. |
| 5407 | bool HandlerChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5408 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5409 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5410 | StmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5411 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5412 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5413 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5415 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5416 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5417 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5419 | if (!getDerived().AlwaysRebuild() && |
| 5420 | TryBlock.get() == S->getTryBlock() && |
| 5421 | !HandlerChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5422 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5423 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5424 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5425 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5427 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5428 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5429 | // Expression transformation |
| 5430 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5431 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5432 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5433 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5434 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5435 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | |
| 5437 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5438 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5439 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5440 | NestedNameSpecifierLoc QualifierLoc; |
| 5441 | if (E->getQualifierLoc()) { |
| 5442 | QualifierLoc |
| 5443 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5444 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5445 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5446 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5447 | |
| 5448 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5449 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5450 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5451 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5452 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5453 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5454 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5455 | if (NameInfo.getName()) { |
| 5456 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5457 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5458 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5459 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5460 | |
| 5461 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5462 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5463 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5464 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5465 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5466 | |
| 5467 | // Mark it referenced in the new context regardless. |
| 5468 | // FIXME: this is a bit instantiation-specific. |
| 5469 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5470 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5471 | return SemaRef.Owned(E); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5472 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5473 | |
| 5474 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5475 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5476 | TemplateArgs = &TransArgs; |
| 5477 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5478 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5479 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5480 | E->getNumTemplateArgs(), |
| 5481 | TransArgs)) |
| 5482 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5483 | } |
| 5484 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5485 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 5486 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5489 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5490 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5491 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5492 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5493 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5494 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5495 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5496 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5498 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5500 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5501 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5502 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5503 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5504 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5507 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5508 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5509 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5510 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5512 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5513 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5514 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5515 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5516 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5520 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5521 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5522 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5523 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5524 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5526 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5527 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5528 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5529 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5530 | E->getRParen()); |
| 5531 | } |
| 5532 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5533 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5534 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5535 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5536 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5537 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5538 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5539 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5540 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5541 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5543 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5544 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5545 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5548 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5549 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5550 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5551 | // Transform the type. |
| 5552 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5553 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5554 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5555 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5556 | // Transform all of the components into components similar to what the |
| 5557 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5558 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5559 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5560 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5561 | // template code that we don't care. |
| 5562 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5563 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5564 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 5565 | llvm::SmallVector<Component, 4> Components; |
| 5566 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5567 | const Node &ON = E->getComponent(I); |
| 5568 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5569 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5570 | Comp.LocStart = ON.getRange().getBegin(); |
| 5571 | Comp.LocEnd = ON.getRange().getEnd(); |
| 5572 | switch (ON.getKind()) { |
| 5573 | case Node::Array: { |
| 5574 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5575 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5576 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5577 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5578 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5579 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5580 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5581 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5582 | break; |
| 5583 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5584 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5585 | case Node::Field: |
| 5586 | case Node::Identifier: |
| 5587 | Comp.isBrackets = false; |
| 5588 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5589 | if (!Comp.U.IdentInfo) |
| 5590 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5591 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5592 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5593 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5594 | case Node::Base: |
| 5595 | // Will be recomputed during the rebuild. |
| 5596 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5597 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5598 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5599 | Components.push_back(Comp); |
| 5600 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5601 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5602 | // If nothing changed, retain the existing expression. |
| 5603 | if (!getDerived().AlwaysRebuild() && |
| 5604 | Type == E->getTypeSourceInfo() && |
| 5605 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5606 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5608 | // Build a new offsetof expression. |
| 5609 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5610 | Components.data(), Components.size(), |
| 5611 | E->getRParenLoc()); |
| 5612 | } |
| 5613 | |
| 5614 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5615 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5616 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5617 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5618 | "opaque value expression requires transformation"); |
| 5619 | return SemaRef.Owned(E); |
| 5620 | } |
| 5621 | |
| 5622 | template<typename Derived> |
| 5623 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5624 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5625 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5626 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5627 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5628 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5629 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5630 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5632 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5633 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5635 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5636 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5637 | E->getSourceRange()); |
| 5638 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5639 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5640 | ExprResult SubExpr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5641 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5642 | // C++0x [expr.sizeof]p1: |
| 5643 | // The operand is either an expression, which is an unevaluated operand |
| 5644 | // [...] |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5645 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5646 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5647 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5648 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5649 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5651 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5652 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5654 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5655 | return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | E->isSizeOf(), |
| 5657 | E->getSourceRange()); |
| 5658 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5660 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5661 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5662 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5663 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5664 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5665 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5667 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5668 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5669 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | |
| 5671 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5672 | if (!getDerived().AlwaysRebuild() && |
| 5673 | LHS.get() == E->getLHS() && |
| 5674 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5675 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5677 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5678 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5679 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5680 | E->getRBracketLoc()); |
| 5681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5682 | |
| 5683 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5684 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5685 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5687 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5688 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5689 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | |
| 5691 | // Transform arguments. |
| 5692 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5693 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5694 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5695 | &ArgChanged)) |
| 5696 | return ExprError(); |
| 5697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5698 | if (!getDerived().AlwaysRebuild() && |
| 5699 | Callee.get() == E->getCallee() && |
| 5700 | !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5701 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5703 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5705 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5706 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5707 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5708 | E->getRParenLoc()); |
| 5709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5710 | |
| 5711 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5712 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5713 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5714 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5715 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5716 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5717 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5718 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5719 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5720 | QualifierLoc |
| 5721 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5722 | |
| 5723 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5724 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5725 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5726 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 5727 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5728 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 5729 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5731 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5733 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 5734 | if (FoundDecl == E->getMemberDecl()) { |
| 5735 | FoundDecl = Member; |
| 5736 | } else { |
| 5737 | FoundDecl = cast_or_null<NamedDecl>( |
| 5738 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 5739 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5740 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5741 | } |
| 5742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5743 | if (!getDerived().AlwaysRebuild() && |
| 5744 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5745 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5746 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5747 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5748 | !E->hasExplicitTemplateArgs()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5749 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5750 | // Mark it referenced in the new context regardless. |
| 5751 | // FIXME: this is a bit instantiation-specific. |
| 5752 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5753 | return SemaRef.Owned(E); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5754 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5755 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5756 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5757 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5758 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5759 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5760 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5761 | E->getNumTemplateArgs(), |
| 5762 | TransArgs)) |
| 5763 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5764 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5765 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5766 | // FIXME: Bogus source location for the operator |
| 5767 | SourceLocation FakeOperatorLoc |
| 5768 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 5769 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5770 | // FIXME: to do this check properly, we will need to preserve the |
| 5771 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5772 | // base (and therefore couldn't do the check) and a |
| 5773 | // nested-name-qualifier (and therefore could do the lookup). |
| 5774 | NamedDecl *FirstQualifierInScope = 0; |
| 5775 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5776 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5777 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5778 | QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5779 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5780 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5781 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5782 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5783 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5784 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5785 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5786 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5787 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5788 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5789 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5790 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5791 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5792 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5793 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5794 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5795 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5796 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5797 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5798 | if (!getDerived().AlwaysRebuild() && |
| 5799 | LHS.get() == E->getLHS() && |
| 5800 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5801 | return SemaRef.Owned(E); |
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 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5804 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5805 | } |
| 5806 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5807 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5808 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5809 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5810 | CompoundAssignOperator *E) { |
| 5811 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5814 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 5815 | ExprResult TreeTransform<Derived>:: |
| 5816 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 5817 | // Just rebuild the common and RHS expressions and see whether we |
| 5818 | // get any changes. |
| 5819 | |
| 5820 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 5821 | if (commonExpr.isInvalid()) |
| 5822 | return ExprError(); |
| 5823 | |
| 5824 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 5825 | if (rhs.isInvalid()) |
| 5826 | return ExprError(); |
| 5827 | |
| 5828 | if (!getDerived().AlwaysRebuild() && |
| 5829 | commonExpr.get() == e->getCommon() && |
| 5830 | rhs.get() == e->getFalseExpr()) |
| 5831 | return SemaRef.Owned(e); |
| 5832 | |
| 5833 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 5834 | e->getQuestionLoc(), |
| 5835 | 0, |
| 5836 | e->getColonLoc(), |
| 5837 | rhs.get()); |
| 5838 | } |
| 5839 | |
| 5840 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5841 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5842 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5843 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5844 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5845 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5846 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5847 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5848 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5849 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5850 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5851 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5852 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5853 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5854 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5855 | if (!getDerived().AlwaysRebuild() && |
| 5856 | Cond.get() == E->getCond() && |
| 5857 | LHS.get() == E->getLHS() && |
| 5858 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5859 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5860 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5861 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5862 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5863 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5864 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5865 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5867 | |
| 5868 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5869 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5870 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5871 | // Implicit casts are eliminated during transformation, since they |
| 5872 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5873 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5874 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5875 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5876 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5877 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5878 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5879 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5880 | if (!Type) |
| 5881 | return ExprError(); |
| 5882 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5883 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5884 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5885 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5886 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5888 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5889 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5890 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5891 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5892 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5893 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5894 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5895 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5896 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5897 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5898 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5899 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5900 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5901 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5902 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 5903 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 5904 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5905 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5906 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5907 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5908 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5909 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5910 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5911 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5912 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5913 | Init.get() == E->getInitializer()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5914 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5915 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 5916 | // Note: the expression type doesn't necessarily match the |
| 5917 | // type-as-written, but that's okay, because it should always be |
| 5918 | // derivable from the initializer. |
| 5919 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5920 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5921 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5922 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5923 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5924 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5925 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5926 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5927 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5928 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5929 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5930 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5931 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5932 | if (!getDerived().AlwaysRebuild() && |
| 5933 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5934 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5935 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5936 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5937 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5938 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5939 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5940 | E->getAccessorLoc(), |
| 5941 | E->getAccessor()); |
| 5942 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5943 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5944 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5945 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5946 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5947 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5948 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5949 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5950 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 5951 | Inits, &InitChanged)) |
| 5952 | return ExprError(); |
| 5953 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5954 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5955 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5956 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5957 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 5958 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5959 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5960 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5961 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5962 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5963 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5964 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5965 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5966 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5967 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5968 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5969 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5970 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5971 | // transform the designators. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5972 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5973 | bool ExprChanged = false; |
| 5974 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 5975 | DEnd = E->designators_end(); |
| 5976 | D != DEnd; ++D) { |
| 5977 | if (D->isFieldDesignator()) { |
| 5978 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 5979 | D->getDotLoc(), |
| 5980 | D->getFieldLoc())); |
| 5981 | continue; |
| 5982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5983 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5984 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5985 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5986 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5987 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5988 | |
| 5989 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5990 | D->getLBracketLoc())); |
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 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 5993 | ArrayExprs.push_back(Index.release()); |
| 5994 | continue; |
| 5995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5996 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5997 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5998 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5999 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6000 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6001 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6002 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6003 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6004 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6005 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6006 | |
| 6007 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6008 | End.get(), |
| 6009 | D->getLBracketLoc(), |
| 6010 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6012 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6013 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6014 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6015 | ArrayExprs.push_back(Start.release()); |
| 6016 | ArrayExprs.push_back(End.release()); |
| 6017 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6019 | if (!getDerived().AlwaysRebuild() && |
| 6020 | Init.get() == E->getInit() && |
| 6021 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6022 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6024 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6025 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6026 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6028 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6029 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6030 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6032 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6033 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6034 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6035 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6036 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6037 | QualType T = getDerived().TransformType(E->getType()); |
| 6038 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6039 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6040 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6041 | if (!getDerived().AlwaysRebuild() && |
| 6042 | T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6043 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6044 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6045 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6046 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6048 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6049 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6050 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6051 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6052 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6053 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6054 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6055 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6056 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6057 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6058 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6059 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6060 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6061 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6062 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6063 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6064 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6065 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6066 | } |
| 6067 | |
| 6068 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6069 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6070 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6071 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6072 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6073 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6074 | &ArgumentChanged)) |
| 6075 | return ExprError(); |
| 6076 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6077 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6078 | move_arg(Inits), |
| 6079 | E->getRParenLoc()); |
| 6080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6082 | /// \brief Transform an address-of-label expression. |
| 6083 | /// |
| 6084 | /// By default, the transformation of an address-of-label expression always |
| 6085 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6086 | /// the corresponding label statement by semantic analysis. |
| 6087 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6088 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6089 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6090 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6091 | E->getLabel()); |
| 6092 | if (!LD) |
| 6093 | return ExprError(); |
| 6094 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6095 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6096 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6098 | |
| 6099 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6100 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6101 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6102 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6103 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 6104 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6105 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6106 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6107 | if (!getDerived().AlwaysRebuild() && |
| 6108 | SubStmt.get() == E->getSubStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6109 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6110 | |
| 6111 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6112 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6113 | E->getRParenLoc()); |
| 6114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6115 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6116 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6117 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6118 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6119 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6121 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6122 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6123 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6124 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6125 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6126 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6127 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6128 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6129 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6131 | if (!getDerived().AlwaysRebuild() && |
| 6132 | Cond.get() == E->getCond() && |
| 6133 | LHS.get() == E->getLHS() && |
| 6134 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6135 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6137 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6138 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6139 | E->getRParenLoc()); |
| 6140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6141 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6142 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6143 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6144 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6145 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6146 | } |
| 6147 | |
| 6148 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6149 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6150 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6151 | switch (E->getOperator()) { |
| 6152 | case OO_New: |
| 6153 | case OO_Delete: |
| 6154 | case OO_Array_New: |
| 6155 | case OO_Array_Delete: |
| 6156 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6157 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6158 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6159 | case OO_Call: { |
| 6160 | // This is a call to an object's operator(). |
| 6161 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6162 | |
| 6163 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6164 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6165 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6166 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6167 | |
| 6168 | // FIXME: Poor location information |
| 6169 | SourceLocation FakeLParenLoc |
| 6170 | = SemaRef.PP.getLocForEndOfToken( |
| 6171 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6172 | |
| 6173 | // Transform the call arguments. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6174 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6175 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6176 | Args)) |
| 6177 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6178 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6179 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6180 | move_arg(Args), |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6181 | E->getLocEnd()); |
| 6182 | } |
| 6183 | |
| 6184 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6185 | case OO_##Name: |
| 6186 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6187 | #include "clang/Basic/OperatorKinds.def" |
| 6188 | case OO_Subscript: |
| 6189 | // Handled below. |
| 6190 | break; |
| 6191 | |
| 6192 | case OO_Conditional: |
| 6193 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6194 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6195 | |
| 6196 | case OO_None: |
| 6197 | case NUM_OVERLOADED_OPERATORS: |
| 6198 | llvm_unreachable("not an overloaded operator?"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6199 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6200 | } |
| 6201 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6202 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6203 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6204 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6205 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6206 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6207 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6208 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6209 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6210 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6211 | if (E->getNumArgs() == 2) { |
| 6212 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6213 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6214 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6215 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6216 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6217 | if (!getDerived().AlwaysRebuild() && |
| 6218 | Callee.get() == E->getCallee() && |
| 6219 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6220 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6221 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6222 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6223 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6224 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6225 | Callee.get(), |
| 6226 | First.get(), |
| 6227 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6229 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6230 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6231 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6232 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6233 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6234 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6235 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6236 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6237 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6238 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6239 | // Transform the callee. |
| 6240 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6241 | if (Callee.isInvalid()) |
| 6242 | return ExprError(); |
| 6243 | |
| 6244 | // Transform exec config. |
| 6245 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6246 | if (EC.isInvalid()) |
| 6247 | return ExprError(); |
| 6248 | |
| 6249 | // Transform arguments. |
| 6250 | bool ArgChanged = false; |
| 6251 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6252 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6253 | &ArgChanged)) |
| 6254 | return ExprError(); |
| 6255 | |
| 6256 | if (!getDerived().AlwaysRebuild() && |
| 6257 | Callee.get() == E->getCallee() && |
| 6258 | !ArgChanged) |
| 6259 | return SemaRef.Owned(E); |
| 6260 | |
| 6261 | // FIXME: Wrong source location information for the '('. |
| 6262 | SourceLocation FakeLParenLoc |
| 6263 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6264 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6265 | move_arg(Args), |
| 6266 | E->getRParenLoc(), EC.get()); |
| 6267 | } |
| 6268 | |
| 6269 | template<typename Derived> |
| 6270 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6271 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6272 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6273 | if (!Type) |
| 6274 | return ExprError(); |
| 6275 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6276 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6277 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6278 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6279 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6281 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6282 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6283 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6284 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6286 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6287 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6288 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6289 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6290 | SourceLocation FakeRParenLoc |
| 6291 | = SemaRef.PP.getLocForEndOfToken( |
| 6292 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6293 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6295 | FakeLAngleLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6296 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6297 | FakeRAngleLoc, |
| 6298 | FakeRAngleLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6299 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6300 | FakeRParenLoc); |
| 6301 | } |
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 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6304 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6305 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6306 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6308 | |
| 6309 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6310 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6311 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6312 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6313 | } |
| 6314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6315 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6316 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6317 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6318 | CXXReinterpretCastExpr *E) { |
| 6319 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6320 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6321 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6322 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6323 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6324 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6325 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6328 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6329 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6330 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6331 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6332 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6333 | if (!Type) |
| 6334 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6335 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6336 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6337 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6338 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6339 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6340 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6341 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6342 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6343 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6344 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6345 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6346 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6347 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6348 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6349 | E->getRParenLoc()); |
| 6350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6351 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6352 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6353 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6354 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6355 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6356 | TypeSourceInfo *TInfo |
| 6357 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6358 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6359 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6362 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6363 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6364 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6365 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6366 | E->getLocStart(), |
| 6367 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6368 | E->getLocEnd()); |
| 6369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6370 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6371 | // We don't know whether the expression is potentially evaluated until |
| 6372 | // after we perform semantic analysis, so the expression is potentially |
| 6373 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6374 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6375 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6376 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6377 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6378 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6379 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6380 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6381 | if (!getDerived().AlwaysRebuild() && |
| 6382 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6383 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6384 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6385 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6386 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6387 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6388 | E->getLocEnd()); |
| 6389 | } |
| 6390 | |
| 6391 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6392 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6393 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6394 | if (E->isTypeOperand()) { |
| 6395 | TypeSourceInfo *TInfo |
| 6396 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6397 | if (!TInfo) |
| 6398 | return ExprError(); |
| 6399 | |
| 6400 | if (!getDerived().AlwaysRebuild() && |
| 6401 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6402 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6403 | |
| 6404 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6405 | E->getLocStart(), |
| 6406 | TInfo, |
| 6407 | E->getLocEnd()); |
| 6408 | } |
| 6409 | |
| 6410 | // We don't know whether the expression is potentially evaluated until |
| 6411 | // after we perform semantic analysis, so the expression is potentially |
| 6412 | // potentially evaluated. |
| 6413 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6414 | |
| 6415 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6416 | if (SubExpr.isInvalid()) |
| 6417 | return ExprError(); |
| 6418 | |
| 6419 | if (!getDerived().AlwaysRebuild() && |
| 6420 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6421 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6422 | |
| 6423 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6424 | E->getLocStart(), |
| 6425 | SubExpr.get(), |
| 6426 | E->getLocEnd()); |
| 6427 | } |
| 6428 | |
| 6429 | template<typename Derived> |
| 6430 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6431 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6432 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6433 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6434 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6435 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6436 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6437 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6438 | CXXNullPtrLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6439 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6440 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6441 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6442 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6443 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6444 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6445 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
| 6446 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); |
| 6447 | QualType T = MD->getThisType(getSema().Context); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6448 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6449 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6450 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6451 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6452 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6453 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6454 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6455 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6456 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6457 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6458 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6460 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 6463 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6464 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6465 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6466 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6467 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6468 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6470 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6471 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6472 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6473 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6474 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6475 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6476 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6477 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6478 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6479 | Param == E->getParam()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6480 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6482 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6484 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6485 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6486 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6487 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6488 | CXXScalarValueInitExpr *E) { |
| 6489 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6490 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6491 | return ExprError(); |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6492 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6493 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6494 | T == E->getTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6495 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6496 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6497 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6498 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6499 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6500 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6501 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6502 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6503 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6504 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6505 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6506 | TypeSourceInfo *AllocTypeInfo |
| 6507 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6508 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6509 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6511 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6512 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6513 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6514 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6515 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6516 | // Transform the placement arguments (if any). |
| 6517 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6518 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6519 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6520 | E->getNumPlacementArgs(), true, |
| 6521 | PlacementArgs, &ArgumentChanged)) |
| 6522 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6523 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6524 | // transform the constructor arguments (if any). |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6525 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6526 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6527 | ConstructorArgs, &ArgumentChanged)) |
| 6528 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6529 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6530 | // Transform constructor, new operator, and delete operator. |
| 6531 | CXXConstructorDecl *Constructor = 0; |
| 6532 | if (E->getConstructor()) { |
| 6533 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6534 | getDerived().TransformDecl(E->getLocStart(), |
| 6535 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6536 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6537 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | FunctionDecl *OperatorNew = 0; |
| 6541 | if (E->getOperatorNew()) { |
| 6542 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6543 | getDerived().TransformDecl(E->getLocStart(), |
| 6544 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6545 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6546 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | FunctionDecl *OperatorDelete = 0; |
| 6550 | if (E->getOperatorDelete()) { |
| 6551 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6552 | getDerived().TransformDecl(E->getLocStart(), |
| 6553 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6554 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6555 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6556 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6557 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6558 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6559 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6560 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6561 | Constructor == E->getConstructor() && |
| 6562 | OperatorNew == E->getOperatorNew() && |
| 6563 | OperatorDelete == E->getOperatorDelete() && |
| 6564 | !ArgumentChanged) { |
| 6565 | // Mark any declarations we need as referenced. |
| 6566 | // FIXME: instantiation-specific. |
| 6567 | if (Constructor) |
| 6568 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6569 | if (OperatorNew) |
| 6570 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6571 | if (OperatorDelete) |
| 6572 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6573 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6574 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6575 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6576 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6577 | if (!ArraySize.get()) { |
| 6578 | // If no array size was specified, but the new expression was |
| 6579 | // instantiated with an array type (e.g., "new T" where T is |
| 6580 | // instantiated with "int[4]"), extract the outer bound from the |
| 6581 | // array type as our array size. We do this with constant and |
| 6582 | // dependently-sized array types. |
| 6583 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6584 | if (!ArrayT) { |
| 6585 | // Do nothing |
| 6586 | } else if (const ConstantArrayType *ConsArrayT |
| 6587 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6588 | ArraySize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6589 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6590 | ConsArrayT->getSize(), |
| 6591 | SemaRef.Context.getSizeType(), |
| 6592 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6593 | AllocType = ConsArrayT->getElementType(); |
| 6594 | } else if (const DependentSizedArrayType *DepArrayT |
| 6595 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6596 | if (DepArrayT->getSizeExpr()) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6597 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6598 | AllocType = DepArrayT->getElementType(); |
| 6599 | } |
| 6600 | } |
| 6601 | } |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6602 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6603 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6604 | E->isGlobalNew(), |
| 6605 | /*FIXME:*/E->getLocStart(), |
| 6606 | move_arg(PlacementArgs), |
| 6607 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6608 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6609 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6610 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6611 | ArraySize.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6612 | /*FIXME:*/E->getLocStart(), |
| 6613 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6614 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6615 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6616 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6617 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6618 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6619 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6620 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6621 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6622 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6623 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6624 | // Transform the delete operator, if known. |
| 6625 | FunctionDecl *OperatorDelete = 0; |
| 6626 | if (E->getOperatorDelete()) { |
| 6627 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6628 | getDerived().TransformDecl(E->getLocStart(), |
| 6629 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6630 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6631 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6632 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6633 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6634 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6635 | Operand.get() == E->getArgument() && |
| 6636 | OperatorDelete == E->getOperatorDelete()) { |
| 6637 | // Mark any declarations we need as referenced. |
| 6638 | // FIXME: instantiation-specific. |
| 6639 | if (OperatorDelete) |
| 6640 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 6641 | |
| 6642 | if (!E->getArgument()->isTypeDependent()) { |
| 6643 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 6644 | E->getDestroyedType()); |
| 6645 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 6646 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 6647 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 6648 | SemaRef.LookupDestructor(Record)); |
| 6649 | } |
| 6650 | } |
| 6651 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6652 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6654 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6655 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 6656 | E->isGlobalDelete(), |
| 6657 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6658 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
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 | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6663 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6664 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6665 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6666 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6667 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6668 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6669 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6670 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6671 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6672 | E->getOperatorLoc(), |
| 6673 | E->isArrow()? tok::arrow : tok::period, |
| 6674 | ObjectTypePtr, |
| 6675 | MayBePseudoDestructor); |
| 6676 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6677 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6678 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6679 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6680 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 6681 | if (QualifierLoc) { |
| 6682 | QualifierLoc |
| 6683 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 6684 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6685 | return ExprError(); |
| 6686 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6687 | CXXScopeSpec SS; |
| 6688 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6689 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6690 | PseudoDestructorTypeStorage Destroyed; |
| 6691 | if (E->getDestroyedTypeInfo()) { |
| 6692 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6693 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6694 | ObjectType, 0, |
| 6695 | QualifierLoc.getNestedNameSpecifier()); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6696 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6697 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6698 | Destroyed = DestroyedTypeInfo; |
| 6699 | } else if (ObjectType->isDependentType()) { |
| 6700 | // We aren't likely to be able to resolve the identifier down to a type |
| 6701 | // now anyway, so just retain the identifier. |
| 6702 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 6703 | E->getDestroyedTypeLoc()); |
| 6704 | } else { |
| 6705 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6706 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6707 | *E->getDestroyedTypeIdentifier(), |
| 6708 | E->getDestroyedTypeLoc(), |
| 6709 | /*Scope=*/0, |
| 6710 | SS, ObjectTypePtr, |
| 6711 | false); |
| 6712 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6713 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6714 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6715 | Destroyed |
| 6716 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 6717 | E->getDestroyedTypeLoc()); |
| 6718 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6719 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6720 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 6721 | if (E->getScopeTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6722 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6723 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6724 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6725 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6726 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6727 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6728 | E->getOperatorLoc(), |
| 6729 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6730 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6731 | ScopeTypeInfo, |
| 6732 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6733 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6734 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6736 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6737 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6738 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6739 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6740 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6741 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 6742 | |
| 6743 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 6744 | Sema::LookupOrdinaryName); |
| 6745 | |
| 6746 | // Transform all the decls. |
| 6747 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 6748 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6749 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6750 | getDerived().TransformDecl(Old->getNameLoc(), |
| 6751 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6752 | if (!InstD) { |
| 6753 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6754 | // This can happen because of dependent hiding. |
| 6755 | if (isa<UsingShadowDecl>(*I)) |
| 6756 | continue; |
| 6757 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6758 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6759 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6760 | |
| 6761 | // Expand using declarations. |
| 6762 | if (isa<UsingDecl>(InstD)) { |
| 6763 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6764 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6765 | E = UD->shadow_end(); I != E; ++I) |
| 6766 | R.addDecl(*I); |
| 6767 | continue; |
| 6768 | } |
| 6769 | |
| 6770 | R.addDecl(InstD); |
| 6771 | } |
| 6772 | |
| 6773 | // Resolve a kind, but don't do any further analysis. If it's |
| 6774 | // ambiguous, the callee needs to deal with it. |
| 6775 | R.resolveKind(); |
| 6776 | |
| 6777 | // Rebuild the nested-name qualifier, if present. |
| 6778 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6779 | if (Old->getQualifierLoc()) { |
| 6780 | NestedNameSpecifierLoc QualifierLoc |
| 6781 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 6782 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6783 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6784 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6785 | SS.Adopt(QualifierLoc); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6786 | } |
| 6787 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6788 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6789 | CXXRecordDecl *NamingClass |
| 6790 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 6791 | Old->getNameLoc(), |
| 6792 | Old->getNamingClass())); |
| 6793 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6794 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6795 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6796 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | // If we have no template arguments, it's a normal declaration name. |
| 6800 | if (!Old->hasExplicitTemplateArgs()) |
| 6801 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 6802 | |
| 6803 | // If we have template arguments, rebuild them, then rebuild the |
| 6804 | // templateid expression. |
| 6805 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6806 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6807 | Old->getNumTemplateArgs(), |
| 6808 | TransArgs)) |
| 6809 | return ExprError(); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6810 | |
| 6811 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 6812 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6813 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6815 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6816 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6817 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6818 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 6819 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6820 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6821 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6822 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6823 | T == E->getQueriedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6824 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6825 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6826 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6827 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6828 | T, |
| 6829 | E->getLocEnd()); |
| 6830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6831 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6832 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6833 | ExprResult |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 6834 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 6835 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 6836 | if (!LhsT) |
| 6837 | return ExprError(); |
| 6838 | |
| 6839 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 6840 | if (!RhsT) |
| 6841 | return ExprError(); |
| 6842 | |
| 6843 | if (!getDerived().AlwaysRebuild() && |
| 6844 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 6845 | return SemaRef.Owned(E); |
| 6846 | |
| 6847 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 6848 | E->getLocStart(), |
| 6849 | LhsT, RhsT, |
| 6850 | E->getLocEnd()); |
| 6851 | } |
| 6852 | |
| 6853 | template<typename Derived> |
| 6854 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6855 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6856 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6857 | NestedNameSpecifierLoc QualifierLoc |
| 6858 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6859 | if (!QualifierLoc) |
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 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6862 | // TODO: If this is a conversion-function-id, verify that the |
| 6863 | // destination type name (if present) resolves the same way after |
| 6864 | // instantiation as it did in the local scope. |
| 6865 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6866 | DeclarationNameInfo NameInfo |
| 6867 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 6868 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6869 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6870 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6871 | if (!E->hasExplicitTemplateArgs()) { |
| 6872 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6873 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6874 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 6875 | // if name has not changed, DNLoc has not changed either. |
| 6876 | NameInfo.getName() == E->getDeclName()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6877 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6878 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6879 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6880 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6881 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6882 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6883 | |
| 6884 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6885 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6886 | E->getNumTemplateArgs(), |
| 6887 | TransArgs)) |
| 6888 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6889 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6890 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6891 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6892 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6896 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6897 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 6898 | // CXXConstructExprs are always implicit, so when we have a |
| 6899 | // 1-argument construction we just transform that argument. |
| 6900 | if (E->getNumArgs() == 1 || |
| 6901 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 6902 | return getDerived().TransformExpr(E->getArg(0)); |
| 6903 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6904 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 6905 | |
| 6906 | QualType T = getDerived().TransformType(E->getType()); |
| 6907 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6908 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6909 | |
| 6910 | CXXConstructorDecl *Constructor |
| 6911 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6912 | getDerived().TransformDecl(E->getLocStart(), |
| 6913 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6915 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6917 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6918 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6919 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6920 | &ArgumentChanged)) |
| 6921 | return ExprError(); |
| 6922 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6923 | if (!getDerived().AlwaysRebuild() && |
| 6924 | T == E->getType() && |
| 6925 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6926 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6927 | // Mark the constructor as referenced. |
| 6928 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6929 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6930 | return SemaRef.Owned(E); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6931 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6932 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 6933 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 6934 | Constructor, E->isElidable(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 6935 | move_arg(Args), |
| 6936 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 6937 | E->getConstructionKind(), |
| 6938 | E->getParenRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6939 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6940 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6941 | /// \brief Transform a C++ temporary-binding expression. |
| 6942 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6943 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 6944 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6945 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6946 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6947 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6948 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6950 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6951 | /// \brief Transform a C++ expression that contains cleanups that should |
| 6952 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6953 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6954 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6955 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6956 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6957 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6958 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6959 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6960 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6961 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6962 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6963 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6964 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6965 | CXXTemporaryObjectExpr *E) { |
| 6966 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6967 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6968 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6969 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6970 | CXXConstructorDecl *Constructor |
| 6971 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6972 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6973 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6974 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6975 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6976 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6977 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6978 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6979 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6980 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6981 | &ArgumentChanged)) |
| 6982 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6983 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6984 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6985 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6986 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6987 | !ArgumentChanged) { |
| 6988 | // FIXME: Instantiation-specific |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6989 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6990 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6991 | } |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6992 | |
| 6993 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 6994 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6995 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6996 | E->getLocEnd()); |
| 6997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6998 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6999 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7000 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7001 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7002 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7003 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7004 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7005 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7006 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7007 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7008 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7009 | Args.reserve(E->arg_size()); |
| 7010 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 7011 | &ArgumentChanged)) |
| 7012 | return ExprError(); |
| 7013 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7014 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7015 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7016 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7017 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7019 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7020 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7021 | E->getLParenLoc(), |
| 7022 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7023 | E->getRParenLoc()); |
| 7024 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7025 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7026 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7027 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7028 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7029 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7030 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7031 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7032 | Expr *OldBase; |
| 7033 | QualType BaseType; |
| 7034 | QualType ObjectType; |
| 7035 | if (!E->isImplicitAccess()) { |
| 7036 | OldBase = E->getBase(); |
| 7037 | Base = getDerived().TransformExpr(OldBase); |
| 7038 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7039 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7040 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7041 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7042 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7043 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7044 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7045 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7046 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7047 | ObjectTy, |
| 7048 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7049 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7050 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7051 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7052 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7053 | BaseType = ((Expr*) Base.get())->getType(); |
| 7054 | } else { |
| 7055 | OldBase = 0; |
| 7056 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 7057 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 7058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7059 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7060 | // Transform the first part of the nested-name-specifier that qualifies |
| 7061 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7062 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7063 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7064 | E->getFirstQualifierFoundInScope(), |
| 7065 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7066 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7067 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7068 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7069 | QualifierLoc |
| 7070 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 7071 | ObjectType, |
| 7072 | FirstQualifierInScope); |
| 7073 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7074 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7075 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7076 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7077 | // TODO: If this is a conversion-function-id, verify that the |
| 7078 | // destination type name (if present) resolves the same way after |
| 7079 | // instantiation as it did in the local scope. |
| 7080 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7081 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7082 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7083 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7084 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7085 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7086 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7087 | // This is a reference to a member without an explicitly-specified |
| 7088 | // template argument list. Optimize for this common case. |
| 7089 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7090 | Base.get() == OldBase && |
| 7091 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7092 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7093 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7094 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7095 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7096 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7097 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7098 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7099 | E->isArrow(), |
| 7100 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7101 | QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7102 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7103 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7104 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7105 | } |
| 7106 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7107 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7108 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7109 | E->getNumTemplateArgs(), |
| 7110 | TransArgs)) |
| 7111 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7112 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7113 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7114 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7115 | E->isArrow(), |
| 7116 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7117 | QualifierLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7118 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7119 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7120 | &TransArgs); |
| 7121 | } |
| 7122 | |
| 7123 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7124 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7125 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7126 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7127 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7128 | QualType BaseType; |
| 7129 | if (!Old->isImplicitAccess()) { |
| 7130 | Base = getDerived().TransformExpr(Old->getBase()); |
| 7131 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7132 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7133 | BaseType = ((Expr*) Base.get())->getType(); |
| 7134 | } else { |
| 7135 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 7136 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7137 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7138 | NestedNameSpecifierLoc QualifierLoc; |
| 7139 | if (Old->getQualifierLoc()) { |
| 7140 | QualifierLoc |
| 7141 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7142 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7143 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7144 | } |
| 7145 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7146 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7147 | Sema::LookupOrdinaryName); |
| 7148 | |
| 7149 | // Transform all the decls. |
| 7150 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 7151 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7152 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7153 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 7154 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7155 | if (!InstD) { |
| 7156 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7157 | // This can happen because of dependent hiding. |
| 7158 | if (isa<UsingShadowDecl>(*I)) |
| 7159 | continue; |
| 7160 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7161 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7162 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7163 | |
| 7164 | // Expand using declarations. |
| 7165 | if (isa<UsingDecl>(InstD)) { |
| 7166 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7167 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7168 | E = UD->shadow_end(); I != E; ++I) |
| 7169 | R.addDecl(*I); |
| 7170 | continue; |
| 7171 | } |
| 7172 | |
| 7173 | R.addDecl(InstD); |
| 7174 | } |
| 7175 | |
| 7176 | R.resolveKind(); |
| 7177 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7178 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 7179 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7180 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7181 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7182 | Old->getMemberLoc(), |
| 7183 | Old->getNamingClass())); |
| 7184 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7185 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7186 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7187 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7188 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7189 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7190 | TemplateArgumentListInfo TransArgs; |
| 7191 | if (Old->hasExplicitTemplateArgs()) { |
| 7192 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 7193 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7194 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7195 | Old->getNumTemplateArgs(), |
| 7196 | TransArgs)) |
| 7197 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7198 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7199 | |
| 7200 | // FIXME: to do this check properly, we will need to preserve the |
| 7201 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7202 | // base (and therefore couldn't do the check) and a |
| 7203 | // nested-name-qualifier (and therefore could do the lookup). |
| 7204 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7205 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7206 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7207 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7208 | Old->getOperatorLoc(), |
| 7209 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7210 | QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7211 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7212 | R, |
| 7213 | (Old->hasExplicitTemplateArgs() |
| 7214 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7218 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7219 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 7220 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 7221 | if (SubExpr.isInvalid()) |
| 7222 | return ExprError(); |
| 7223 | |
| 7224 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7225 | return SemaRef.Owned(E); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7226 | |
| 7227 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 7228 | } |
| 7229 | |
| 7230 | template<typename Derived> |
| 7231 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7232 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 7233 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 7234 | if (Pattern.isInvalid()) |
| 7235 | return ExprError(); |
| 7236 | |
| 7237 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 7238 | return SemaRef.Owned(E); |
| 7239 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 7240 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 7241 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7242 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7243 | |
| 7244 | template<typename Derived> |
| 7245 | ExprResult |
| 7246 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7247 | // If E is not value-dependent, then nothing will change when we transform it. |
| 7248 | // Note: This is an instantiation-centric view. |
| 7249 | if (!E->isValueDependent()) |
| 7250 | return SemaRef.Owned(E); |
| 7251 | |
| 7252 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 7253 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 7254 | // so |
| 7255 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 7256 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7257 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7258 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7259 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 7260 | &Unexpanded, 1, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7261 | ShouldExpand, RetainExpansion, |
| 7262 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7263 | return ExprError(); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7264 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7265 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7266 | return SemaRef.Owned(E); |
| 7267 | |
| 7268 | // We now know the length of the parameter pack, so build a new expression |
| 7269 | // that stores that length. |
| 7270 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 7271 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7272 | *NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7273 | } |
| 7274 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7275 | template<typename Derived> |
| 7276 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 7277 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 7278 | SubstNonTypeTemplateParmPackExpr *E) { |
| 7279 | // Default behavior is to do nothing with this transformation. |
| 7280 | return SemaRef.Owned(E); |
| 7281 | } |
| 7282 | |
| 7283 | template<typename Derived> |
| 7284 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7285 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7286 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7287 | } |
| 7288 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7289 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7290 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7291 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7292 | TypeSourceInfo *EncodedTypeInfo |
| 7293 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 7294 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7295 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7296 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7297 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7298 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7299 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7300 | |
| 7301 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7302 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7303 | E->getRParenLoc()); |
| 7304 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7305 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7306 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7307 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7308 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7309 | // Transform arguments. |
| 7310 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7311 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7312 | Args.reserve(E->getNumArgs()); |
| 7313 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 7314 | &ArgChanged)) |
| 7315 | return ExprError(); |
| 7316 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7317 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 7318 | // Class message: transform the receiver type. |
| 7319 | TypeSourceInfo *ReceiverTypeInfo |
| 7320 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 7321 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7322 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7323 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7324 | // If nothing changed, just retain the existing message send. |
| 7325 | if (!getDerived().AlwaysRebuild() && |
| 7326 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7327 | return SemaRef.Owned(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7328 | |
| 7329 | // Build a new class message send. |
| 7330 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7331 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7332 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7333 | E->getMethodDecl(), |
| 7334 | E->getLeftLoc(), |
| 7335 | move_arg(Args), |
| 7336 | E->getRightLoc()); |
| 7337 | } |
| 7338 | |
| 7339 | // Instance message: transform the receiver |
| 7340 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7341 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7342 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7343 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7344 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7345 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7346 | |
| 7347 | // If nothing changed, just retain the existing message send. |
| 7348 | if (!getDerived().AlwaysRebuild() && |
| 7349 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7350 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7351 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7352 | // Build a new instance message send. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7353 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7354 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7355 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7356 | E->getMethodDecl(), |
| 7357 | E->getLeftLoc(), |
| 7358 | move_arg(Args), |
| 7359 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7360 | } |
| 7361 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7362 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7363 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7364 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7365 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7366 | } |
| 7367 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7368 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7369 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7370 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7371 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7372 | } |
| 7373 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7374 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7375 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7376 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7377 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7378 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7379 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7380 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7381 | |
| 7382 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7383 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7384 | // If nothing changed, just retain the existing expression. |
| 7385 | if (!getDerived().AlwaysRebuild() && |
| 7386 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7387 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7388 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7389 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7390 | E->getLocation(), |
| 7391 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7392 | } |
| 7393 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7394 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7395 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7396 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7397 | // 'super' and types never change. Property never changes. Just |
| 7398 | // retain the existing expression. |
| 7399 | if (!E->isObjectReceiver()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7400 | return SemaRef.Owned(E); |
Fariborz Jahanian | 681c075 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7401 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7402 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7403 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7404 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7405 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7406 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7407 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7408 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7409 | // If nothing changed, just retain the existing expression. |
| 7410 | if (!getDerived().AlwaysRebuild() && |
| 7411 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7412 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7413 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7414 | if (E->isExplicitProperty()) |
| 7415 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7416 | E->getExplicitProperty(), |
| 7417 | E->getLocation()); |
| 7418 | |
| 7419 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7420 | E->getType(), |
| 7421 | E->getImplicitPropertyGetter(), |
| 7422 | E->getImplicitPropertySetter(), |
| 7423 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7424 | } |
| 7425 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7426 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7427 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7428 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7429 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7430 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7431 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7432 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7433 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7434 | // If nothing changed, just retain the existing expression. |
| 7435 | if (!getDerived().AlwaysRebuild() && |
| 7436 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7437 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7438 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7439 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7440 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7441 | } |
| 7442 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7443 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7444 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7445 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7446 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7447 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7448 | SubExprs.reserve(E->getNumSubExprs()); |
| 7449 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7450 | SubExprs, &ArgumentChanged)) |
| 7451 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7452 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7453 | if (!getDerived().AlwaysRebuild() && |
| 7454 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7455 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7456 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7457 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7458 | move_arg(SubExprs), |
| 7459 | E->getRParenLoc()); |
| 7460 | } |
| 7461 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7462 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7463 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7464 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7465 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7466 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7467 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7468 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7469 | |
| 7470 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 7471 | llvm::SmallVector<ParmVarDecl*, 4> params; |
| 7472 | llvm::SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7473 | |
| 7474 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7475 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7476 | oldBlock->param_begin(), |
| 7477 | oldBlock->param_size(), |
| 7478 | 0, paramTypes, ¶ms)) |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7479 | return true; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7480 | |
| 7481 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7482 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7483 | if (!exprResultType.isNull()) { |
| 7484 | if (!exprResultType->isDependentType()) |
| 7485 | blockScope->ReturnType = exprResultType; |
| 7486 | else if (exprResultType != getSema().Context.DependentTy) |
| 7487 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7488 | } |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7489 | |
| 7490 | // If the return type has not been determined yet, leave it as a dependent |
| 7491 | // type; it'll get set when we process the body. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7492 | if (blockScope->ReturnType.isNull()) |
| 7493 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7494 | |
| 7495 | // Don't allow returning a objc interface by value. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7496 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7497 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7498 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7499 | << 0 << blockScope->ReturnType; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7500 | return ExprError(); |
| 7501 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7502 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7503 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7504 | blockScope->ReturnType, |
| 7505 | paramTypes.data(), |
| 7506 | paramTypes.size(), |
| 7507 | oldBlock->isVariadic(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7508 | 0, RQ_None, |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7509 | exprFunctionType->getExtInfo()); |
| 7510 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7511 | |
| 7512 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7513 | if (!params.empty()) |
| 7514 | blockScope->TheDecl->setParams(params.data(), params.size()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7515 | |
| 7516 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7517 | // dependent type (DependentTy); clear out the return type setting so |
| 7518 | // 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] | 7519 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7520 | blockScope->ReturnType = QualType(); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7521 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7522 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7523 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7524 | if (body.isInvalid()) |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7525 | return ExprError(); |
| 7526 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7527 | #ifndef NDEBUG |
| 7528 | // In builds with assertions, make sure that we captured everything we |
| 7529 | // captured before. |
| 7530 | |
| 7531 | if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); |
| 7532 | |
| 7533 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 7534 | e = oldBlock->capture_end(); i != e; ++i) { |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7535 | VarDecl *oldCapture = i->getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7536 | |
| 7537 | // Ignore parameter packs. |
| 7538 | if (isa<ParmVarDecl>(oldCapture) && |
| 7539 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 7540 | continue; |
| 7541 | |
| 7542 | VarDecl *newCapture = |
| 7543 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 7544 | oldCapture)); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7545 | assert(blockScope->CaptureMap.count(newCapture)); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7546 | } |
| 7547 | #endif |
| 7548 | |
| 7549 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 7550 | /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7551 | } |
| 7552 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7553 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7554 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7555 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7556 | ValueDecl *ND |
| 7557 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7558 | E->getDecl())); |
| 7559 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7560 | return ExprError(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7561 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7562 | if (!getDerived().AlwaysRebuild() && |
| 7563 | ND == E->getDecl()) { |
| 7564 | // Mark it referenced in the new context regardless. |
| 7565 | // FIXME: this is a bit instantiation-specific. |
| 7566 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 7567 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7568 | return SemaRef.Owned(E); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7569 | } |
| 7570 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7571 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7572 | return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7573 | ND, NameInfo, 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7574 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7575 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7576 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7577 | // Type reconstruction |
| 7578 | //===----------------------------------------------------------------------===// |
| 7579 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7580 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7581 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 7582 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7583 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7584 | getDerived().getBaseEntity()); |
| 7585 | } |
| 7586 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7587 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7588 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 7589 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7590 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7591 | getDerived().getBaseEntity()); |
| 7592 | } |
| 7593 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7594 | template<typename Derived> |
| 7595 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7596 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 7597 | bool WrittenAsLValue, |
| 7598 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7599 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7600 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7604 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7605 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 7606 | QualType ClassType, |
| 7607 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7608 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7609 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7613 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7614 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 7615 | ArrayType::ArraySizeModifier SizeMod, |
| 7616 | const llvm::APInt *Size, |
| 7617 | Expr *SizeExpr, |
| 7618 | unsigned IndexTypeQuals, |
| 7619 | SourceRange BracketsRange) { |
| 7620 | if (SizeExpr || !Size) |
| 7621 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 7622 | IndexTypeQuals, BracketsRange, |
| 7623 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7624 | |
| 7625 | QualType Types[] = { |
| 7626 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 7627 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 7628 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7629 | }; |
| 7630 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 7631 | QualType SizeType; |
| 7632 | for (unsigned I = 0; I != NumTypes; ++I) |
| 7633 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 7634 | SizeType = Types[I]; |
| 7635 | break; |
| 7636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7637 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7638 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 7639 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7640 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7641 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7642 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7643 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7644 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7645 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7646 | QualType |
| 7647 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7648 | ArrayType::ArraySizeModifier SizeMod, |
| 7649 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7650 | unsigned IndexTypeQuals, |
| 7651 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7652 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7653 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7657 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7658 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7659 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7660 | unsigned IndexTypeQuals, |
| 7661 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7662 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7663 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7664 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7665 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7666 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7667 | QualType |
| 7668 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7669 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7670 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7671 | unsigned IndexTypeQuals, |
| 7672 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7673 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7674 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7675 | IndexTypeQuals, BracketsRange); |
| 7676 | } |
| 7677 | |
| 7678 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7679 | QualType |
| 7680 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7681 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7682 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7683 | unsigned IndexTypeQuals, |
| 7684 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7685 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7686 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7687 | IndexTypeQuals, BracketsRange); |
| 7688 | } |
| 7689 | |
| 7690 | template<typename Derived> |
| 7691 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7692 | unsigned NumElements, |
| 7693 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7694 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7695 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7696 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7697 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7698 | template<typename Derived> |
| 7699 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 7700 | unsigned NumElements, |
| 7701 | SourceLocation AttributeLoc) { |
| 7702 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 7703 | NumElements, true); |
| 7704 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7705 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 7706 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7707 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7708 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7709 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7710 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7711 | QualType |
| 7712 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7713 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7714 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7715 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7716 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7717 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7718 | template<typename Derived> |
| 7719 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7720 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7721 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7722 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7723 | unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7724 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7725 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7726 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7727 | Quals, RefQualifier, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7728 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7729 | getDerived().getBaseEntity(), |
| 7730 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7732 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7733 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 7734 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 7735 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 7736 | } |
| 7737 | |
| 7738 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7739 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 7740 | assert(D && "no decl found"); |
| 7741 | if (D->isInvalidDecl()) return QualType(); |
| 7742 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7743 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7744 | TypeDecl *Ty; |
| 7745 | if (isa<UsingDecl>(D)) { |
| 7746 | UsingDecl *Using = cast<UsingDecl>(D); |
| 7747 | assert(Using->isTypeName() && |
| 7748 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 7749 | |
| 7750 | // A valid resolved using typename decl points to exactly one type decl. |
| 7751 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 7752 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7753 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7754 | } else { |
| 7755 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 7756 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 7757 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 7758 | } |
| 7759 | |
| 7760 | return SemaRef.Context.getTypeDeclType(Ty); |
| 7761 | } |
| 7762 | |
| 7763 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7764 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 7765 | SourceLocation Loc) { |
| 7766 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7767 | } |
| 7768 | |
| 7769 | template<typename Derived> |
| 7770 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 7771 | return SemaRef.Context.getTypeOfType(Underlying); |
| 7772 | } |
| 7773 | |
| 7774 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7775 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 7776 | SourceLocation Loc) { |
| 7777 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7778 | } |
| 7779 | |
| 7780 | template<typename Derived> |
| 7781 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 7782 | TemplateName Template, |
| 7783 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7784 | const TemplateArgumentListInfo &TemplateArgs) { |
| 7785 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7786 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7787 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7788 | template<typename Derived> |
| 7789 | NestedNameSpecifier * |
| 7790 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7791 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7792 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7793 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7794 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7795 | CXXScopeSpec SS; |
| 7796 | // FIXME: The source location information is all wrong. |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7797 | SS.MakeTrivial(SemaRef.Context, Prefix, Range); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 7798 | if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(), |
| 7799 | /*FIXME:*/Range.getEnd(), |
| 7800 | ObjectType, false, |
| 7801 | SS, FirstQualifierInScope, |
| 7802 | false)) |
| 7803 | return 0; |
| 7804 | |
| 7805 | return SS.getScopeRep(); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7806 | } |
| 7807 | |
| 7808 | template<typename Derived> |
| 7809 | NestedNameSpecifier * |
| 7810 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7811 | SourceRange Range, |
| 7812 | NamespaceDecl *NS) { |
| 7813 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 7814 | } |
| 7815 | |
| 7816 | template<typename Derived> |
| 7817 | NestedNameSpecifier * |
| 7818 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7819 | SourceRange Range, |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 7820 | NamespaceAliasDecl *Alias) { |
| 7821 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias); |
| 7822 | } |
| 7823 | |
| 7824 | template<typename Derived> |
| 7825 | NestedNameSpecifier * |
| 7826 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7827 | SourceRange Range, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7828 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 7829 | QualType T) { |
| 7830 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7831 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 7832 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7833 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 7834 | T.getTypePtr()); |
| 7835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7836 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7837 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 7838 | return 0; |
| 7839 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7840 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7841 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7842 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7843 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7844 | bool TemplateKW, |
| 7845 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7846 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7847 | Template); |
| 7848 | } |
| 7849 | |
| 7850 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7851 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7852 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 7853 | SourceRange QualifierRange, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7854 | const IdentifierInfo &II, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7855 | QualType ObjectType, |
| 7856 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7857 | CXXScopeSpec SS; |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7858 | SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 7859 | UnqualifiedId Name; |
| 7860 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7861 | Sema::TemplateTy Template; |
| 7862 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 7863 | /*FIXME:*/getDerived().getBaseLocation(), |
| 7864 | SS, |
| 7865 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7866 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7867 | /*EnteringContext=*/false, |
| 7868 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7869 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7871 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7872 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7873 | TemplateName |
| 7874 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 7875 | OverloadedOperatorKind Operator, |
| 7876 | QualType ObjectType) { |
| 7877 | CXXScopeSpec SS; |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7878 | SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7879 | UnqualifiedId Name; |
| 7880 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 7881 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 7882 | Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7883 | Sema::TemplateTy Template; |
| 7884 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7885 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7886 | SS, |
| 7887 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7888 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7889 | /*EnteringContext=*/false, |
| 7890 | Template); |
| 7891 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7892 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7893 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7894 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7895 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7896 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 7897 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7898 | Expr *OrigCallee, |
| 7899 | Expr *First, |
| 7900 | Expr *Second) { |
| 7901 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 7902 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7903 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7904 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7905 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7906 | if (!First->getType()->isOverloadableType() && |
| 7907 | !Second->getType()->isOverloadableType()) |
| 7908 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 7909 | Callee->getLocStart(), |
| 7910 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 7911 | } else if (Op == OO_Arrow) { |
| 7912 | // -> is never a builtin operation. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7913 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 7914 | } else if (Second == 0 || isPostIncDec) { |
| 7915 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7916 | // The argument is not of overloadable type, so try to create a |
| 7917 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7918 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7919 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7920 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7921 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7922 | } |
| 7923 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7924 | if (!First->getType()->isOverloadableType() && |
| 7925 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7926 | // Neither of the arguments is an overloadable type, so try to |
| 7927 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7928 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7929 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7930 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7931 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7932 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7934 | return move(Result); |
| 7935 | } |
| 7936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7937 | |
| 7938 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7939 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7940 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7941 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7942 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7943 | assert(ULE->requiresADL()); |
| 7944 | |
| 7945 | // FIXME: Do we have to check |
| 7946 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7947 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7948 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7949 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7950 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7951 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7952 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7953 | Expr *Args[2] = { First, Second }; |
| 7954 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7956 | // Create the overloaded operator invocation for unary operators. |
| 7957 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7958 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7959 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7960 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7962 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7963 | if (Op == OO_Subscript) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7964 | return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7965 | OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7966 | First, |
| 7967 | Second); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7968 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7969 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7970 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7971 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7972 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 7973 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7974 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7975 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7976 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7977 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7978 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7979 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7980 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7981 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7982 | SourceLocation OperatorLoc, |
| 7983 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7984 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7985 | TypeSourceInfo *ScopeType, |
| 7986 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7987 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7988 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7989 | QualType BaseType = Base->getType(); |
| 7990 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7991 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7992 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 7993 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 7994 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7995 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7996 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7997 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7998 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7999 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8000 | /*FIXME?*/true); |
| 8001 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8002 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8003 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8004 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 8005 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 8006 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 8007 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 8008 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8009 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8010 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8011 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8012 | OperatorLoc, isArrow, |
| 8013 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8014 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8015 | /*TemplateArgs*/ 0); |
| 8016 | } |
| 8017 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8018 | } // end namespace clang |
| 8019 | |
| 8020 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |