Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
John McCall | 8302463 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 18 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
| 27 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 28 | #include "clang/AST/Stmt.h" |
| 29 | #include "clang/AST/StmtCXX.h" |
| 30 | #include "clang/AST/StmtObjC.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/Designator.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 33 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 451d1b1 | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 35 | #include "TypeLocBuilder.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 36 | #include <algorithm> |
| 37 | |
| 38 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 39 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 41 | /// \brief A semantic tree transformation that allows one to transform one |
| 42 | /// abstract syntax tree into another. |
| 43 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 44 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 45 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 46 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 47 | /// instantiation is implemented as a tree transformation where the |
| 48 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 49 | /// template arguments for their corresponding template parameters; a similar |
| 50 | /// transformation is performed for non-type template parameters and |
| 51 | /// template template parameters. |
| 52 | /// |
| 53 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 55 | /// override any of the transformation or rebuild operators by providing an |
| 56 | /// operation with the same signature as the default implementation. The |
| 57 | /// overridding function should not be virtual. |
| 58 | /// |
| 59 | /// Semantic tree transformations are split into two stages, either of which |
| 60 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 61 | /// or the parts of an AST node using the various transformation functions, |
| 62 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 63 | /// node of the appropriate kind from the pieces. The default transformation |
| 64 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 65 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 66 | /// were changed by the transformation, invokes the rebuild operation to create |
| 67 | /// a new AST node. |
| 68 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 70 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 71 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 73 | /// new implementations. |
| 74 | /// |
| 75 | /// For more fine-grained transformations, subclasses can replace any of the |
| 76 | /// \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] | 77 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 78 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 80 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 81 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 82 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 83 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 84 | /// be able to use more efficient rebuild steps. |
| 85 | /// |
| 86 | /// 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] | 87 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 88 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 89 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 90 | /// default locations and entity names used for type-checking |
| 91 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 92 | template<typename Derived> |
| 93 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 94 | /// \brief Private RAII object that helps us forget and then re-remember |
| 95 | /// the template argument corresponding to a partially-substituted parameter |
| 96 | /// pack. |
| 97 | class ForgetPartiallySubstitutedPackRAII { |
| 98 | Derived &Self; |
| 99 | TemplateArgument Old; |
| 100 | |
| 101 | public: |
| 102 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 103 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 104 | } |
| 105 | |
| 106 | ~ForgetPartiallySubstitutedPackRAII() { |
| 107 | Self.RememberPartiallySubstitutedPack(Old); |
| 108 | } |
| 109 | }; |
| 110 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 111 | protected: |
| 112 | Sema &SemaRef; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 113 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 115 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 116 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 118 | /// \brief Retrieves a reference to the derived class. |
| 119 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 120 | |
| 121 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | const Derived &getDerived() const { |
| 123 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 124 | } |
| 125 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 126 | static inline ExprResult Owned(Expr *E) { return E; } |
| 127 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 128 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 129 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 130 | /// this tree transform. |
| 131 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 133 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 134 | /// if none of the children have changed. |
| 135 | /// |
| 136 | /// Subclasses may override this function to specify when the transformation |
| 137 | /// should rebuild all AST nodes. |
| 138 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 140 | /// \brief Returns the location of the entity being transformed, if that |
| 141 | /// information was not available elsewhere in the AST. |
| 142 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 144 | /// provide an alternative implementation that provides better location |
| 145 | /// information. |
| 146 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 147 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 148 | /// \brief Returns the name of the entity being transformed, if that |
| 149 | /// information was not available elsewhere in the AST. |
| 150 | /// |
| 151 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 152 | /// implementation with a more precise name. |
| 153 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 155 | /// \brief Sets the "base" location and entity when that |
| 156 | /// information is known based on another transformation. |
| 157 | /// |
| 158 | /// By default, the source location and entity are ignored. Subclasses can |
| 159 | /// override this function to provide a customized implementation. |
| 160 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 162 | /// \brief RAII object that temporarily sets the base location and entity |
| 163 | /// used for reporting diagnostics in types. |
| 164 | class TemporaryBase { |
| 165 | TreeTransform &Self; |
| 166 | SourceLocation OldLocation; |
| 167 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 169 | public: |
| 170 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 172 | OldLocation = Self.getDerived().getBaseLocation(); |
| 173 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 174 | |
| 175 | if (Location.isValid()) |
| 176 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 179 | ~TemporaryBase() { |
| 180 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 181 | } |
| 182 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
| 184 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// transformed. |
| 186 | /// |
| 187 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | /// 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] | 189 | /// not change. For example, template instantiation need not traverse |
| 190 | /// non-dependent types. |
| 191 | bool AlreadyTransformed(QualType T) { |
| 192 | return T.isNull(); |
| 193 | } |
| 194 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 195 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 196 | /// because it is a default argument. |
| 197 | /// |
| 198 | /// Subclasses can provide an alternative implementation of this routine to |
| 199 | /// determine which kinds of call arguments get dropped. By default, |
| 200 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 201 | bool DropCallArgument(Expr *E) { |
| 202 | return E->isDefaultArgument(); |
| 203 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 204 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 205 | /// \brief Determine whether we should expand a pack expansion with the |
| 206 | /// given set of parameter packs into separate arguments by repeatedly |
| 207 | /// transforming the pattern. |
| 208 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 209 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 210 | /// Subclasses can override this routine to provide different behavior. |
| 211 | /// |
| 212 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 213 | /// pack expansion. |
| 214 | /// |
| 215 | /// \param PatternRange The source range that covers the entire pattern of |
| 216 | /// the pack expansion. |
| 217 | /// |
| 218 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 219 | /// pattern. |
| 220 | /// |
| 221 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 222 | /// \p Unexpanded. |
| 223 | /// |
| 224 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 225 | /// expand the corresponding pack expansions into separate arguments. When |
| 226 | /// set, \c NumExpansions must also be set. |
| 227 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 228 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 229 | /// pack expansion after all of the expanded arguments. This is used |
| 230 | /// when extending explicitly-specified template argument packs per |
| 231 | /// C++0x [temp.arg.explicit]p9. |
| 232 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 233 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 234 | /// the expanded form of the corresponding pack expansion. This is both an |
| 235 | /// input and an output parameter, which can be set by the caller if the |
| 236 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 237 | /// and will be set by the callee when the number of expansions is known. |
| 238 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 239 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 240 | /// |
| 241 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 242 | /// are to be instantiated with arguments of different lengths), false |
| 243 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 244 | /// must be set. |
| 245 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 246 | SourceRange PatternRange, |
| 247 | const UnexpandedParameterPack *Unexpanded, |
| 248 | unsigned NumUnexpanded, |
| 249 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 250 | bool &RetainExpansion, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 251 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 252 | ShouldExpand = false; |
| 253 | return false; |
| 254 | } |
| 255 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 256 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 257 | /// when performing an instantiation that must preserve the parameter pack |
| 258 | /// use. |
| 259 | /// |
| 260 | /// This routine is meant to be overridden by the template instantiator. |
| 261 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 262 | return TemplateArgument(); |
| 263 | } |
| 264 | |
| 265 | /// \brief "Remember" the partially-substituted pack template argument |
| 266 | /// after performing an instantiation that must preserve the parameter pack |
| 267 | /// use. |
| 268 | /// |
| 269 | /// This routine is meant to be overridden by the template instantiator. |
| 270 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 271 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 272 | /// \brief Note to the derived class when a function parameter pack is |
| 273 | /// being expanded. |
| 274 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 275 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 276 | /// \brief Transforms the given type into another type. |
| 277 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 278 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 279 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 280 | /// function. This is expensive, but we don't mind, because |
| 281 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 282 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// |
| 284 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 285 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 287 | /// \brief Transforms the given type-with-location into a new |
| 288 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 290 | /// By default, this routine transforms a type by delegating to the |
| 291 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 292 | /// may override this function (to take over all type |
| 293 | /// transformations) or some set of the TransformXXXType functions |
| 294 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 295 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 296 | |
| 297 | /// \brief Transform the given type-with-location into a new |
| 298 | /// type, collecting location information in the given builder |
| 299 | /// as necessary. |
| 300 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 301 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 303 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 304 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 306 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 307 | /// statement or the TransformExpr() function to transform an expression. |
| 308 | /// Subclasses may override this function to transform statements using some |
| 309 | /// other mechanism. |
| 310 | /// |
| 311 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 312 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 314 | /// \brief Transform the given expression. |
| 315 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 316 | /// By default, this routine transforms an expression by delegating to the |
| 317 | /// appropriate TransformXXXExpr function to build a new expression. |
| 318 | /// Subclasses may override this function to transform expressions using some |
| 319 | /// other mechanism. |
| 320 | /// |
| 321 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 322 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 324 | /// \brief Transform the given list of expressions. |
| 325 | /// |
| 326 | /// This routine transforms a list of expressions by invoking |
| 327 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 328 | /// support for variadic templates by expanding any pack expansions (if the |
| 329 | /// derived class permits such expansion) along the way. When pack expansions |
| 330 | /// are present, the number of outputs may not equal the number of inputs. |
| 331 | /// |
| 332 | /// \param Inputs The set of expressions to be transformed. |
| 333 | /// |
| 334 | /// \param NumInputs The number of expressions in \c Inputs. |
| 335 | /// |
| 336 | /// \param IsCall If \c true, then this transform is being performed on |
| 337 | /// function-call arguments, and any arguments that should be dropped, will |
| 338 | /// be. |
| 339 | /// |
| 340 | /// \param Outputs The transformed input expressions will be added to this |
| 341 | /// vector. |
| 342 | /// |
| 343 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 344 | /// due to transformation. |
| 345 | /// |
| 346 | /// \returns true if an error occurred, false otherwise. |
| 347 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
| 348 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 349 | bool *ArgChanged = 0); |
| 350 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 351 | /// \brief Transform the given declaration, which is referenced from a type |
| 352 | /// or expression. |
| 353 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 354 | /// By default, acts as the identity function on declarations. Subclasses |
| 355 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 356 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 357 | |
| 358 | /// \brief Transform the definition of the given declaration. |
| 359 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 361 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 362 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 363 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 366 | /// \brief Transform the given declaration, which was the first part of a |
| 367 | /// nested-name-specifier in a member access expression. |
| 368 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 369 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 370 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 371 | /// the \c T in \c x->T::member |
| 372 | /// |
| 373 | /// By default, invokes TransformDecl() to transform the declaration. |
| 374 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 375 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 376 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 377 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 378 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 379 | /// \brief Transform the given nested-name-specifier with source-location |
| 380 | /// information. |
| 381 | /// |
| 382 | /// By default, transforms all of the types and declarations within the |
| 383 | /// nested-name-specifier. Subclasses may override this function to provide |
| 384 | /// alternate behavior. |
| 385 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 386 | NestedNameSpecifierLoc NNS, |
| 387 | QualType ObjectType = QualType(), |
| 388 | NamedDecl *FirstQualifierInScope = 0); |
| 389 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 390 | /// \brief Transform the given declaration name. |
| 391 | /// |
| 392 | /// By default, transforms the types of conversion function, constructor, |
| 393 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 394 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 395 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 396 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 397 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 399 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 401 | /// \param SS The nested-name-specifier that qualifies the template |
| 402 | /// name. This nested-name-specifier must already have been transformed. |
| 403 | /// |
| 404 | /// \param Name The template name to transform. |
| 405 | /// |
| 406 | /// \param NameLoc The source location of the template name. |
| 407 | /// |
| 408 | /// \param ObjectType If we're translating a template name within a member |
| 409 | /// access expression, this is the type of the object whose member template |
| 410 | /// is being referenced. |
| 411 | /// |
| 412 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 413 | /// also refers to a name within the current (lexical) scope, this is the |
| 414 | /// declaration it refers to. |
| 415 | /// |
| 416 | /// By default, transforms the template name by transforming the declarations |
| 417 | /// and nested-name-specifiers that occur within the template name. |
| 418 | /// Subclasses may override this function to provide alternate behavior. |
| 419 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 420 | TemplateName Name, |
| 421 | SourceLocation NameLoc, |
| 422 | QualType ObjectType = QualType(), |
| 423 | NamedDecl *FirstQualifierInScope = 0); |
| 424 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | /// \brief Transform the given template argument. |
| 426 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | /// By default, this operation transforms the type, expression, or |
| 428 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 429 | /// new template argument from the transformed result. Subclasses may |
| 430 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 431 | /// |
| 432 | /// Returns true if there was an error. |
| 433 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 434 | TemplateArgumentLoc &Output); |
| 435 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 436 | /// \brief Transform the given set of template arguments. |
| 437 | /// |
| 438 | /// By default, this operation transforms all of the template arguments |
| 439 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 440 | /// the transformed arguments to the output list. |
| 441 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 442 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 443 | /// a convenience function. Subclasses that wish to override this behavior |
| 444 | /// should override the iterator-based member template version. |
| 445 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 446 | /// \param Inputs The set of template arguments to be transformed. |
| 447 | /// |
| 448 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 449 | /// |
| 450 | /// \param Outputs The set of transformed template arguments output by this |
| 451 | /// routine. |
| 452 | /// |
| 453 | /// Returns true if an error occurred. |
| 454 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 455 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 456 | TemplateArgumentListInfo &Outputs) { |
| 457 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 458 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 459 | |
| 460 | /// \brief Transform the given set of template arguments. |
| 461 | /// |
| 462 | /// By default, this operation transforms all of the template arguments |
| 463 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 464 | /// the transformed arguments to the output list. |
| 465 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 466 | /// \param First An iterator to the first template argument. |
| 467 | /// |
| 468 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 469 | /// |
| 470 | /// \param Outputs The set of transformed template arguments output by this |
| 471 | /// routine. |
| 472 | /// |
| 473 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 474 | template<typename InputIterator> |
| 475 | bool TransformTemplateArguments(InputIterator First, |
| 476 | InputIterator Last, |
| 477 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 478 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 479 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 480 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 481 | TemplateArgumentLoc &ArgLoc); |
| 482 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 483 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 484 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 485 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 486 | getDerived().getBaseLocation()); |
| 487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 489 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 490 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 491 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 492 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 494 | StmtResult |
| 495 | TransformSEHHandler(Stmt *Handler); |
| 496 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 497 | QualType |
| 498 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 499 | TemplateSpecializationTypeLoc TL, |
| 500 | TemplateName Template); |
| 501 | |
| 502 | QualType |
| 503 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 504 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 505 | TemplateName Template, |
| 506 | CXXScopeSpec &SS); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 507 | |
| 508 | QualType |
| 509 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 510 | DependentTemplateSpecializationTypeLoc TL, |
| 511 | NestedNameSpecifierLoc QualifierLoc); |
| 512 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 513 | /// \brief Transforms the parameters of a function type into the |
| 514 | /// given vectors. |
| 515 | /// |
| 516 | /// The result vectors should be kept in sync; null entries in the |
| 517 | /// variables vector are acceptable. |
| 518 | /// |
| 519 | /// Return true on error. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 520 | bool TransformFunctionTypeParams(SourceLocation Loc, |
| 521 | ParmVarDecl **Params, unsigned NumParams, |
| 522 | const QualType *ParamTypes, |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 523 | llvm::SmallVectorImpl<QualType> &PTypes, |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 524 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 525 | |
| 526 | /// \brief Transforms a single function-type parameter. Return null |
| 527 | /// on error. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 528 | /// |
| 529 | /// \param indexAdjustment - A number to add to the parameter's |
| 530 | /// scope index; can be negative |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 531 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 532 | int indexAdjustment, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 533 | llvm::Optional<unsigned> NumExpansions); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 534 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 535 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 536 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 537 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 538 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 540 | #define STMT(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 541 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 542 | #define EXPR(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 543 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 544 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 545 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 547 | /// \brief Build a new pointer type given its pointee type. |
| 548 | /// |
| 549 | /// By default, performs semantic analysis when building the pointer type. |
| 550 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 551 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 552 | |
| 553 | /// \brief Build a new block pointer type given its pointee type. |
| 554 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 556 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 557 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 558 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 559 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 561 | /// By default, performs semantic analysis when building the |
| 562 | /// reference type. Subclasses may override this routine to provide |
| 563 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 564 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 565 | /// \param LValue whether the type was written with an lvalue sigil |
| 566 | /// or an rvalue sigil. |
| 567 | QualType RebuildReferenceType(QualType ReferentType, |
| 568 | bool LValue, |
| 569 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 571 | /// \brief Build a new member pointer type given the pointee type and the |
| 572 | /// class type it refers into. |
| 573 | /// |
| 574 | /// By default, performs semantic analysis when building the member pointer |
| 575 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 576 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 577 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 579 | /// \brief Build a new array type given the element type, size |
| 580 | /// modifier, size of the array (if known), size expression, and index type |
| 581 | /// qualifiers. |
| 582 | /// |
| 583 | /// By default, performs semantic analysis when building the array type. |
| 584 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 586 | QualType RebuildArrayType(QualType ElementType, |
| 587 | ArrayType::ArraySizeModifier SizeMod, |
| 588 | const llvm::APInt *Size, |
| 589 | Expr *SizeExpr, |
| 590 | unsigned IndexTypeQuals, |
| 591 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 592 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 593 | /// \brief Build a new constant array type given the element type, size |
| 594 | /// modifier, (known) size of the array, and index type qualifiers. |
| 595 | /// |
| 596 | /// By default, performs semantic analysis when building the array type. |
| 597 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 599 | ArrayType::ArraySizeModifier SizeMod, |
| 600 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 601 | unsigned IndexTypeQuals, |
| 602 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 604 | /// \brief Build a new incomplete array type given the element type, size |
| 605 | /// modifier, and index type qualifiers. |
| 606 | /// |
| 607 | /// By default, performs semantic analysis when building the array type. |
| 608 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 610 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 611 | unsigned IndexTypeQuals, |
| 612 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 613 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 614 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 615 | /// size modifier, size expression, and index type qualifiers. |
| 616 | /// |
| 617 | /// By default, performs semantic analysis when building the array type. |
| 618 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 620 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 621 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 622 | unsigned IndexTypeQuals, |
| 623 | SourceRange BracketsRange); |
| 624 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 626 | /// size modifier, size expression, and index type qualifiers. |
| 627 | /// |
| 628 | /// By default, performs semantic analysis when building the array type. |
| 629 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 631 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 632 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 633 | unsigned IndexTypeQuals, |
| 634 | SourceRange BracketsRange); |
| 635 | |
| 636 | /// \brief Build a new vector type given the element type and |
| 637 | /// number of elements. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the vector type. |
| 640 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 641 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 642 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 644 | /// \brief Build a new extended vector type given the element type and |
| 645 | /// number of elements. |
| 646 | /// |
| 647 | /// By default, performs semantic analysis when building the vector type. |
| 648 | /// Subclasses may override this routine to provide different behavior. |
| 649 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 650 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | |
| 652 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 653 | /// given the element type and number of elements. |
| 654 | /// |
| 655 | /// By default, performs semantic analysis when building the vector type. |
| 656 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 658 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 659 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 661 | /// \brief Build a new function type. |
| 662 | /// |
| 663 | /// By default, performs semantic analysis when building the function type. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
| 665 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 667 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 668 | bool Variadic, unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 669 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 670 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 672 | /// \brief Build a new unprototyped function type. |
| 673 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 674 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 675 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 676 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 677 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 678 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 679 | /// \brief Build a new typedef type. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 680 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 681 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 682 | } |
| 683 | |
| 684 | /// \brief Build a new class/struct/union type. |
| 685 | QualType RebuildRecordType(RecordDecl *Record) { |
| 686 | return SemaRef.Context.getTypeDeclType(Record); |
| 687 | } |
| 688 | |
| 689 | /// \brief Build a new Enum type. |
| 690 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 691 | return SemaRef.Context.getTypeDeclType(Enum); |
| 692 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 693 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | /// |
| 696 | /// By default, performs semantic analysis when building the typeof type. |
| 697 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 698 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 699 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 701 | /// |
| 702 | /// By default, builds a new TypeOfType with the given underlying type. |
| 703 | QualType RebuildTypeOfType(QualType Underlying); |
| 704 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 706 | /// |
| 707 | /// By default, performs semantic analysis when building the decltype type. |
| 708 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 709 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 711 | /// \brief Build a new C++0x auto type. |
| 712 | /// |
| 713 | /// By default, builds a new AutoType with the given deduced type. |
| 714 | QualType RebuildAutoType(QualType Deduced) { |
| 715 | return SemaRef.Context.getAutoType(Deduced); |
| 716 | } |
| 717 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 718 | /// \brief Build a new template specialization type. |
| 719 | /// |
| 720 | /// By default, performs semantic analysis when building the template |
| 721 | /// specialization type. Subclasses may override this routine to provide |
| 722 | /// different behavior. |
| 723 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 724 | SourceLocation TemplateLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 725 | TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 727 | /// \brief Build a new parenthesized type. |
| 728 | /// |
| 729 | /// By default, builds a new ParenType type from the inner type. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
| 731 | QualType RebuildParenType(QualType InnerType) { |
| 732 | return SemaRef.Context.getParenType(InnerType); |
| 733 | } |
| 734 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 735 | /// \brief Build a new qualified name type. |
| 736 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 737 | /// By default, builds a new ElaboratedType type from the keyword, |
| 738 | /// the nested-name-specifier and the named type. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 740 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 741 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 742 | NestedNameSpecifierLoc QualifierLoc, |
| 743 | QualType Named) { |
| 744 | return SemaRef.Context.getElaboratedType(Keyword, |
| 745 | QualifierLoc.getNestedNameSpecifier(), |
| 746 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 748 | |
| 749 | /// \brief Build a new typename type that refers to a template-id. |
| 750 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 751 | /// By default, builds a new DependentNameType type from the |
| 752 | /// nested-name-specifier and the given type. Subclasses may override |
| 753 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 754 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 755 | ElaboratedTypeKeyword Keyword, |
| 756 | NestedNameSpecifierLoc QualifierLoc, |
| 757 | const IdentifierInfo *Name, |
| 758 | SourceLocation NameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 759 | TemplateArgumentListInfo &Args) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 760 | // Rebuild the template name. |
| 761 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 762 | CXXScopeSpec SS; |
| 763 | SS.Adopt(QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 764 | TemplateName InstName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 765 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 766 | |
| 767 | if (InstName.isNull()) |
| 768 | return QualType(); |
| 769 | |
| 770 | // If it's still dependent, make a dependent specialization. |
| 771 | if (InstName.getAsDependentTemplateName()) |
| 772 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 773 | QualifierLoc.getNestedNameSpecifier(), |
| 774 | Name, |
| 775 | Args); |
| 776 | |
| 777 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 778 | // specialization. |
| 779 | QualType T = |
| 780 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 781 | if (T.isNull()) return QualType(); |
| 782 | |
| 783 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 784 | return T; |
| 785 | |
| 786 | return SemaRef.Context.getElaboratedType(Keyword, |
| 787 | QualifierLoc.getNestedNameSpecifier(), |
| 788 | T); |
| 789 | } |
| 790 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 791 | /// \brief Build a new typename type that refers to an identifier. |
| 792 | /// |
| 793 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 794 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 795 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 796 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 797 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 798 | NestedNameSpecifierLoc QualifierLoc, |
| 799 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 800 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 801 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 802 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 803 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 804 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 805 | // If the name is still dependent, just build a new dependent name type. |
| 806 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 807 | return SemaRef.Context.getDependentNameType(Keyword, |
| 808 | QualifierLoc.getNestedNameSpecifier(), |
| 809 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 812 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 813 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 814 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 815 | |
| 816 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 817 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 818 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 819 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 820 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 821 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 822 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 823 | if (!DC) |
| 824 | return QualType(); |
| 825 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 826 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 827 | return QualType(); |
| 828 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 829 | TagDecl *Tag = 0; |
| 830 | SemaRef.LookupQualifiedName(Result, DC); |
| 831 | switch (Result.getResultKind()) { |
| 832 | case LookupResult::NotFound: |
| 833 | case LookupResult::NotFoundInCurrentInstantiation: |
| 834 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 835 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 836 | case LookupResult::Found: |
| 837 | Tag = Result.getAsSingle<TagDecl>(); |
| 838 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 839 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 840 | case LookupResult::FoundOverloaded: |
| 841 | case LookupResult::FoundUnresolvedValue: |
| 842 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 843 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 844 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 845 | case LookupResult::Ambiguous: |
| 846 | // Let the LookupResult structure handle ambiguities. |
| 847 | return QualType(); |
| 848 | } |
| 849 | |
| 850 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 851 | // Check where the name exists but isn't a tag type and use that to emit |
| 852 | // better diagnostics. |
| 853 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 854 | SemaRef.LookupQualifiedName(Result, DC); |
| 855 | switch (Result.getResultKind()) { |
| 856 | case LookupResult::Found: |
| 857 | case LookupResult::FoundOverloaded: |
| 858 | case LookupResult::FoundUnresolvedValue: { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 859 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 860 | unsigned Kind = 0; |
| 861 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 862 | else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; |
| 863 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 864 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 865 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 866 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 867 | } |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 868 | default: |
| 869 | // FIXME: Would be nice to highlight just the source range. |
| 870 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 871 | << Kind << Id << DC; |
| 872 | break; |
| 873 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 874 | return QualType(); |
| 875 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 876 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 877 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 878 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 879 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 880 | return QualType(); |
| 881 | } |
| 882 | |
| 883 | // Build the elaborated-type-specifier type. |
| 884 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 885 | return SemaRef.Context.getElaboratedType(Keyword, |
| 886 | QualifierLoc.getNestedNameSpecifier(), |
| 887 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 888 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 889 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 890 | /// \brief Build a new pack expansion type. |
| 891 | /// |
| 892 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 893 | /// Subclasses may override this routine to provide different behavior. |
| 894 | QualType RebuildPackExpansionType(QualType Pattern, |
| 895 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 896 | SourceLocation EllipsisLoc, |
| 897 | llvm::Optional<unsigned> NumExpansions) { |
| 898 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 899 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 902 | /// \brief Build a new template name given a nested name specifier, a flag |
| 903 | /// indicating whether the "template" keyword was provided, and the template |
| 904 | /// that the template name refers to. |
| 905 | /// |
| 906 | /// By default, builds the new template name directly. Subclasses may override |
| 907 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 908 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 909 | bool TemplateKW, |
| 910 | TemplateDecl *Template); |
| 911 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 912 | /// \brief Build a new template name given a nested name specifier and the |
| 913 | /// name that is referred to as a template. |
| 914 | /// |
| 915 | /// By default, performs semantic analysis to determine whether the name can |
| 916 | /// be resolved to a specific template, then builds the appropriate kind of |
| 917 | /// template name. Subclasses may override this routine to provide different |
| 918 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 919 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 920 | const IdentifierInfo &Name, |
| 921 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 922 | QualType ObjectType, |
| 923 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 925 | /// \brief Build a new template name given a nested name specifier and the |
| 926 | /// overloaded operator name that is referred to as a template. |
| 927 | /// |
| 928 | /// By default, performs semantic analysis to determine whether the name can |
| 929 | /// be resolved to a specific template, then builds the appropriate kind of |
| 930 | /// template name. Subclasses may override this routine to provide different |
| 931 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 932 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 933 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 934 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 935 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 936 | |
| 937 | /// \brief Build a new template name given a template template parameter pack |
| 938 | /// and the |
| 939 | /// |
| 940 | /// By default, performs semantic analysis to determine whether the name can |
| 941 | /// be resolved to a specific template, then builds the appropriate kind of |
| 942 | /// template name. Subclasses may override this routine to provide different |
| 943 | /// behavior. |
| 944 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 945 | const TemplateArgument &ArgPack) { |
| 946 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 947 | } |
| 948 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 949 | /// \brief Build a new compound statement. |
| 950 | /// |
| 951 | /// By default, performs semantic analysis to build the new statement. |
| 952 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 953 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 954 | MultiStmtArg Statements, |
| 955 | SourceLocation RBraceLoc, |
| 956 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 957 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 958 | IsStmtExpr); |
| 959 | } |
| 960 | |
| 961 | /// \brief Build a new case statement. |
| 962 | /// |
| 963 | /// By default, performs semantic analysis to build the new statement. |
| 964 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 965 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 966 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 967 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 968 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 969 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 970 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 971 | ColonLoc); |
| 972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 974 | /// \brief Attach the body to a new case statement. |
| 975 | /// |
| 976 | /// By default, performs semantic analysis to build the new statement. |
| 977 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 978 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 979 | getSema().ActOnCaseStmtBody(S, Body); |
| 980 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 981 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 983 | /// \brief Build a new default statement. |
| 984 | /// |
| 985 | /// By default, performs semantic analysis to build the new statement. |
| 986 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 987 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 988 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 989 | Stmt *SubStmt) { |
| 990 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 991 | /*CurScope=*/0); |
| 992 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 993 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 994 | /// \brief Build a new label statement. |
| 995 | /// |
| 996 | /// By default, performs semantic analysis to build the new statement. |
| 997 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 998 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 999 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1000 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1003 | /// \brief Build a new "if" statement. |
| 1004 | /// |
| 1005 | /// By default, performs semantic analysis to build the new statement. |
| 1006 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1007 | StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1008 | VarDecl *CondVar, Stmt *Then, |
| 1009 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1010 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1011 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1012 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1013 | /// \brief Start building a new switch statement. |
| 1014 | /// |
| 1015 | /// By default, performs semantic analysis to build the new statement. |
| 1016 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1017 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1018 | Expr *Cond, VarDecl *CondVar) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1019 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1020 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1022 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1023 | /// \brief Attach the body to the switch statement. |
| 1024 | /// |
| 1025 | /// By default, performs semantic analysis to build the new statement. |
| 1026 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1027 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1028 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1029 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /// \brief Build a new while statement. |
| 1033 | /// |
| 1034 | /// By default, performs semantic analysis to build the new statement. |
| 1035 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1036 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1037 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1038 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
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 Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1046 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1047 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1048 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1049 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | /// \brief Build a new for statement. |
| 1053 | /// |
| 1054 | /// By default, performs semantic analysis to build the new statement. |
| 1055 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1056 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1057 | Stmt *Init, Sema::FullExprArg Cond, |
| 1058 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1059 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1060 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1061 | CondVar, Inc, RParenLoc, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1064 | /// \brief Build a new goto statement. |
| 1065 | /// |
| 1066 | /// By default, performs semantic analysis to build the new statement. |
| 1067 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1068 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1069 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1070 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | /// \brief Build a new indirect goto statement. |
| 1074 | /// |
| 1075 | /// By default, performs semantic analysis to build the new statement. |
| 1076 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1077 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1078 | SourceLocation StarLoc, |
| 1079 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1080 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1081 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1083 | /// \brief Build a new return statement. |
| 1084 | /// |
| 1085 | /// By default, performs semantic analysis to build the new statement. |
| 1086 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1087 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1088 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1091 | /// \brief Build a new declaration 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 RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1097 | SourceLocation EndLoc) { |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1098 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1099 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1100 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1102 | /// \brief Build a new inline asm statement. |
| 1103 | /// |
| 1104 | /// By default, performs semantic analysis to build the new statement. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1106 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1107 | bool IsSimple, |
| 1108 | bool IsVolatile, |
| 1109 | unsigned NumOutputs, |
| 1110 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1111 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1112 | MultiExprArg Constraints, |
| 1113 | MultiExprArg Exprs, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1114 | Expr *AsmString, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1115 | MultiExprArg Clobbers, |
| 1116 | SourceLocation RParenLoc, |
| 1117 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1118 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1119 | NumInputs, Names, move(Constraints), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1120 | Exprs, AsmString, Clobbers, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1121 | RParenLoc, MSAsm); |
| 1122 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1123 | |
| 1124 | /// \brief Build a new Objective-C @try statement. |
| 1125 | /// |
| 1126 | /// By default, performs semantic analysis to build the new statement. |
| 1127 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1128 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1129 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1130 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1131 | Stmt *Finally) { |
| 1132 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1133 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1136 | /// \brief Rebuild an Objective-C exception declaration. |
| 1137 | /// |
| 1138 | /// By default, performs semantic analysis to build the new declaration. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
| 1140 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1141 | TypeSourceInfo *TInfo, QualType T) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1142 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1143 | ExceptionDecl->getInnerLocStart(), |
| 1144 | ExceptionDecl->getLocation(), |
| 1145 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1146 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1148 | /// \brief Build a new Objective-C @catch statement. |
| 1149 | /// |
| 1150 | /// By default, performs semantic analysis to build the new statement. |
| 1151 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1152 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1153 | SourceLocation RParenLoc, |
| 1154 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1155 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1156 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1157 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1158 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1159 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1160 | /// \brief Build a new Objective-C @finally statement. |
| 1161 | /// |
| 1162 | /// By default, performs semantic analysis to build the new statement. |
| 1163 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1164 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1165 | Stmt *Body) { |
| 1166 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1167 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1168 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1169 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1170 | /// |
| 1171 | /// By default, performs semantic analysis to build the new statement. |
| 1172 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1173 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1174 | Expr *Operand) { |
| 1175 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1176 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1177 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1178 | /// \brief Build a new Objective-C @synchronized statement. |
| 1179 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1180 | /// By default, performs semantic analysis to build the new statement. |
| 1181 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1182 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1183 | Expr *Object, |
| 1184 | Stmt *Body) { |
| 1185 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, |
| 1186 | Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1187 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1188 | |
| 1189 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1190 | /// |
| 1191 | /// By default, performs semantic analysis to build the new statement. |
| 1192 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1193 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1194 | SourceLocation LParenLoc, |
| 1195 | Stmt *Element, |
| 1196 | Expr *Collection, |
| 1197 | SourceLocation RParenLoc, |
| 1198 | Stmt *Body) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1199 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1200 | Element, |
| 1201 | Collection, |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1202 | RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1203 | Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1204 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1206 | /// \brief Build a new C++ exception declaration. |
| 1207 | /// |
| 1208 | /// By default, performs semantic analysis to build the new decaration. |
| 1209 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1210 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1211 | TypeSourceInfo *Declarator, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1212 | SourceLocation StartLoc, |
| 1213 | SourceLocation IdLoc, |
| 1214 | IdentifierInfo *Id) { |
Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1215 | VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, |
| 1216 | StartLoc, IdLoc, Id); |
| 1217 | if (Var) |
| 1218 | getSema().CurContext->addDecl(Var); |
| 1219 | return Var; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /// \brief Build a new C++ catch statement. |
| 1223 | /// |
| 1224 | /// By default, performs semantic analysis to build the new statement. |
| 1225 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1226 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1227 | VarDecl *ExceptionDecl, |
| 1228 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1229 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1230 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1233 | /// \brief Build a new C++ try statement. |
| 1234 | /// |
| 1235 | /// By default, performs semantic analysis to build the new statement. |
| 1236 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1237 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1238 | Stmt *TryBlock, |
| 1239 | MultiStmtArg Handlers) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1240 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1241 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1243 | /// \brief Build a new C++0x range-based for statement. |
| 1244 | /// |
| 1245 | /// By default, performs semantic analysis to build the new statement. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
| 1247 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 1248 | SourceLocation ColonLoc, |
| 1249 | Stmt *Range, Stmt *BeginEnd, |
| 1250 | Expr *Cond, Expr *Inc, |
| 1251 | Stmt *LoopVar, |
| 1252 | SourceLocation RParenLoc) { |
| 1253 | return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, |
| 1254 | Cond, Inc, LoopVar, RParenLoc); |
| 1255 | } |
| 1256 | |
| 1257 | /// \brief Attach body to a C++0x range-based for statement. |
| 1258 | /// |
| 1259 | /// By default, performs semantic analysis to finish the new statement. |
| 1260 | /// Subclasses may override this routine to provide different behavior. |
| 1261 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 1262 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 1263 | } |
| 1264 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1265 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, |
| 1266 | SourceLocation TryLoc, |
| 1267 | Stmt *TryBlock, |
| 1268 | Stmt *Handler) { |
| 1269 | return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1270 | } |
| 1271 | |
| 1272 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, |
| 1273 | Expr *FilterExpr, |
| 1274 | Stmt *Block) { |
| 1275 | return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); |
| 1276 | } |
| 1277 | |
| 1278 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, |
| 1279 | Stmt *Block) { |
| 1280 | return getSema().ActOnSEHFinallyBlock(Loc,Block); |
| 1281 | } |
| 1282 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1283 | /// \brief Build a new expression that references a declaration. |
| 1284 | /// |
| 1285 | /// By default, performs semantic analysis to build the new expression. |
| 1286 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1287 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1288 | LookupResult &R, |
| 1289 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1290 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1291 | } |
| 1292 | |
| 1293 | |
| 1294 | /// \brief Build a new expression that references a declaration. |
| 1295 | /// |
| 1296 | /// By default, performs semantic analysis to build the new expression. |
| 1297 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1298 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1299 | ValueDecl *VD, |
| 1300 | const DeclarationNameInfo &NameInfo, |
| 1301 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1302 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1303 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1304 | |
| 1305 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1306 | |
| 1307 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | /// By default, performs semantic analysis to build the new expression. |
| 1313 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1314 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1316 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1319 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1321 | /// By default, performs semantic analysis to build the new expression. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1323 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1324 | SourceLocation OperatorLoc, |
| 1325 | bool isArrow, |
| 1326 | CXXScopeSpec &SS, |
| 1327 | TypeSourceInfo *ScopeType, |
| 1328 | SourceLocation CCLoc, |
| 1329 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1330 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// By default, performs semantic analysis to build the new expression. |
| 1335 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1336 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1337 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1338 | Expr *SubExpr) { |
| 1339 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1342 | /// \brief Build a new builtin offsetof expression. |
| 1343 | /// |
| 1344 | /// By default, performs semantic analysis to build the new expression. |
| 1345 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1346 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1347 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1348 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1349 | unsigned NumComponents, |
| 1350 | SourceLocation RParenLoc) { |
| 1351 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1352 | NumComponents, RParenLoc); |
| 1353 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1354 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1355 | /// \brief Build a new sizeof, alignof or vec_step expression with a |
| 1356 | /// type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | /// By default, performs semantic analysis to build the new expression. |
| 1359 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1360 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 1361 | SourceLocation OpLoc, |
| 1362 | UnaryExprOrTypeTrait ExprKind, |
| 1363 | SourceRange R) { |
| 1364 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1367 | /// \brief Build a new sizeof, alignof or vec step expression with an |
| 1368 | /// expression argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1370 | /// By default, performs semantic analysis to build the new expression. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1372 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 1373 | UnaryExprOrTypeTrait ExprKind, |
| 1374 | SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1375 | ExprResult Result |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1376 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1377 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1378 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | return move(Result); |
| 1381 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1384 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1385 | /// By default, performs semantic analysis to build the new expression. |
| 1386 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1387 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1388 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1389 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1390 | SourceLocation RBracketLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1391 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1392 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1393 | RBracketLoc); |
| 1394 | } |
| 1395 | |
| 1396 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1398 | /// By default, performs semantic analysis to build the new expression. |
| 1399 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1400 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1401 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1402 | SourceLocation RParenLoc, |
| 1403 | Expr *ExecConfig = 0) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1404 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1405 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | /// By default, performs semantic analysis to build the new expression. |
| 1411 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1412 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1413 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1414 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1415 | const DeclarationNameInfo &MemberNameInfo, |
| 1416 | ValueDecl *Member, |
| 1417 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1418 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1419 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1420 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1421 | // We have a reference to an unnamed field. This is always the |
| 1422 | // base of an anonymous struct/union member access, i.e. the |
| 1423 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1424 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1425 | assert(Member->getType()->isRecordType() && |
| 1426 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1428 | ExprResult BaseResult = |
| 1429 | getSema().PerformObjectMemberConversion(Base, |
| 1430 | QualifierLoc.getNestedNameSpecifier(), |
| 1431 | FoundDecl, Member); |
| 1432 | if (BaseResult.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1433 | return ExprError(); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1434 | Base = BaseResult.take(); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1435 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1436 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1437 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1438 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1439 | cast<FieldDecl>(Member)->getType(), |
| 1440 | VK, OK_Ordinary); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1441 | return getSema().Owned(ME); |
| 1442 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1444 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1445 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1446 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 1447 | ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base); |
| 1448 | if (BaseResult.isInvalid()) |
| 1449 | return ExprError(); |
| 1450 | Base = BaseResult.take(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1451 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1452 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1453 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1454 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1455 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1456 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1457 | R.resolveKind(); |
| 1458 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1459 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1460 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1461 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1463 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1464 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1465 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | /// By default, performs semantic analysis to build the new expression. |
| 1467 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1468 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1469 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1470 | Expr *LHS, Expr *RHS) { |
| 1471 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1475 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1476 | /// By default, performs semantic analysis to build the new expression. |
| 1477 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1478 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1479 | SourceLocation QuestionLoc, |
| 1480 | Expr *LHS, |
| 1481 | SourceLocation ColonLoc, |
| 1482 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1483 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1484 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1488 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | /// By default, performs semantic analysis to build the new expression. |
| 1490 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1491 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1492 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1494 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1495 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1496 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1499 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1500 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | /// By default, performs semantic analysis to build the new expression. |
| 1502 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1503 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1504 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1505 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1506 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1507 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1508 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1509 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | /// \brief Build a new extended vector element access expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1514 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1515 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | SourceLocation OpLoc, |
| 1517 | SourceLocation AccessorLoc, |
| 1518 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1519 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1520 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1521 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1522 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1523 | OpLoc, /*IsArrow*/ false, |
| 1524 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1525 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1526 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1529 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1530 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | /// By default, performs semantic analysis to build the new expression. |
| 1532 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1533 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1535 | SourceLocation RBraceLoc, |
| 1536 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1537 | ExprResult Result |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1538 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1539 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1540 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1541 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1542 | // Patch in the result type we were given, which may have been computed |
| 1543 | // when the initial InitListExpr was built. |
| 1544 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1545 | ILE->setType(ResultTy); |
| 1546 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1551 | /// By default, performs semantic analysis to build the new expression. |
| 1552 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1553 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1554 | MultiExprArg ArrayExprs, |
| 1555 | SourceLocation EqualOrColonLoc, |
| 1556 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1557 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1558 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1560 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1562 | return ExprError(); |
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 | ArrayExprs.release(); |
| 1565 | return move(Result); |
| 1566 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1567 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1569 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1570 | /// By default, builds the implicit value initialization without performing |
| 1571 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1572 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1573 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1576 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1577 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | /// By default, performs semantic analysis to build the new expression. |
| 1580 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1581 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1582 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1583 | SourceLocation RParenLoc) { |
| 1584 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1585 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1586 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1590 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | /// By default, performs semantic analysis to build the new expression. |
| 1592 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1593 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | MultiExprArg SubExprs, |
| 1595 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1596 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1597 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1598 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | /// |
| 1602 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | /// rather than attempting to map the label statement itself. |
| 1604 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1605 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1606 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1607 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | /// By default, performs semantic analysis to build the new expression. |
| 1613 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1614 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1615 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1617 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1618 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1619 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1620 | /// \brief Build a new __builtin_choose_expr expression. |
| 1621 | /// |
| 1622 | /// By default, performs semantic analysis to build the new expression. |
| 1623 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1624 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1625 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | SourceLocation RParenLoc) { |
| 1627 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1628 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1629 | RParenLoc); |
| 1630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1631 | |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1632 | /// \brief Build a new generic selection expression. |
| 1633 | /// |
| 1634 | /// By default, performs semantic analysis to build the new expression. |
| 1635 | /// Subclasses may override this routine to provide different behavior. |
| 1636 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 1637 | SourceLocation DefaultLoc, |
| 1638 | SourceLocation RParenLoc, |
| 1639 | Expr *ControllingExpr, |
| 1640 | TypeSourceInfo **Types, |
| 1641 | Expr **Exprs, |
| 1642 | unsigned NumAssocs) { |
| 1643 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 1644 | ControllingExpr, Types, Exprs, |
| 1645 | NumAssocs); |
| 1646 | } |
| 1647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | /// \brief Build a new overloaded operator call expression. |
| 1649 | /// |
| 1650 | /// By default, performs semantic analysis to build the new expression. |
| 1651 | /// The semantic analysis provides the behavior of template instantiation, |
| 1652 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1655 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1656 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1657 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1658 | Expr *Callee, |
| 1659 | Expr *First, |
| 1660 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1661 | |
| 1662 | /// \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] | 1663 | /// reinterpret_cast. |
| 1664 | /// |
| 1665 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1667 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1668 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | Stmt::StmtClass Class, |
| 1670 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1671 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1672 | SourceLocation RAngleLoc, |
| 1673 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1674 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | SourceLocation RParenLoc) { |
| 1676 | switch (Class) { |
| 1677 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1678 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1680 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | |
| 1682 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1683 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1685 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1686 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1688 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1690 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1694 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1696 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | default: |
| 1699 | assert(false && "Invalid C++ named cast"); |
| 1700 | break; |
| 1701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1703 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1705 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1706 | /// \brief Build a new C++ static_cast expression. |
| 1707 | /// |
| 1708 | /// By default, performs semantic analysis to build the new expression. |
| 1709 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1710 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1711 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1712 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1713 | SourceLocation RAngleLoc, |
| 1714 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1715 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1716 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1717 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1718 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1719 | SourceRange(LAngleLoc, RAngleLoc), |
| 1720 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /// \brief Build a new C++ dynamic_cast expression. |
| 1724 | /// |
| 1725 | /// By default, performs semantic analysis to build the new expression. |
| 1726 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1727 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1729 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | SourceLocation RAngleLoc, |
| 1731 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1732 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1733 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1734 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1735 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1736 | SourceRange(LAngleLoc, RAngleLoc), |
| 1737 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1741 | /// |
| 1742 | /// By default, performs semantic analysis to build the new expression. |
| 1743 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1744 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1745 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1746 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1747 | SourceLocation RAngleLoc, |
| 1748 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1749 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1750 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1751 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1752 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1753 | SourceRange(LAngleLoc, RAngleLoc), |
| 1754 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | /// \brief Build a new C++ const_cast expression. |
| 1758 | /// |
| 1759 | /// By default, performs semantic analysis to build the new expression. |
| 1760 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1761 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1762 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1763 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | SourceLocation RAngleLoc, |
| 1765 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1766 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1768 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1769 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1770 | SourceRange(LAngleLoc, RAngleLoc), |
| 1771 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1772 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1774 | /// \brief Build a new C++ functional-style cast expression. |
| 1775 | /// |
| 1776 | /// By default, performs semantic analysis to build the new expression. |
| 1777 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1778 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1779 | SourceLocation LParenLoc, |
| 1780 | Expr *Sub, |
| 1781 | SourceLocation RParenLoc) { |
| 1782 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1783 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1784 | RParenLoc); |
| 1785 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1787 | /// \brief Build a new C++ typeid(type) expression. |
| 1788 | /// |
| 1789 | /// By default, performs semantic analysis to build the new expression. |
| 1790 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1791 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1792 | SourceLocation TypeidLoc, |
| 1793 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1794 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1795 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1796 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1799 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1800 | /// \brief Build a new C++ typeid(expr) expression. |
| 1801 | /// |
| 1802 | /// By default, performs semantic analysis to build the new expression. |
| 1803 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1804 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1805 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1806 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1807 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1808 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1809 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1812 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1813 | /// |
| 1814 | /// By default, performs semantic analysis to build the new expression. |
| 1815 | /// Subclasses may override this routine to provide different behavior. |
| 1816 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1817 | SourceLocation TypeidLoc, |
| 1818 | TypeSourceInfo *Operand, |
| 1819 | SourceLocation RParenLoc) { |
| 1820 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1821 | RParenLoc); |
| 1822 | } |
| 1823 | |
| 1824 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1825 | /// |
| 1826 | /// By default, performs semantic analysis to build the new expression. |
| 1827 | /// Subclasses may override this routine to provide different behavior. |
| 1828 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1829 | SourceLocation TypeidLoc, |
| 1830 | Expr *Operand, |
| 1831 | SourceLocation RParenLoc) { |
| 1832 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1833 | RParenLoc); |
| 1834 | } |
| 1835 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1836 | /// \brief Build a new C++ "this" expression. |
| 1837 | /// |
| 1838 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1840 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1841 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1842 | QualType ThisType, |
| 1843 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1844 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1845 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1846 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | /// \brief Build a new C++ throw expression. |
| 1850 | /// |
| 1851 | /// By default, performs semantic analysis to build the new expression. |
| 1852 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1853 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1854 | return getSema().ActOnCXXThrow(ThrowLoc, Sub); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | /// \brief Build a new C++ default-argument expression. |
| 1858 | /// |
| 1859 | /// By default, builds a new default-argument expression, which does not |
| 1860 | /// require any semantic analysis. Subclasses may override this routine to |
| 1861 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1862 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1863 | ParmVarDecl *Param) { |
| 1864 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1865 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | /// \brief Build a new C++ zero-initialization expression. |
| 1869 | /// |
| 1870 | /// By default, performs semantic analysis to build the new expression. |
| 1871 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1872 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1873 | SourceLocation LParenLoc, |
| 1874 | SourceLocation RParenLoc) { |
| 1875 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1877 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1878 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1880 | /// \brief Build a new C++ "new" expression. |
| 1881 | /// |
| 1882 | /// By default, performs semantic analysis to build the new expression. |
| 1883 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1884 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1885 | bool UseGlobal, |
| 1886 | SourceLocation PlacementLParen, |
| 1887 | MultiExprArg PlacementArgs, |
| 1888 | SourceLocation PlacementRParen, |
| 1889 | SourceRange TypeIdParens, |
| 1890 | QualType AllocatedType, |
| 1891 | TypeSourceInfo *AllocatedTypeInfo, |
| 1892 | Expr *ArraySize, |
| 1893 | SourceLocation ConstructorLParen, |
| 1894 | MultiExprArg ConstructorArgs, |
| 1895 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1896 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1897 | PlacementLParen, |
| 1898 | move(PlacementArgs), |
| 1899 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1900 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1901 | AllocatedType, |
| 1902 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1903 | ArraySize, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1904 | ConstructorLParen, |
| 1905 | move(ConstructorArgs), |
| 1906 | ConstructorRParen); |
| 1907 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1909 | /// \brief Build a new C++ "delete" expression. |
| 1910 | /// |
| 1911 | /// By default, performs semantic analysis to build the new expression. |
| 1912 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1913 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1914 | bool IsGlobalDelete, |
| 1915 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1916 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1917 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1918 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1920 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | /// \brief Build a new unary type trait expression. |
| 1922 | /// |
| 1923 | /// By default, performs semantic analysis to build the new expression. |
| 1924 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1925 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1926 | SourceLocation StartLoc, |
| 1927 | TypeSourceInfo *T, |
| 1928 | SourceLocation RParenLoc) { |
| 1929 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1932 | /// \brief Build a new binary type trait expression. |
| 1933 | /// |
| 1934 | /// By default, performs semantic analysis to build the new expression. |
| 1935 | /// Subclasses may override this routine to provide different behavior. |
| 1936 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1937 | SourceLocation StartLoc, |
| 1938 | TypeSourceInfo *LhsT, |
| 1939 | TypeSourceInfo *RhsT, |
| 1940 | SourceLocation RParenLoc) { |
| 1941 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1942 | } |
| 1943 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 1944 | /// \brief Build a new array type trait expression. |
| 1945 | /// |
| 1946 | /// By default, performs semantic analysis to build the new expression. |
| 1947 | /// Subclasses may override this routine to provide different behavior. |
| 1948 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 1949 | SourceLocation StartLoc, |
| 1950 | TypeSourceInfo *TSInfo, |
| 1951 | Expr *DimExpr, |
| 1952 | SourceLocation RParenLoc) { |
| 1953 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 1954 | } |
| 1955 | |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 1956 | /// \brief Build a new expression trait expression. |
| 1957 | /// |
| 1958 | /// By default, performs semantic analysis to build the new expression. |
| 1959 | /// Subclasses may override this routine to provide different behavior. |
| 1960 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 1961 | SourceLocation StartLoc, |
| 1962 | Expr *Queried, |
| 1963 | SourceLocation RParenLoc) { |
| 1964 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 1965 | } |
| 1966 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1967 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1968 | /// expression. |
| 1969 | /// |
| 1970 | /// By default, performs semantic analysis to build the new expression. |
| 1971 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1972 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 1973 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1974 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1975 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1976 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1977 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1978 | |
| 1979 | if (TemplateArgs) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1980 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1981 | *TemplateArgs); |
| 1982 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1983 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | /// \brief Build a new template-id expression. |
| 1987 | /// |
| 1988 | /// By default, performs semantic analysis to build the new expression. |
| 1989 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1990 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1991 | LookupResult &R, |
| 1992 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1993 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1994 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | /// \brief Build a new object-construction expression. |
| 1998 | /// |
| 1999 | /// By default, performs semantic analysis to build the new expression. |
| 2000 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2001 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2002 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2003 | CXXConstructorDecl *Constructor, |
| 2004 | bool IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 2005 | MultiExprArg Args, |
| 2006 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2007 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 2008 | SourceRange ParenRange) { |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 2009 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2010 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2011 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2012 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2013 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2014 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 2015 | move_arg(ConvertedArgs), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2016 | RequiresZeroInit, ConstructKind, |
| 2017 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | /// \brief Build a new object-construction expression. |
| 2021 | /// |
| 2022 | /// By default, performs semantic analysis to build the new expression. |
| 2023 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2024 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 2025 | SourceLocation LParenLoc, |
| 2026 | MultiExprArg Args, |
| 2027 | SourceLocation RParenLoc) { |
| 2028 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2029 | LParenLoc, |
| 2030 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2031 | RParenLoc); |
| 2032 | } |
| 2033 | |
| 2034 | /// \brief Build a new object-construction expression. |
| 2035 | /// |
| 2036 | /// By default, performs semantic analysis to build the new expression. |
| 2037 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2038 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2039 | SourceLocation LParenLoc, |
| 2040 | MultiExprArg Args, |
| 2041 | SourceLocation RParenLoc) { |
| 2042 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2043 | LParenLoc, |
| 2044 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2045 | RParenLoc); |
| 2046 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2048 | /// \brief Build a new member reference expression. |
| 2049 | /// |
| 2050 | /// By default, performs semantic analysis to build the new expression. |
| 2051 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2052 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2053 | QualType BaseType, |
| 2054 | bool IsArrow, |
| 2055 | SourceLocation OperatorLoc, |
| 2056 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2057 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2058 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2059 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2060 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2061 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2063 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2064 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2065 | SS, FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2066 | MemberNameInfo, |
| 2067 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2070 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2071 | /// |
| 2072 | /// By default, performs semantic analysis to build the new expression. |
| 2073 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2074 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2075 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2076 | SourceLocation OperatorLoc, |
| 2077 | bool IsArrow, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2078 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2079 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2080 | LookupResult &R, |
| 2081 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2082 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2083 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2084 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2085 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2086 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2087 | SS, FirstQualifierInScope, |
| 2088 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2090 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2091 | /// \brief Build a new noexcept expression. |
| 2092 | /// |
| 2093 | /// By default, performs semantic analysis to build the new expression. |
| 2094 | /// Subclasses may override this routine to provide different behavior. |
| 2095 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2096 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2097 | } |
| 2098 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2099 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2100 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2101 | SourceLocation PackLoc, |
| 2102 | SourceLocation RParenLoc, |
| 2103 | unsigned Length) { |
| 2104 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2105 | OperatorLoc, Pack, PackLoc, |
| 2106 | RParenLoc, Length); |
| 2107 | } |
| 2108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2109 | /// \brief Build a new Objective-C @encode expression. |
| 2110 | /// |
| 2111 | /// By default, performs semantic analysis to build the new expression. |
| 2112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2113 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2114 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2115 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2116 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2117 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2118 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2119 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2120 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2121 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2122 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2123 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2124 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2125 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2126 | MultiExprArg Args, |
| 2127 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2128 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2129 | ReceiverTypeInfo->getType(), |
| 2130 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2131 | Sel, Method, LBracLoc, SelectorLoc, |
| 2132 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2136 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2137 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2138 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2139 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2140 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2141 | MultiExprArg Args, |
| 2142 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2143 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2144 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2145 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2146 | Sel, Method, LBracLoc, SelectorLoc, |
| 2147 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2150 | /// \brief Build a new Objective-C ivar reference expression. |
| 2151 | /// |
| 2152 | /// By default, performs semantic analysis to build the new expression. |
| 2153 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2154 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2155 | SourceLocation IvarLoc, |
| 2156 | bool IsArrow, bool IsFreeIvar) { |
| 2157 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2158 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2159 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2160 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2161 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2162 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2163 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2164 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2165 | false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2166 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2167 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2169 | if (Result.get()) |
| 2170 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2171 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2172 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2173 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2174 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2175 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2176 | /*TemplateArgs=*/0); |
| 2177 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2178 | |
| 2179 | /// \brief Build a new Objective-C property reference expression. |
| 2180 | /// |
| 2181 | /// By default, performs semantic analysis to build the new expression. |
| 2182 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2183 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2184 | ObjCPropertyDecl *Property, |
| 2185 | SourceLocation PropertyLoc) { |
| 2186 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2187 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2188 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2189 | Sema::LookupMemberName); |
| 2190 | bool IsArrow = false; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2191 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2192 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2193 | SS, 0, false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2194 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2195 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2196 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2197 | if (Result.get()) |
| 2198 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2199 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2200 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2201 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2202 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2203 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2204 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2205 | /*TemplateArgs=*/0); |
| 2206 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2207 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2208 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2209 | /// |
| 2210 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2211 | /// Subclasses may override this routine to provide different behavior. |
| 2212 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2213 | ObjCMethodDecl *Getter, |
| 2214 | ObjCMethodDecl *Setter, |
| 2215 | SourceLocation PropertyLoc) { |
| 2216 | // Since these expressions can only be value-dependent, we do not |
| 2217 | // need to perform semantic analysis again. |
| 2218 | return Owned( |
| 2219 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2220 | VK_LValue, OK_ObjCProperty, |
| 2221 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2224 | /// \brief Build a new Objective-C "isa" expression. |
| 2225 | /// |
| 2226 | /// By default, performs semantic analysis to build the new expression. |
| 2227 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2228 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2229 | bool IsArrow) { |
| 2230 | CXXScopeSpec SS; |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2231 | ExprResult Base = getSema().Owned(BaseArg); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2232 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2233 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2234 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2235 | /*FIME:*/IsaLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2236 | SS, 0, false); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2237 | if (Result.isInvalid() || Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2238 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2239 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2240 | if (Result.get()) |
| 2241 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2242 | |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2243 | return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2244 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2245 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2246 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2247 | /*TemplateArgs=*/0); |
| 2248 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2250 | /// \brief Build a new shuffle vector expression. |
| 2251 | /// |
| 2252 | /// By default, performs semantic analysis to build the new expression. |
| 2253 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2254 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2255 | MultiExprArg SubExprs, |
| 2256 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2257 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2258 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2259 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2260 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2261 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2262 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2264 | // Build a reference to the __builtin_shufflevector builtin |
| 2265 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2266 | ExprResult Callee |
| 2267 | = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
| 2268 | VK_LValue, BuiltinLoc)); |
| 2269 | Callee = SemaRef.UsualUnaryConversions(Callee.take()); |
| 2270 | if (Callee.isInvalid()) |
| 2271 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2272 | |
| 2273 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2274 | unsigned NumSubExprs = SubExprs.size(); |
| 2275 | Expr **Subs = (Expr **)SubExprs.release(); |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2276 | ExprResult TheCall = SemaRef.Owned( |
| 2277 | new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2278 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2279 | Builtin->getCallResultType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2280 | Expr::getValueKindForType(Builtin->getResultType()), |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2281 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2282 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2283 | // Type-check the __builtin_shufflevector expression. |
John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2284 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2285 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2286 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2287 | /// \brief Build a new template argument pack expansion. |
| 2288 | /// |
| 2289 | /// By default, performs semantic analysis to build a new pack expansion |
| 2290 | /// for a template argument. Subclasses may override this routine to provide |
| 2291 | /// different behavior. |
| 2292 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2293 | SourceLocation EllipsisLoc, |
| 2294 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2295 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2296 | case TemplateArgument::Expression: { |
| 2297 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2298 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2299 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2300 | if (Result.isInvalid()) |
| 2301 | return TemplateArgumentLoc(); |
| 2302 | |
| 2303 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2304 | } |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2305 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2306 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2307 | return TemplateArgumentLoc(TemplateArgument( |
| 2308 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2309 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2310 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2311 | Pattern.getTemplateNameLoc(), |
| 2312 | EllipsisLoc); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2313 | |
| 2314 | case TemplateArgument::Null: |
| 2315 | case TemplateArgument::Integral: |
| 2316 | case TemplateArgument::Declaration: |
| 2317 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2318 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2319 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2320 | |
| 2321 | case TemplateArgument::Type: |
| 2322 | if (TypeSourceInfo *Expansion |
| 2323 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2324 | EllipsisLoc, |
| 2325 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2326 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2327 | Expansion); |
| 2328 | break; |
| 2329 | } |
| 2330 | |
| 2331 | return TemplateArgumentLoc(); |
| 2332 | } |
| 2333 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2334 | /// \brief Build a new expression pack expansion. |
| 2335 | /// |
| 2336 | /// By default, performs semantic analysis to build a new pack expansion |
| 2337 | /// for an expression. Subclasses may override this routine to provide |
| 2338 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2339 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2340 | llvm::Optional<unsigned> NumExpansions) { |
| 2341 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2344 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2345 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2346 | QualType ObjectType, |
| 2347 | NamedDecl *FirstQualifierInScope, |
| 2348 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2349 | |
| 2350 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2351 | QualType ObjectType, |
| 2352 | NamedDecl *FirstQualifierInScope, |
| 2353 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2354 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2355 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2356 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2357 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2358 | if (!S) |
| 2359 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2360 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2361 | switch (S->getStmtClass()) { |
| 2362 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2363 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2364 | // Transform individual statement nodes |
| 2365 | #define STMT(Node, Parent) \ |
| 2366 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2367 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2368 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2369 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2370 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2371 | // Transform expressions by calling TransformExpr. |
| 2372 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2373 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2374 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2375 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2376 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2377 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2378 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2379 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2380 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2381 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2385 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2386 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2387 | |
| 2388 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2389 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2390 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2391 | if (!E) |
| 2392 | return SemaRef.Owned(E); |
| 2393 | |
| 2394 | switch (E->getStmtClass()) { |
| 2395 | case Stmt::NoStmtClass: break; |
| 2396 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2397 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2398 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2399 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2400 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2403 | return SemaRef.Owned(E); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | template<typename Derived> |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2407 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2408 | unsigned NumInputs, |
| 2409 | bool IsCall, |
| 2410 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 2411 | bool *ArgChanged) { |
| 2412 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2413 | // If requested, drop call arguments that need to be dropped. |
| 2414 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2415 | if (ArgChanged) |
| 2416 | *ArgChanged = true; |
| 2417 | |
| 2418 | break; |
| 2419 | } |
| 2420 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2421 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2422 | Expr *Pattern = Expansion->getPattern(); |
| 2423 | |
| 2424 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2425 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2426 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2427 | |
| 2428 | // Determine whether the set of unexpanded parameter packs can and should |
| 2429 | // be expanded. |
| 2430 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2431 | bool RetainExpansion = false; |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2432 | llvm::Optional<unsigned> OrigNumExpansions |
| 2433 | = Expansion->getNumExpansions(); |
| 2434 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2435 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2436 | Pattern->getSourceRange(), |
| 2437 | Unexpanded.data(), |
| 2438 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2439 | Expand, RetainExpansion, |
| 2440 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2441 | return true; |
| 2442 | |
| 2443 | if (!Expand) { |
| 2444 | // The transform has determined that we should perform a simple |
| 2445 | // transformation on the pack expansion, producing another pack |
| 2446 | // expansion. |
| 2447 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2448 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2449 | if (OutPattern.isInvalid()) |
| 2450 | return true; |
| 2451 | |
| 2452 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2453 | Expansion->getEllipsisLoc(), |
| 2454 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2455 | if (Out.isInvalid()) |
| 2456 | return true; |
| 2457 | |
| 2458 | if (ArgChanged) |
| 2459 | *ArgChanged = true; |
| 2460 | Outputs.push_back(Out.get()); |
| 2461 | continue; |
| 2462 | } |
| 2463 | |
| 2464 | // The transform has determined that we should perform an elementwise |
| 2465 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2466 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2467 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2468 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2469 | if (Out.isInvalid()) |
| 2470 | return true; |
| 2471 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2472 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2473 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2474 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2475 | if (Out.isInvalid()) |
| 2476 | return true; |
| 2477 | } |
| 2478 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2479 | if (ArgChanged) |
| 2480 | *ArgChanged = true; |
| 2481 | Outputs.push_back(Out.get()); |
| 2482 | } |
| 2483 | |
| 2484 | continue; |
| 2485 | } |
| 2486 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2487 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2488 | if (Result.isInvalid()) |
| 2489 | return true; |
| 2490 | |
| 2491 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2492 | *ArgChanged = true; |
| 2493 | |
| 2494 | Outputs.push_back(Result.get()); |
| 2495 | } |
| 2496 | |
| 2497 | return false; |
| 2498 | } |
| 2499 | |
| 2500 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2501 | NestedNameSpecifierLoc |
| 2502 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2503 | NestedNameSpecifierLoc NNS, |
| 2504 | QualType ObjectType, |
| 2505 | NamedDecl *FirstQualifierInScope) { |
| 2506 | llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 2507 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2508 | Qualifier = Qualifier.getPrefix()) |
| 2509 | Qualifiers.push_back(Qualifier); |
| 2510 | |
| 2511 | CXXScopeSpec SS; |
| 2512 | while (!Qualifiers.empty()) { |
| 2513 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2514 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2515 | |
| 2516 | switch (QNNS->getKind()) { |
| 2517 | case NestedNameSpecifier::Identifier: |
| 2518 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2519 | *QNNS->getAsIdentifier(), |
| 2520 | Q.getLocalBeginLoc(), |
| 2521 | Q.getLocalEndLoc(), |
| 2522 | ObjectType, false, SS, |
| 2523 | FirstQualifierInScope, false)) |
| 2524 | return NestedNameSpecifierLoc(); |
| 2525 | |
| 2526 | break; |
| 2527 | |
| 2528 | case NestedNameSpecifier::Namespace: { |
| 2529 | NamespaceDecl *NS |
| 2530 | = cast_or_null<NamespaceDecl>( |
| 2531 | getDerived().TransformDecl( |
| 2532 | Q.getLocalBeginLoc(), |
| 2533 | QNNS->getAsNamespace())); |
| 2534 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2535 | break; |
| 2536 | } |
| 2537 | |
| 2538 | case NestedNameSpecifier::NamespaceAlias: { |
| 2539 | NamespaceAliasDecl *Alias |
| 2540 | = cast_or_null<NamespaceAliasDecl>( |
| 2541 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2542 | QNNS->getAsNamespaceAlias())); |
| 2543 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2544 | Q.getLocalEndLoc()); |
| 2545 | break; |
| 2546 | } |
| 2547 | |
| 2548 | case NestedNameSpecifier::Global: |
| 2549 | // There is no meaningful transformation that one could perform on the |
| 2550 | // global scope. |
| 2551 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2552 | break; |
| 2553 | |
| 2554 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2555 | case NestedNameSpecifier::TypeSpec: { |
| 2556 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2557 | FirstQualifierInScope, SS); |
| 2558 | |
| 2559 | if (!TL) |
| 2560 | return NestedNameSpecifierLoc(); |
| 2561 | |
| 2562 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 2563 | (SemaRef.getLangOptions().CPlusPlus0x && |
| 2564 | TL.getType()->isEnumeralType())) { |
| 2565 | assert(!TL.getType().hasLocalQualifiers() && |
| 2566 | "Can't get cv-qualifiers here"); |
| 2567 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2568 | Q.getLocalEndLoc()); |
| 2569 | break; |
| 2570 | } |
Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame^] | 2571 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 2572 | // error because a previous error should have already been emitted. |
| 2573 | TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); |
| 2574 | if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { |
| 2575 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2576 | << TL.getType() << SS.getRange(); |
| 2577 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2578 | return NestedNameSpecifierLoc(); |
| 2579 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2580 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2582 | // 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] | 2583 | FirstQualifierInScope = 0; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2584 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2588 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2589 | !getDerived().AlwaysRebuild()) |
| 2590 | return NNS; |
| 2591 | |
| 2592 | // If we can re-use the source-location data from the original |
| 2593 | // nested-name-specifier, do so. |
| 2594 | if (SS.location_size() == NNS.getDataLength() && |
| 2595 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2596 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2597 | |
| 2598 | // Allocate new nested-name-specifier location information. |
| 2599 | return SS.getWithLocInContext(SemaRef.Context); |
| 2600 | } |
| 2601 | |
| 2602 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2603 | DeclarationNameInfo |
| 2604 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2605 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2606 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2607 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2608 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2609 | |
| 2610 | switch (Name.getNameKind()) { |
| 2611 | case DeclarationName::Identifier: |
| 2612 | case DeclarationName::ObjCZeroArgSelector: |
| 2613 | case DeclarationName::ObjCOneArgSelector: |
| 2614 | case DeclarationName::ObjCMultiArgSelector: |
| 2615 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2616 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2617 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2618 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2620 | case DeclarationName::CXXConstructorName: |
| 2621 | case DeclarationName::CXXDestructorName: |
| 2622 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2623 | TypeSourceInfo *NewTInfo; |
| 2624 | CanQualType NewCanTy; |
| 2625 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2626 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2627 | if (!NewTInfo) |
| 2628 | return DeclarationNameInfo(); |
| 2629 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2630 | } |
| 2631 | else { |
| 2632 | NewTInfo = 0; |
| 2633 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2634 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2635 | if (NewT.isNull()) |
| 2636 | return DeclarationNameInfo(); |
| 2637 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2638 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2639 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2640 | DeclarationName NewName |
| 2641 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2642 | NewCanTy); |
| 2643 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2644 | NewNameInfo.setName(NewName); |
| 2645 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2646 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2650 | assert(0 && "Unknown name kind."); |
| 2651 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2655 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2656 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2657 | TemplateName Name, |
| 2658 | SourceLocation NameLoc, |
| 2659 | QualType ObjectType, |
| 2660 | NamedDecl *FirstQualifierInScope) { |
| 2661 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2662 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2663 | assert(Template && "qualified template name must refer to a template"); |
| 2664 | |
| 2665 | TemplateDecl *TransTemplate |
| 2666 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2667 | Template)); |
| 2668 | if (!TransTemplate) |
| 2669 | return TemplateName(); |
| 2670 | |
| 2671 | if (!getDerived().AlwaysRebuild() && |
| 2672 | SS.getScopeRep() == QTN->getQualifier() && |
| 2673 | TransTemplate == Template) |
| 2674 | return Name; |
| 2675 | |
| 2676 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2677 | TransTemplate); |
| 2678 | } |
| 2679 | |
| 2680 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2681 | if (SS.getScopeRep()) { |
| 2682 | // These apply to the scope specifier, not the template. |
| 2683 | ObjectType = QualType(); |
| 2684 | FirstQualifierInScope = 0; |
| 2685 | } |
| 2686 | |
| 2687 | if (!getDerived().AlwaysRebuild() && |
| 2688 | SS.getScopeRep() == DTN->getQualifier() && |
| 2689 | ObjectType.isNull()) |
| 2690 | return Name; |
| 2691 | |
| 2692 | if (DTN->isIdentifier()) { |
| 2693 | return getDerived().RebuildTemplateName(SS, |
| 2694 | *DTN->getIdentifier(), |
| 2695 | NameLoc, |
| 2696 | ObjectType, |
| 2697 | FirstQualifierInScope); |
| 2698 | } |
| 2699 | |
| 2700 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2701 | ObjectType); |
| 2702 | } |
| 2703 | |
| 2704 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2705 | TemplateDecl *TransTemplate |
| 2706 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2707 | Template)); |
| 2708 | if (!TransTemplate) |
| 2709 | return TemplateName(); |
| 2710 | |
| 2711 | if (!getDerived().AlwaysRebuild() && |
| 2712 | TransTemplate == Template) |
| 2713 | return Name; |
| 2714 | |
| 2715 | return TemplateName(TransTemplate); |
| 2716 | } |
| 2717 | |
| 2718 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2719 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2720 | TemplateTemplateParmDecl *TransParam |
| 2721 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2722 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2723 | if (!TransParam) |
| 2724 | return TemplateName(); |
| 2725 | |
| 2726 | if (!getDerived().AlwaysRebuild() && |
| 2727 | TransParam == SubstPack->getParameterPack()) |
| 2728 | return Name; |
| 2729 | |
| 2730 | return getDerived().RebuildTemplateName(TransParam, |
| 2731 | SubstPack->getArgumentPack()); |
| 2732 | } |
| 2733 | |
| 2734 | // These should be getting filtered out before they reach the AST. |
| 2735 | llvm_unreachable("overloaded function decl survived to here"); |
| 2736 | return TemplateName(); |
| 2737 | } |
| 2738 | |
| 2739 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2740 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2741 | const TemplateArgument &Arg, |
| 2742 | TemplateArgumentLoc &Output) { |
| 2743 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2744 | switch (Arg.getKind()) { |
| 2745 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2746 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2747 | break; |
| 2748 | |
| 2749 | case TemplateArgument::Type: |
| 2750 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2751 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2752 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2753 | break; |
| 2754 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2755 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2756 | case TemplateArgument::TemplateExpansion: { |
| 2757 | NestedNameSpecifierLocBuilder Builder; |
| 2758 | TemplateName Template = Arg.getAsTemplate(); |
| 2759 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 2760 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 2761 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 2762 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| 2763 | |
| 2764 | if (Arg.getKind() == TemplateArgument::Template) |
| 2765 | Output = TemplateArgumentLoc(Arg, |
| 2766 | Builder.getWithLocInContext(SemaRef.Context), |
| 2767 | Loc); |
| 2768 | else |
| 2769 | Output = TemplateArgumentLoc(Arg, |
| 2770 | Builder.getWithLocInContext(SemaRef.Context), |
| 2771 | Loc, Loc); |
| 2772 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2773 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2774 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2775 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2776 | case TemplateArgument::Expression: |
| 2777 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2778 | break; |
| 2779 | |
| 2780 | case TemplateArgument::Declaration: |
| 2781 | case TemplateArgument::Integral: |
| 2782 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2783 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2784 | break; |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | template<typename Derived> |
| 2789 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2790 | const TemplateArgumentLoc &Input, |
| 2791 | TemplateArgumentLoc &Output) { |
| 2792 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2793 | switch (Arg.getKind()) { |
| 2794 | case TemplateArgument::Null: |
| 2795 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2796 | Output = Input; |
| 2797 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2798 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2799 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2800 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2801 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2802 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2803 | |
| 2804 | DI = getDerived().TransformType(DI); |
| 2805 | if (!DI) return true; |
| 2806 | |
| 2807 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2808 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2809 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2810 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2811 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2812 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2813 | DeclarationName Name; |
| 2814 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2815 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2816 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2817 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2818 | if (!D) return true; |
| 2819 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2820 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2821 | if (SourceExpr) { |
| 2822 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2823 | Sema::Unevaluated); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2824 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2825 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2829 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2831 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2832 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2833 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 2834 | if (QualifierLoc) { |
| 2835 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 2836 | if (!QualifierLoc) |
| 2837 | return true; |
| 2838 | } |
| 2839 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2840 | CXXScopeSpec SS; |
| 2841 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2842 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2843 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 2844 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2845 | if (Template.isNull()) |
| 2846 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2847 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2848 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2849 | Input.getTemplateNameLoc()); |
| 2850 | return false; |
| 2851 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2852 | |
| 2853 | case TemplateArgument::TemplateExpansion: |
| 2854 | llvm_unreachable("Caller should expand pack expansions"); |
| 2855 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2856 | case TemplateArgument::Expression: { |
| 2857 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2858 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2859 | Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2860 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2861 | Expr *InputExpr = Input.getSourceExpression(); |
| 2862 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2863 | |
Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 2864 | ExprResult E = getDerived().TransformExpr(InputExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2865 | if (E.isInvalid()) return true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2866 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2867 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2868 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2869 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2870 | case TemplateArgument::Pack: { |
| 2871 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2872 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2873 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2874 | AEnd = Arg.pack_end(); |
| 2875 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2876 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2877 | // FIXME: preserve source information here when we start |
| 2878 | // caring about parameter packs. |
| 2879 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2880 | TemplateArgumentLoc InputArg; |
| 2881 | TemplateArgumentLoc OutputArg; |
| 2882 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2883 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2884 | return true; |
| 2885 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2886 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2887 | } |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2888 | |
| 2889 | TemplateArgument *TransformedArgsPtr |
| 2890 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2891 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2892 | TransformedArgsPtr); |
| 2893 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2894 | TransformedArgs.size()), |
| 2895 | Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2896 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2897 | } |
| 2898 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2899 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2900 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2901 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2904 | /// \brief Iterator adaptor that invents template argument location information |
| 2905 | /// for each of the template arguments in its underlying iterator. |
| 2906 | template<typename Derived, typename InputIterator> |
| 2907 | class TemplateArgumentLocInventIterator { |
| 2908 | TreeTransform<Derived> &Self; |
| 2909 | InputIterator Iter; |
| 2910 | |
| 2911 | public: |
| 2912 | typedef TemplateArgumentLoc value_type; |
| 2913 | typedef TemplateArgumentLoc reference; |
| 2914 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2915 | difference_type; |
| 2916 | typedef std::input_iterator_tag iterator_category; |
| 2917 | |
| 2918 | class pointer { |
| 2919 | TemplateArgumentLoc Arg; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2920 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2921 | public: |
| 2922 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2923 | |
| 2924 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2925 | }; |
| 2926 | |
| 2927 | TemplateArgumentLocInventIterator() { } |
| 2928 | |
| 2929 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2930 | InputIterator Iter) |
| 2931 | : Self(Self), Iter(Iter) { } |
| 2932 | |
| 2933 | TemplateArgumentLocInventIterator &operator++() { |
| 2934 | ++Iter; |
| 2935 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2938 | TemplateArgumentLocInventIterator operator++(int) { |
| 2939 | TemplateArgumentLocInventIterator Old(*this); |
| 2940 | ++(*this); |
| 2941 | return Old; |
| 2942 | } |
| 2943 | |
| 2944 | reference operator*() const { |
| 2945 | TemplateArgumentLoc Result; |
| 2946 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 2947 | return Result; |
| 2948 | } |
| 2949 | |
| 2950 | pointer operator->() const { return pointer(**this); } |
| 2951 | |
| 2952 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 2953 | const TemplateArgumentLocInventIterator &Y) { |
| 2954 | return X.Iter == Y.Iter; |
| 2955 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2956 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2957 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 2958 | const TemplateArgumentLocInventIterator &Y) { |
| 2959 | return X.Iter != Y.Iter; |
| 2960 | } |
| 2961 | }; |
| 2962 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2963 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2964 | template<typename InputIterator> |
| 2965 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 2966 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2967 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2968 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2969 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2970 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2971 | |
| 2972 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 2973 | // Unpack argument packs, which we translate them into separate |
| 2974 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2975 | // FIXME: We could do much better if we could guarantee that the |
| 2976 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 2977 | // all of the template arguments in the argument pack. |
| 2978 | typedef TemplateArgumentLocInventIterator<Derived, |
| 2979 | TemplateArgument::pack_iterator> |
| 2980 | PackLocIterator; |
| 2981 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 2982 | In.getArgument().pack_begin()), |
| 2983 | PackLocIterator(*this, |
| 2984 | In.getArgument().pack_end()), |
| 2985 | Outputs)) |
| 2986 | return true; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2987 | |
| 2988 | continue; |
| 2989 | } |
| 2990 | |
| 2991 | if (In.getArgument().isPackExpansion()) { |
| 2992 | // We have a pack expansion, for which we will be substituting into |
| 2993 | // the pattern. |
| 2994 | SourceLocation Ellipsis; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2995 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2996 | TemplateArgumentLoc Pattern |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2997 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 2998 | getSema().Context); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2999 | |
| 3000 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3001 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3002 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 3003 | |
| 3004 | // Determine whether the set of unexpanded parameter packs can and should |
| 3005 | // be expanded. |
| 3006 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3007 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3008 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3009 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 3010 | Pattern.getSourceRange(), |
| 3011 | Unexpanded.data(), |
| 3012 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3013 | Expand, |
| 3014 | RetainExpansion, |
| 3015 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3016 | return true; |
| 3017 | |
| 3018 | if (!Expand) { |
| 3019 | // The transform has determined that we should perform a simple |
| 3020 | // transformation on the pack expansion, producing another pack |
| 3021 | // expansion. |
| 3022 | TemplateArgumentLoc OutPattern; |
| 3023 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3024 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 3025 | return true; |
| 3026 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3027 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 3028 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3029 | if (Out.getArgument().isNull()) |
| 3030 | return true; |
| 3031 | |
| 3032 | Outputs.addArgument(Out); |
| 3033 | continue; |
| 3034 | } |
| 3035 | |
| 3036 | // The transform has determined that we should perform an elementwise |
| 3037 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3038 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3039 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3040 | |
| 3041 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3042 | return true; |
| 3043 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3044 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3045 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3046 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3047 | if (Out.getArgument().isNull()) |
| 3048 | return true; |
| 3049 | } |
| 3050 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3051 | Outputs.addArgument(Out); |
| 3052 | } |
| 3053 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3054 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3055 | // forgetting the partially-substituted parameter pack. |
| 3056 | if (RetainExpansion) { |
| 3057 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3058 | |
| 3059 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3060 | return true; |
| 3061 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3062 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3063 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3064 | if (Out.getArgument().isNull()) |
| 3065 | return true; |
| 3066 | |
| 3067 | Outputs.addArgument(Out); |
| 3068 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3069 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3070 | continue; |
| 3071 | } |
| 3072 | |
| 3073 | // The simple case: |
| 3074 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3075 | return true; |
| 3076 | |
| 3077 | Outputs.addArgument(Out); |
| 3078 | } |
| 3079 | |
| 3080 | return false; |
| 3081 | |
| 3082 | } |
| 3083 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3084 | //===----------------------------------------------------------------------===// |
| 3085 | // Type transformation |
| 3086 | //===----------------------------------------------------------------------===// |
| 3087 | |
| 3088 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3089 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3090 | if (getDerived().AlreadyTransformed(T)) |
| 3091 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3092 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3093 | // Temporary workaround. All of these transformations should |
| 3094 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3095 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3096 | getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3097 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3098 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3099 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3100 | if (!NewDI) |
| 3101 | return QualType(); |
| 3102 | |
| 3103 | return NewDI->getType(); |
| 3104 | } |
| 3105 | |
| 3106 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3107 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3108 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3109 | return DI; |
| 3110 | |
| 3111 | TypeLocBuilder TLB; |
| 3112 | |
| 3113 | TypeLoc TL = DI->getTypeLoc(); |
| 3114 | TLB.reserve(TL.getFullDataSize()); |
| 3115 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3116 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3117 | if (Result.isNull()) |
| 3118 | return 0; |
| 3119 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3120 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | template<typename Derived> |
| 3124 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3125 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3126 | switch (T.getTypeLocClass()) { |
| 3127 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3128 | #define TYPELOC(CLASS, PARENT) \ |
| 3129 | case TypeLoc::CLASS: \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3130 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3131 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3132 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3134 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3135 | return QualType(); |
| 3136 | } |
| 3137 | |
| 3138 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3139 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3140 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3141 | /// types). This is the right thing for template instantiation, but |
| 3142 | /// probably not for other clients. |
| 3143 | template<typename Derived> |
| 3144 | QualType |
| 3145 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3146 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3147 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3148 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3149 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3150 | if (Result.isNull()) |
| 3151 | return QualType(); |
| 3152 | |
| 3153 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3154 | // FIXME: this is the right thing for template instantiation, but |
| 3155 | // probably not for other clients. |
| 3156 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3157 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3159 | if (!Quals.empty()) { |
| 3160 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3161 | TLB.push<QualifiedTypeLoc>(Result); |
| 3162 | // No location information to preserve. |
| 3163 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3164 | |
| 3165 | return Result; |
| 3166 | } |
| 3167 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3168 | template<typename Derived> |
| 3169 | TypeLoc |
| 3170 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3171 | QualType ObjectType, |
| 3172 | NamedDecl *UnqualLookup, |
| 3173 | CXXScopeSpec &SS) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3174 | QualType T = TL.getType(); |
| 3175 | if (getDerived().AlreadyTransformed(T)) |
| 3176 | return TL; |
| 3177 | |
| 3178 | TypeLocBuilder TLB; |
| 3179 | QualType Result; |
| 3180 | |
| 3181 | if (isa<TemplateSpecializationType>(T)) { |
| 3182 | TemplateSpecializationTypeLoc SpecTL |
| 3183 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3184 | |
| 3185 | TemplateName Template = |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3186 | getDerived().TransformTemplateName(SS, |
| 3187 | SpecTL.getTypePtr()->getTemplateName(), |
| 3188 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3189 | ObjectType, UnqualLookup); |
| 3190 | if (Template.isNull()) |
| 3191 | return TypeLoc(); |
| 3192 | |
| 3193 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3194 | Template); |
| 3195 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3196 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3197 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3198 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3199 | TemplateName Template |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3200 | = getDerived().RebuildTemplateName(SS, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3201 | *SpecTL.getTypePtr()->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3202 | SpecTL.getNameLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3203 | ObjectType, UnqualLookup); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3204 | if (Template.isNull()) |
| 3205 | return TypeLoc(); |
| 3206 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3207 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3208 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3209 | Template, |
| 3210 | SS); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3211 | } else { |
| 3212 | // Nothing special needs to be done for these. |
| 3213 | Result = getDerived().TransformType(TLB, TL); |
| 3214 | } |
| 3215 | |
| 3216 | if (Result.isNull()) |
| 3217 | return TypeLoc(); |
| 3218 | |
| 3219 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3220 | } |
| 3221 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3222 | template<typename Derived> |
| 3223 | TypeSourceInfo * |
| 3224 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3225 | QualType ObjectType, |
| 3226 | NamedDecl *UnqualLookup, |
| 3227 | CXXScopeSpec &SS) { |
| 3228 | // FIXME: Painfully copy-paste from the above! |
| 3229 | |
| 3230 | QualType T = TSInfo->getType(); |
| 3231 | if (getDerived().AlreadyTransformed(T)) |
| 3232 | return TSInfo; |
| 3233 | |
| 3234 | TypeLocBuilder TLB; |
| 3235 | QualType Result; |
| 3236 | |
| 3237 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3238 | if (isa<TemplateSpecializationType>(T)) { |
| 3239 | TemplateSpecializationTypeLoc SpecTL |
| 3240 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3241 | |
| 3242 | TemplateName Template |
| 3243 | = getDerived().TransformTemplateName(SS, |
| 3244 | SpecTL.getTypePtr()->getTemplateName(), |
| 3245 | SpecTL.getTemplateNameLoc(), |
| 3246 | ObjectType, UnqualLookup); |
| 3247 | if (Template.isNull()) |
| 3248 | return 0; |
| 3249 | |
| 3250 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3251 | Template); |
| 3252 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3253 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3254 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3255 | |
| 3256 | TemplateName Template |
| 3257 | = getDerived().RebuildTemplateName(SS, |
| 3258 | *SpecTL.getTypePtr()->getIdentifier(), |
| 3259 | SpecTL.getNameLoc(), |
| 3260 | ObjectType, UnqualLookup); |
| 3261 | if (Template.isNull()) |
| 3262 | return 0; |
| 3263 | |
| 3264 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| 3265 | SpecTL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 3266 | Template, |
| 3267 | SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3268 | } else { |
| 3269 | // Nothing special needs to be done for these. |
| 3270 | Result = getDerived().TransformType(TLB, TL); |
| 3271 | } |
| 3272 | |
| 3273 | if (Result.isNull()) |
| 3274 | return 0; |
| 3275 | |
| 3276 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3277 | } |
| 3278 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3279 | template <class TyLoc> static inline |
| 3280 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3281 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3282 | NewT.setNameLoc(T.getNameLoc()); |
| 3283 | return T.getType(); |
| 3284 | } |
| 3285 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3286 | template<typename Derived> |
| 3287 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3288 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3289 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3290 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3291 | if (T.needsExtraLocalData()) |
| 3292 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3293 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3294 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3296 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3297 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3298 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3299 | // FIXME: recurse? |
| 3300 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3301 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3302 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3303 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3304 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3305 | PointerTypeLoc TL) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3306 | QualType PointeeType |
| 3307 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3308 | if (PointeeType.isNull()) |
| 3309 | return QualType(); |
| 3310 | |
| 3311 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3312 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3313 | // A dependent pointer type 'T *' has is being transformed such |
| 3314 | // that an Objective-C class type is being replaced for 'T'. The |
| 3315 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3316 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3317 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3318 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3319 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3320 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3321 | return Result; |
| 3322 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3323 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3324 | if (getDerived().AlwaysRebuild() || |
| 3325 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3326 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3327 | if (Result.isNull()) |
| 3328 | return QualType(); |
| 3329 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3330 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3331 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3332 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3333 | return Result; |
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 | |
| 3336 | template<typename Derived> |
| 3337 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3338 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3339 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3340 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3341 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3342 | if (PointeeType.isNull()) |
| 3343 | return QualType(); |
| 3344 | |
| 3345 | QualType Result = TL.getType(); |
| 3346 | if (getDerived().AlwaysRebuild() || |
| 3347 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3348 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3349 | TL.getSigilLoc()); |
| 3350 | if (Result.isNull()) |
| 3351 | return QualType(); |
| 3352 | } |
| 3353 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3354 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3355 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3356 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3359 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3360 | /// don't care whether the type itself is an l-value type or an r-value |
| 3361 | /// type; we only care if the type was *written* as an l-value type |
| 3362 | /// or an r-value type. |
| 3363 | template<typename Derived> |
| 3364 | QualType |
| 3365 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3366 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3367 | const ReferenceType *T = TL.getTypePtr(); |
| 3368 | |
| 3369 | // Note that this works with the pointee-as-written. |
| 3370 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3371 | if (PointeeType.isNull()) |
| 3372 | return QualType(); |
| 3373 | |
| 3374 | QualType Result = TL.getType(); |
| 3375 | if (getDerived().AlwaysRebuild() || |
| 3376 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3377 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3378 | T->isSpelledAsLValue(), |
| 3379 | TL.getSigilLoc()); |
| 3380 | if (Result.isNull()) |
| 3381 | return QualType(); |
| 3382 | } |
| 3383 | |
| 3384 | // r-value references can be rebuilt as l-value references. |
| 3385 | ReferenceTypeLoc NewTL; |
| 3386 | if (isa<LValueReferenceType>(Result)) |
| 3387 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3388 | else |
| 3389 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3390 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3391 | |
| 3392 | return Result; |
| 3393 | } |
| 3394 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | template<typename Derived> |
| 3396 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3397 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3398 | LValueReferenceTypeLoc TL) { |
| 3399 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3402 | template<typename Derived> |
| 3403 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3404 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3405 | RValueReferenceTypeLoc TL) { |
| 3406 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3407 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3408 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3409 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3411 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3412 | MemberPointerTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3413 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3414 | if (PointeeType.isNull()) |
| 3415 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3416 | |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3417 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 3418 | TypeSourceInfo* NewClsTInfo = 0; |
| 3419 | if (OldClsTInfo) { |
| 3420 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 3421 | if (!NewClsTInfo) |
| 3422 | return QualType(); |
| 3423 | } |
| 3424 | |
| 3425 | const MemberPointerType *T = TL.getTypePtr(); |
| 3426 | QualType OldClsType = QualType(T->getClass(), 0); |
| 3427 | QualType NewClsType; |
| 3428 | if (NewClsTInfo) |
| 3429 | NewClsType = NewClsTInfo->getType(); |
| 3430 | else { |
| 3431 | NewClsType = getDerived().TransformType(OldClsType); |
| 3432 | if (NewClsType.isNull()) |
| 3433 | return QualType(); |
| 3434 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3436 | QualType Result = TL.getType(); |
| 3437 | if (getDerived().AlwaysRebuild() || |
| 3438 | PointeeType != T->getPointeeType() || |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3439 | NewClsType != OldClsType) { |
| 3440 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3441 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3442 | if (Result.isNull()) |
| 3443 | return QualType(); |
| 3444 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3445 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3446 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3447 | NewTL.setSigilLoc(TL.getSigilLoc()); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3448 | NewTL.setClassTInfo(NewClsTInfo); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3449 | |
| 3450 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3453 | template<typename Derived> |
| 3454 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3455 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3456 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3457 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3458 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3459 | if (ElementType.isNull()) |
| 3460 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3462 | QualType Result = TL.getType(); |
| 3463 | if (getDerived().AlwaysRebuild() || |
| 3464 | ElementType != T->getElementType()) { |
| 3465 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3466 | T->getSizeModifier(), |
| 3467 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3468 | T->getIndexTypeCVRQualifiers(), |
| 3469 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3470 | if (Result.isNull()) |
| 3471 | return QualType(); |
| 3472 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3473 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3474 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3475 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3476 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3477 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3478 | Expr *Size = TL.getSizeExpr(); |
| 3479 | if (Size) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3480 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3481 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3482 | } |
| 3483 | NewTL.setSizeExpr(Size); |
| 3484 | |
| 3485 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3487 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3488 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3489 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3490 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3491 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3492 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3493 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3494 | if (ElementType.isNull()) |
| 3495 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3496 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3497 | QualType Result = TL.getType(); |
| 3498 | if (getDerived().AlwaysRebuild() || |
| 3499 | ElementType != T->getElementType()) { |
| 3500 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3501 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3502 | T->getIndexTypeCVRQualifiers(), |
| 3503 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3504 | if (Result.isNull()) |
| 3505 | return QualType(); |
| 3506 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3507 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3508 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3509 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3510 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3511 | NewTL.setSizeExpr(0); |
| 3512 | |
| 3513 | return Result; |
| 3514 | } |
| 3515 | |
| 3516 | template<typename Derived> |
| 3517 | QualType |
| 3518 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3519 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3520 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3521 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3522 | if (ElementType.isNull()) |
| 3523 | return QualType(); |
| 3524 | |
| 3525 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3526 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3527 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3528 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3529 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3530 | if (SizeResult.isInvalid()) |
| 3531 | return QualType(); |
| 3532 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3533 | Expr *Size = SizeResult.take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3534 | |
| 3535 | QualType Result = TL.getType(); |
| 3536 | if (getDerived().AlwaysRebuild() || |
| 3537 | ElementType != T->getElementType() || |
| 3538 | Size != T->getSizeExpr()) { |
| 3539 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3540 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3541 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3542 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3543 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3544 | if (Result.isNull()) |
| 3545 | return QualType(); |
| 3546 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3547 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3548 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3549 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3550 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3551 | NewTL.setSizeExpr(Size); |
| 3552 | |
| 3553 | return Result; |
| 3554 | } |
| 3555 | |
| 3556 | template<typename Derived> |
| 3557 | QualType |
| 3558 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3559 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3560 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3561 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3562 | if (ElementType.isNull()) |
| 3563 | return QualType(); |
| 3564 | |
| 3565 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3566 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3567 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3568 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3569 | Expr *origSize = TL.getSizeExpr(); |
| 3570 | if (!origSize) origSize = T->getSizeExpr(); |
| 3571 | |
| 3572 | ExprResult sizeResult |
| 3573 | = getDerived().TransformExpr(origSize); |
| 3574 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3575 | return QualType(); |
| 3576 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3577 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3578 | |
| 3579 | QualType Result = TL.getType(); |
| 3580 | if (getDerived().AlwaysRebuild() || |
| 3581 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3582 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3583 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3584 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3585 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3586 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3587 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3588 | if (Result.isNull()) |
| 3589 | return QualType(); |
| 3590 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3591 | |
| 3592 | // We might have any sort of array type now, but fortunately they |
| 3593 | // all have the same location layout. |
| 3594 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3595 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3596 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3597 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3598 | |
| 3599 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
| 3602 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3603 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3604 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3605 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3606 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3607 | |
| 3608 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3609 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3610 | if (ElementType.isNull()) |
| 3611 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3613 | // Vector sizes are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3614 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3615 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3616 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3617 | if (Size.isInvalid()) |
| 3618 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3619 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3620 | QualType Result = TL.getType(); |
| 3621 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3622 | ElementType != T->getElementType() || |
| 3623 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3624 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3625 | Size.take(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3626 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3627 | if (Result.isNull()) |
| 3628 | return QualType(); |
| 3629 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3630 | |
| 3631 | // Result might be dependent or not. |
| 3632 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3633 | DependentSizedExtVectorTypeLoc NewTL |
| 3634 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3635 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3636 | } else { |
| 3637 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3638 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3639 | } |
| 3640 | |
| 3641 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | |
| 3644 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3645 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3646 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3647 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3648 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3649 | if (ElementType.isNull()) |
| 3650 | return QualType(); |
| 3651 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3652 | QualType Result = TL.getType(); |
| 3653 | if (getDerived().AlwaysRebuild() || |
| 3654 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3655 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3656 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3657 | if (Result.isNull()) |
| 3658 | return QualType(); |
| 3659 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3660 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3661 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3662 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3664 | return Result; |
| 3665 | } |
| 3666 | |
| 3667 | template<typename Derived> |
| 3668 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3669 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3670 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3671 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3672 | if (ElementType.isNull()) |
| 3673 | return QualType(); |
| 3674 | |
| 3675 | QualType Result = TL.getType(); |
| 3676 | if (getDerived().AlwaysRebuild() || |
| 3677 | ElementType != T->getElementType()) { |
| 3678 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3679 | T->getNumElements(), |
| 3680 | /*FIXME*/ SourceLocation()); |
| 3681 | if (Result.isNull()) |
| 3682 | return QualType(); |
| 3683 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3684 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3685 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3686 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3687 | |
| 3688 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3689 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
| 3691 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3692 | ParmVarDecl * |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3693 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3694 | int indexAdjustment, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3695 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3696 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3697 | TypeSourceInfo *NewDI = 0; |
| 3698 | |
| 3699 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3700 | // If we're substituting into a pack expansion type and we know the |
| 3701 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3702 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3703 | |
| 3704 | TypeLocBuilder TLB; |
| 3705 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3706 | TLB.reserve(NewTL.getFullDataSize()); |
| 3707 | |
| 3708 | QualType Result = getDerived().TransformType(TLB, |
| 3709 | OldExpansionTL.getPatternLoc()); |
| 3710 | if (Result.isNull()) |
| 3711 | return 0; |
| 3712 | |
| 3713 | Result = RebuildPackExpansionType(Result, |
| 3714 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3715 | OldExpansionTL.getEllipsisLoc(), |
| 3716 | NumExpansions); |
| 3717 | if (Result.isNull()) |
| 3718 | return 0; |
| 3719 | |
| 3720 | PackExpansionTypeLoc NewExpansionTL |
| 3721 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3722 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3723 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3724 | } else |
| 3725 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3726 | if (!NewDI) |
| 3727 | return 0; |
| 3728 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3729 | if (NewDI == OldDI && indexAdjustment == 0) |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3730 | return OldParm; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3731 | |
| 3732 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 3733 | OldParm->getDeclContext(), |
| 3734 | OldParm->getInnerLocStart(), |
| 3735 | OldParm->getLocation(), |
| 3736 | OldParm->getIdentifier(), |
| 3737 | NewDI->getType(), |
| 3738 | NewDI, |
| 3739 | OldParm->getStorageClass(), |
| 3740 | OldParm->getStorageClassAsWritten(), |
| 3741 | /* DefArg */ NULL); |
| 3742 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 3743 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 3744 | return newParm; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | template<typename Derived> |
| 3748 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3749 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3750 | ParmVarDecl **Params, unsigned NumParams, |
| 3751 | const QualType *ParamTypes, |
| 3752 | llvm::SmallVectorImpl<QualType> &OutParamTypes, |
| 3753 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3754 | int indexAdjustment = 0; |
| 3755 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3756 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3757 | if (ParmVarDecl *OldParm = Params[i]) { |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3758 | assert(OldParm->getFunctionScopeIndex() == i); |
| 3759 | |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3760 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3761 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3762 | if (OldParm->isParameterPack()) { |
| 3763 | // We have a function parameter pack that may need to be expanded. |
| 3764 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3765 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3766 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3767 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3768 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3769 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3770 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3771 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 3772 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3773 | // Determine whether we should expand the parameter packs. |
| 3774 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3775 | bool RetainExpansion = false; |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3776 | llvm::Optional<unsigned> OrigNumExpansions |
| 3777 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3778 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3779 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3780 | Pattern.getSourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3781 | Unexpanded.data(), |
| 3782 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3783 | ShouldExpand, |
| 3784 | RetainExpansion, |
| 3785 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3786 | return true; |
| 3787 | } |
| 3788 | |
| 3789 | if (ShouldExpand) { |
| 3790 | // Expand the function parameter pack into multiple, separate |
| 3791 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3792 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3793 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3794 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3795 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3796 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3797 | indexAdjustment++, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3798 | OrigNumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3799 | if (!NewParm) |
| 3800 | return true; |
| 3801 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3802 | OutParamTypes.push_back(NewParm->getType()); |
| 3803 | if (PVars) |
| 3804 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3805 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3806 | |
| 3807 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3808 | // forgetting the partially-substituted parameter pack. |
| 3809 | if (RetainExpansion) { |
| 3810 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3811 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3812 | = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3813 | indexAdjustment++, |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3814 | OrigNumExpansions); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3815 | if (!NewParm) |
| 3816 | return true; |
| 3817 | |
| 3818 | OutParamTypes.push_back(NewParm->getType()); |
| 3819 | if (PVars) |
| 3820 | PVars->push_back(NewParm); |
| 3821 | } |
| 3822 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3823 | // The next parameter should have the same adjustment as the |
| 3824 | // last thing we pushed, but we post-incremented indexAdjustment |
| 3825 | // on every push. Also, if we push nothing, the adjustment should |
| 3826 | // go down by one. |
| 3827 | indexAdjustment--; |
| 3828 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3829 | // We're done with the pack expansion. |
| 3830 | continue; |
| 3831 | } |
| 3832 | |
| 3833 | // We'll substitute the parameter now without expanding the pack |
| 3834 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3835 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3836 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3837 | indexAdjustment, |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3838 | NumExpansions); |
| 3839 | } else { |
| 3840 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3841 | indexAdjustment, |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3842 | llvm::Optional<unsigned>()); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3843 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3844 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3845 | if (!NewParm) |
| 3846 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3847 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3848 | OutParamTypes.push_back(NewParm->getType()); |
| 3849 | if (PVars) |
| 3850 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3851 | continue; |
| 3852 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3853 | |
| 3854 | // Deal with the possibility that we don't have a parameter |
| 3855 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3856 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3857 | bool IsPackExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3858 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3859 | QualType NewType; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3860 | if (const PackExpansionType *Expansion |
| 3861 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3862 | // We have a function parameter pack that may need to be expanded. |
| 3863 | QualType Pattern = Expansion->getPattern(); |
| 3864 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3865 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3866 | |
| 3867 | // Determine whether we should expand the parameter packs. |
| 3868 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3869 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3870 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3871 | Unexpanded.data(), |
| 3872 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3873 | ShouldExpand, |
| 3874 | RetainExpansion, |
| 3875 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3876 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | if (ShouldExpand) { |
| 3880 | // Expand the function parameter pack into multiple, separate |
| 3881 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3882 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3883 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3884 | QualType NewType = getDerived().TransformType(Pattern); |
| 3885 | if (NewType.isNull()) |
| 3886 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3887 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3888 | OutParamTypes.push_back(NewType); |
| 3889 | if (PVars) |
| 3890 | PVars->push_back(0); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | // We're done with the pack expansion. |
| 3894 | continue; |
| 3895 | } |
| 3896 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3897 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3898 | // forgetting the partially-substituted parameter pack. |
| 3899 | if (RetainExpansion) { |
| 3900 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3901 | QualType NewType = getDerived().TransformType(Pattern); |
| 3902 | if (NewType.isNull()) |
| 3903 | return true; |
| 3904 | |
| 3905 | OutParamTypes.push_back(NewType); |
| 3906 | if (PVars) |
| 3907 | PVars->push_back(0); |
| 3908 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3909 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3910 | // We'll substitute the parameter now without expanding the pack |
| 3911 | // expansion. |
| 3912 | OldType = Expansion->getPattern(); |
| 3913 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3914 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3915 | NewType = getDerived().TransformType(OldType); |
| 3916 | } else { |
| 3917 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3920 | if (NewType.isNull()) |
| 3921 | return true; |
| 3922 | |
| 3923 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3924 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3925 | NumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3926 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3927 | OutParamTypes.push_back(NewType); |
| 3928 | if (PVars) |
| 3929 | PVars->push_back(0); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3932 | #ifndef NDEBUG |
| 3933 | if (PVars) { |
| 3934 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 3935 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 3936 | assert(parm->getFunctionScopeIndex() == i); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3937 | } |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 3938 | #endif |
| 3939 | |
| 3940 | return false; |
| 3941 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3942 | |
| 3943 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3945 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3946 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3947 | // Transform the parameters and return type. |
| 3948 | // |
| 3949 | // We instantiate in source order, with the return type first followed by |
| 3950 | // the parameters, because users tend to expect this (even if they shouldn't |
| 3951 | // rely on it!). |
| 3952 | // |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3953 | // When the function has a trailing return type, we instantiate the |
| 3954 | // parameters before the return type, since the return type can then refer |
| 3955 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 3956 | // |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3957 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3958 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3959 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3961 | QualType ResultType; |
| 3962 | |
| 3963 | if (TL.getTrailingReturn()) { |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3964 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3965 | TL.getParmArray(), |
| 3966 | TL.getNumArgs(), |
| 3967 | TL.getTypePtr()->arg_type_begin(), |
| 3968 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3969 | return QualType(); |
| 3970 | |
| 3971 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3972 | if (ResultType.isNull()) |
| 3973 | return QualType(); |
| 3974 | } |
| 3975 | else { |
| 3976 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3977 | if (ResultType.isNull()) |
| 3978 | return QualType(); |
| 3979 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3980 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3981 | TL.getParmArray(), |
| 3982 | TL.getNumArgs(), |
| 3983 | TL.getTypePtr()->arg_type_begin(), |
| 3984 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3985 | return QualType(); |
| 3986 | } |
| 3987 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3988 | QualType Result = TL.getType(); |
| 3989 | if (getDerived().AlwaysRebuild() || |
| 3990 | ResultType != T->getResultType() || |
Douglas Gregor | 9f627df | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 3991 | T->getNumArgs() != ParamTypes.size() || |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3992 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 3993 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 3994 | ParamTypes.data(), |
| 3995 | ParamTypes.size(), |
| 3996 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3997 | T->getTypeQuals(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3998 | T->getRefQualifier(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3999 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4000 | if (Result.isNull()) |
| 4001 | return QualType(); |
| 4002 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4003 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4004 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4005 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4006 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4007 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4008 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 4009 | NewTL.setArg(i, ParamDecls[i]); |
| 4010 | |
| 4011 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4012 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4014 | template<typename Derived> |
| 4015 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4016 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4017 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4018 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4019 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 4020 | if (ResultType.isNull()) |
| 4021 | return QualType(); |
| 4022 | |
| 4023 | QualType Result = TL.getType(); |
| 4024 | if (getDerived().AlwaysRebuild() || |
| 4025 | ResultType != T->getResultType()) |
| 4026 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 4027 | |
| 4028 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4029 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 4030 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4031 | NewTL.setTrailingReturn(false); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4032 | |
| 4033 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4035 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4036 | template<typename Derived> QualType |
| 4037 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4038 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4039 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4040 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4041 | if (!D) |
| 4042 | return QualType(); |
| 4043 | |
| 4044 | QualType Result = TL.getType(); |
| 4045 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 4046 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 4047 | if (Result.isNull()) |
| 4048 | return QualType(); |
| 4049 | } |
| 4050 | |
| 4051 | // We might get an arbitrary type spec type back. We should at |
| 4052 | // least always get a type spec type, though. |
| 4053 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 4054 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4055 | |
| 4056 | return Result; |
| 4057 | } |
| 4058 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4059 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4060 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4061 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4062 | const TypedefType *T = TL.getTypePtr(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 4063 | TypedefNameDecl *Typedef |
| 4064 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4065 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4066 | if (!Typedef) |
| 4067 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4069 | QualType Result = TL.getType(); |
| 4070 | if (getDerived().AlwaysRebuild() || |
| 4071 | Typedef != T->getDecl()) { |
| 4072 | Result = getDerived().RebuildTypedefType(Typedef); |
| 4073 | if (Result.isNull()) |
| 4074 | return QualType(); |
| 4075 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4077 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 4078 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4079 | |
| 4080 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4081 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4082 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4083 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4084 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4085 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4086 | // typeof expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4087 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4088 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4089 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4090 | if (E.isInvalid()) |
| 4091 | return QualType(); |
| 4092 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4093 | QualType Result = TL.getType(); |
| 4094 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4095 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4096 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4097 | if (Result.isNull()) |
| 4098 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4099 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4100 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4101 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4102 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4103 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4104 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4105 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4106 | |
| 4107 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
| 4110 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4111 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4112 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4113 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4114 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4115 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4116 | return QualType(); |
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 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4119 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4120 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4121 | if (Result.isNull()) |
| 4122 | return QualType(); |
| 4123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4124 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4125 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4126 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4127 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4128 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4129 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4130 | |
| 4131 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4132 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
| 4134 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4135 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4136 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4137 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4138 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4139 | // decltype expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4140 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4141 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4142 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4143 | if (E.isInvalid()) |
| 4144 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4146 | QualType Result = TL.getType(); |
| 4147 | if (getDerived().AlwaysRebuild() || |
| 4148 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4149 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4150 | if (Result.isNull()) |
| 4151 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4152 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4153 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4155 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4156 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4157 | |
| 4158 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4162 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4163 | AutoTypeLoc TL) { |
| 4164 | const AutoType *T = TL.getTypePtr(); |
| 4165 | QualType OldDeduced = T->getDeducedType(); |
| 4166 | QualType NewDeduced; |
| 4167 | if (!OldDeduced.isNull()) { |
| 4168 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4169 | if (NewDeduced.isNull()) |
| 4170 | return QualType(); |
| 4171 | } |
| 4172 | |
| 4173 | QualType Result = TL.getType(); |
| 4174 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4175 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4176 | if (Result.isNull()) |
| 4177 | return QualType(); |
| 4178 | } |
| 4179 | |
| 4180 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4181 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4182 | |
| 4183 | return Result; |
| 4184 | } |
| 4185 | |
| 4186 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4187 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4188 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4189 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4190 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4191 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4192 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4193 | if (!Record) |
| 4194 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4196 | QualType Result = TL.getType(); |
| 4197 | if (getDerived().AlwaysRebuild() || |
| 4198 | Record != T->getDecl()) { |
| 4199 | Result = getDerived().RebuildRecordType(Record); |
| 4200 | if (Result.isNull()) |
| 4201 | return QualType(); |
| 4202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4204 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4205 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4206 | |
| 4207 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | |
| 4210 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4211 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4212 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4213 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4214 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4215 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4216 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4217 | if (!Enum) |
| 4218 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4219 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4220 | QualType Result = TL.getType(); |
| 4221 | if (getDerived().AlwaysRebuild() || |
| 4222 | Enum != T->getDecl()) { |
| 4223 | Result = getDerived().RebuildEnumType(Enum); |
| 4224 | if (Result.isNull()) |
| 4225 | return QualType(); |
| 4226 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4227 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4228 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4229 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4230 | |
| 4231 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4232 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4233 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4234 | template<typename Derived> |
| 4235 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4236 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4237 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4238 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4239 | TL.getTypePtr()->getDecl()); |
| 4240 | if (!D) return QualType(); |
| 4241 | |
| 4242 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4243 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4244 | return T; |
| 4245 | } |
| 4246 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4247 | template<typename Derived> |
| 4248 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
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 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4251 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4255 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4256 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4257 | SubstTemplateTypeParmTypeLoc TL) { |
Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 4258 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| 4259 | |
| 4260 | // Substitute into the replacement type, which itself might involve something |
| 4261 | // that needs to be transformed. This only tends to occur with default |
| 4262 | // template arguments of template template parameters. |
| 4263 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 4264 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 4265 | if (Replacement.isNull()) |
| 4266 | return QualType(); |
| 4267 | |
| 4268 | // Always canonicalize the replacement type. |
| 4269 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 4270 | QualType Result |
| 4271 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| 4272 | Replacement); |
| 4273 | |
| 4274 | // Propagate type-source information. |
| 4275 | SubstTemplateTypeParmTypeLoc NewTL |
| 4276 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 4277 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4278 | return Result; |
| 4279 | |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4283 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4284 | TypeLocBuilder &TLB, |
| 4285 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4286 | return TransformTypeSpecType(TLB, TL); |
| 4287 | } |
| 4288 | |
| 4289 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4290 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4291 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4292 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4293 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4294 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4295 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4296 | // because we can't have a dependent nested-name-specifier anyway. |
| 4297 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4298 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4299 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4300 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4301 | if (Template.isNull()) |
| 4302 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4304 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4305 | } |
| 4306 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4307 | namespace { |
| 4308 | /// \brief Simple iterator that traverses the template arguments in a |
| 4309 | /// container that provides a \c getArgLoc() member function. |
| 4310 | /// |
| 4311 | /// This iterator is intended to be used with the iterator form of |
| 4312 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4313 | template<typename ArgLocContainer> |
| 4314 | class TemplateArgumentLocContainerIterator { |
| 4315 | ArgLocContainer *Container; |
| 4316 | unsigned Index; |
| 4317 | |
| 4318 | public: |
| 4319 | typedef TemplateArgumentLoc value_type; |
| 4320 | typedef TemplateArgumentLoc reference; |
| 4321 | typedef int difference_type; |
| 4322 | typedef std::input_iterator_tag iterator_category; |
| 4323 | |
| 4324 | class pointer { |
| 4325 | TemplateArgumentLoc Arg; |
| 4326 | |
| 4327 | public: |
| 4328 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4329 | |
| 4330 | const TemplateArgumentLoc *operator->() const { |
| 4331 | return &Arg; |
| 4332 | } |
| 4333 | }; |
| 4334 | |
| 4335 | |
| 4336 | TemplateArgumentLocContainerIterator() {} |
| 4337 | |
| 4338 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4339 | unsigned Index) |
| 4340 | : Container(&Container), Index(Index) { } |
| 4341 | |
| 4342 | TemplateArgumentLocContainerIterator &operator++() { |
| 4343 | ++Index; |
| 4344 | return *this; |
| 4345 | } |
| 4346 | |
| 4347 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4348 | TemplateArgumentLocContainerIterator Old(*this); |
| 4349 | ++(*this); |
| 4350 | return Old; |
| 4351 | } |
| 4352 | |
| 4353 | TemplateArgumentLoc operator*() const { |
| 4354 | return Container->getArgLoc(Index); |
| 4355 | } |
| 4356 | |
| 4357 | pointer operator->() const { |
| 4358 | return pointer(Container->getArgLoc(Index)); |
| 4359 | } |
| 4360 | |
| 4361 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4362 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4363 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4364 | } |
| 4365 | |
| 4366 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4367 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4368 | return !(X == Y); |
| 4369 | } |
| 4370 | }; |
| 4371 | } |
| 4372 | |
| 4373 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4374 | template <typename Derived> |
| 4375 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4376 | TypeLocBuilder &TLB, |
| 4377 | TemplateSpecializationTypeLoc TL, |
| 4378 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4379 | TemplateArgumentListInfo NewTemplateArgs; |
| 4380 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4381 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4382 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4383 | ArgIterator; |
| 4384 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4385 | ArgIterator(TL, TL.getNumArgs()), |
| 4386 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4387 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4389 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4390 | |
| 4391 | QualType Result = |
| 4392 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4393 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4394 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4395 | |
| 4396 | if (!Result.isNull()) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4397 | // Specializations of template template parameters are represented as |
| 4398 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 4399 | // within a dependent context can transform them into |
| 4400 | // DependentTemplateSpecializationTypes. |
| 4401 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4402 | DependentTemplateSpecializationTypeLoc NewTL |
| 4403 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4404 | NewTL.setKeywordLoc(TL.getTemplateNameLoc()); |
| 4405 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
| 4406 | NewTL.setNameLoc(TL.getTemplateNameLoc()); |
| 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 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4414 | TemplateSpecializationTypeLoc NewTL |
| 4415 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4416 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4417 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4418 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4419 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4420 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4423 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4426 | template <typename Derived> |
| 4427 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4428 | TypeLocBuilder &TLB, |
| 4429 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4430 | TemplateName Template, |
| 4431 | CXXScopeSpec &SS) { |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4432 | TemplateArgumentListInfo NewTemplateArgs; |
| 4433 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4434 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4435 | typedef TemplateArgumentLocContainerIterator< |
| 4436 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4437 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4438 | ArgIterator(TL, TL.getNumArgs()), |
| 4439 | NewTemplateArgs)) |
| 4440 | return QualType(); |
| 4441 | |
| 4442 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4443 | |
| 4444 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4445 | QualType Result |
| 4446 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4447 | TL.getTypePtr()->getKeyword(), |
| 4448 | DTN->getQualifier(), |
| 4449 | DTN->getIdentifier(), |
| 4450 | NewTemplateArgs); |
| 4451 | |
| 4452 | DependentTemplateSpecializationTypeLoc NewTL |
| 4453 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4454 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4456 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4457 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4458 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4459 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4460 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4461 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4462 | return Result; |
| 4463 | } |
| 4464 | |
| 4465 | QualType Result |
| 4466 | = getDerived().RebuildTemplateSpecializationType(Template, |
| 4467 | TL.getNameLoc(), |
| 4468 | NewTemplateArgs); |
| 4469 | |
| 4470 | if (!Result.isNull()) { |
| 4471 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4472 | TemplateSpecializationTypeLoc NewTL |
| 4473 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4474 | NewTL.setTemplateNameLoc(TL.getNameLoc()); |
| 4475 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4476 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4477 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4478 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4479 | } |
| 4480 | |
| 4481 | return Result; |
| 4482 | } |
| 4483 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4485 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4486 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4487 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4488 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4489 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4490 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4491 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4492 | if (TL.getQualifierLoc()) { |
| 4493 | QualifierLoc |
| 4494 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4495 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4496 | return QualType(); |
| 4497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4498 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4499 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4500 | if (NamedT.isNull()) |
| 4501 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4502 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4503 | // C++0x [dcl.type.elab]p2: |
| 4504 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 4505 | // resolves to an alias template specialization, the |
| 4506 | // elaborated-type-specifier is ill-formed. |
| 4507 | if (const TemplateSpecializationType *TST = |
| 4508 | NamedT->getAs<TemplateSpecializationType>()) { |
| 4509 | TemplateName Template = TST->getTemplateName(); |
| 4510 | if (TypeAliasTemplateDecl *TAT = |
| 4511 | dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { |
| 4512 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 4513 | diag::err_tag_reference_non_tag) << 4; |
| 4514 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 4515 | } |
| 4516 | } |
| 4517 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4518 | QualType Result = TL.getType(); |
| 4519 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4520 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4521 | NamedT != T->getNamedType()) { |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4522 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4523 | T->getKeyword(), |
| 4524 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4525 | if (Result.isNull()) |
| 4526 | return QualType(); |
| 4527 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4528 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4529 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4530 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4531 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4532 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4533 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4534 | |
| 4535 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4536 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4537 | TypeLocBuilder &TLB, |
| 4538 | AttributedTypeLoc TL) { |
| 4539 | const AttributedType *oldType = TL.getTypePtr(); |
| 4540 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4541 | if (modifiedType.isNull()) |
| 4542 | return QualType(); |
| 4543 | |
| 4544 | QualType result = TL.getType(); |
| 4545 | |
| 4546 | // FIXME: dependent operand expressions? |
| 4547 | if (getDerived().AlwaysRebuild() || |
| 4548 | modifiedType != oldType->getModifiedType()) { |
| 4549 | // TODO: this is really lame; we should really be rebuilding the |
| 4550 | // equivalent type from first principles. |
| 4551 | QualType equivalentType |
| 4552 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4553 | if (equivalentType.isNull()) |
| 4554 | return QualType(); |
| 4555 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4556 | modifiedType, |
| 4557 | equivalentType); |
| 4558 | } |
| 4559 | |
| 4560 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4561 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4562 | if (TL.hasAttrOperand()) |
| 4563 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4564 | if (TL.hasAttrExprOperand()) |
| 4565 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4566 | else if (TL.hasAttrEnumOperand()) |
| 4567 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4568 | |
| 4569 | return result; |
| 4570 | } |
| 4571 | |
| 4572 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4573 | QualType |
| 4574 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4575 | ParenTypeLoc TL) { |
| 4576 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4577 | if (Inner.isNull()) |
| 4578 | return QualType(); |
| 4579 | |
| 4580 | QualType Result = TL.getType(); |
| 4581 | if (getDerived().AlwaysRebuild() || |
| 4582 | Inner != TL.getInnerLoc().getType()) { |
| 4583 | Result = getDerived().RebuildParenType(Inner); |
| 4584 | if (Result.isNull()) |
| 4585 | return QualType(); |
| 4586 | } |
| 4587 | |
| 4588 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4589 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4590 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4591 | return Result; |
| 4592 | } |
| 4593 | |
| 4594 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4595 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4596 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4597 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4598 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4599 | NestedNameSpecifierLoc QualifierLoc |
| 4600 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4601 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4602 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4604 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4605 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4606 | TL.getKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4607 | QualifierLoc, |
| 4608 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4609 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4610 | if (Result.isNull()) |
| 4611 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4612 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4613 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4614 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4615 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4616 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4617 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4618 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4619 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4620 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4621 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4622 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4623 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4624 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4625 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4626 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4628 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4629 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4630 | QualType TreeTransform<Derived>:: |
| 4631 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4632 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4633 | NestedNameSpecifierLoc QualifierLoc; |
| 4634 | if (TL.getQualifierLoc()) { |
| 4635 | QualifierLoc |
| 4636 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4637 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4638 | return QualType(); |
| 4639 | } |
| 4640 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4641 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4642 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | template<typename Derived> |
| 4646 | QualType TreeTransform<Derived>:: |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4647 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4648 | DependentTemplateSpecializationTypeLoc TL, |
| 4649 | NestedNameSpecifierLoc QualifierLoc) { |
| 4650 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 4651 | |
| 4652 | TemplateArgumentListInfo NewTemplateArgs; |
| 4653 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4654 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4655 | |
| 4656 | typedef TemplateArgumentLocContainerIterator< |
| 4657 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4658 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4659 | ArgIterator(TL, TL.getNumArgs()), |
| 4660 | NewTemplateArgs)) |
| 4661 | return QualType(); |
| 4662 | |
| 4663 | QualType Result |
| 4664 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4665 | QualifierLoc, |
| 4666 | T->getIdentifier(), |
| 4667 | TL.getNameLoc(), |
| 4668 | NewTemplateArgs); |
| 4669 | if (Result.isNull()) |
| 4670 | return QualType(); |
| 4671 | |
| 4672 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4673 | QualType NamedT = ElabT->getNamedType(); |
| 4674 | |
| 4675 | // Copy information relevant to the template specialization. |
| 4676 | TemplateSpecializationTypeLoc NamedTL |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4677 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
Chandler Carruth | 3d7e3da | 2011-04-01 02:03:23 +0000 | [diff] [blame] | 4678 | NamedTL.setTemplateNameLoc(TL.getNameLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4679 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4680 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4681 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4682 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4683 | |
| 4684 | // Copy information relevant to the elaborated type. |
| 4685 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4686 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4687 | NewTL.setQualifierLoc(QualifierLoc); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4688 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 4689 | DependentTemplateSpecializationTypeLoc SpecTL |
| 4690 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4691 | SpecTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4692 | SpecTL.setQualifierLoc(QualifierLoc); |
Chandler Carruth | 3d7e3da | 2011-04-01 02:03:23 +0000 | [diff] [blame] | 4693 | SpecTL.setNameLoc(TL.getNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4694 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4695 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4696 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4697 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4698 | } else { |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4699 | TemplateSpecializationTypeLoc SpecTL |
| 4700 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
Chandler Carruth | 3d7e3da | 2011-04-01 02:03:23 +0000 | [diff] [blame] | 4701 | SpecTL.setTemplateNameLoc(TL.getNameLoc()); |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4702 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4703 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 4704 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 4705 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4706 | } |
| 4707 | return Result; |
| 4708 | } |
| 4709 | |
| 4710 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4711 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4712 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4713 | QualType Pattern |
| 4714 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4715 | if (Pattern.isNull()) |
| 4716 | return QualType(); |
| 4717 | |
| 4718 | QualType Result = TL.getType(); |
| 4719 | if (getDerived().AlwaysRebuild() || |
| 4720 | Pattern != TL.getPatternLoc().getType()) { |
| 4721 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4722 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4723 | TL.getEllipsisLoc(), |
| 4724 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4725 | if (Result.isNull()) |
| 4726 | return QualType(); |
| 4727 | } |
| 4728 | |
| 4729 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4730 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4731 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4735 | QualType |
| 4736 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4737 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4738 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4739 | TLB.pushFullCopy(TL); |
| 4740 | return TL.getType(); |
| 4741 | } |
| 4742 | |
| 4743 | template<typename Derived> |
| 4744 | QualType |
| 4745 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4746 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4747 | // ObjCObjectType is never dependent. |
| 4748 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4749 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4750 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4751 | |
| 4752 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4753 | QualType |
| 4754 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4755 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4756 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4757 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4758 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4761 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4762 | // Statement transformation |
| 4763 | //===----------------------------------------------------------------------===// |
| 4764 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4765 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4766 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4767 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4771 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4772 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4773 | return getDerived().TransformCompoundStmt(S, false); |
| 4774 | } |
| 4775 | |
| 4776 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4777 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4778 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4779 | bool IsStmtExpr) { |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4780 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4781 | bool SubStmtChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4782 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4783 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4784 | B != BEnd; ++B) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4785 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4786 | if (Result.isInvalid()) { |
| 4787 | // Immediately fail if this was a DeclStmt, since it's very |
| 4788 | // likely that this will cause problems for future statements. |
| 4789 | if (isa<DeclStmt>(*B)) |
| 4790 | return StmtError(); |
| 4791 | |
| 4792 | // Otherwise, just keep processing substatements and fail later. |
| 4793 | SubStmtInvalid = true; |
| 4794 | continue; |
| 4795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4797 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4798 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4799 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4800 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4801 | if (SubStmtInvalid) |
| 4802 | return StmtError(); |
| 4803 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4804 | if (!getDerived().AlwaysRebuild() && |
| 4805 | !SubStmtChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4806 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4807 | |
| 4808 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4809 | move_arg(Statements), |
| 4810 | S->getRBracLoc(), |
| 4811 | IsStmtExpr); |
| 4812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4814 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4815 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4817 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4818 | { |
| 4819 | // The case value expressions are not potentially evaluated. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4820 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4822 | // Transform the left-hand case value. |
| 4823 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4824 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4825 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4826 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4827 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4828 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4829 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4830 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4833 | // Build the case statement. |
| 4834 | // Case statements are always rebuilt so that they will attached to their |
| 4835 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4836 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4837 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4838 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4839 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4840 | S->getColonLoc()); |
| 4841 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4842 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4844 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4845 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4846 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4847 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4848 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4849 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4850 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4851 | } |
| 4852 | |
| 4853 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4854 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4855 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4856 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4857 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4858 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4859 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4861 | // Default statements are always rebuilt |
| 4862 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4863 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4864 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4866 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4867 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4868 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4869 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4870 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4871 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4872 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4873 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 4874 | S->getDecl()); |
| 4875 | if (!LD) |
| 4876 | return StmtError(); |
| 4877 | |
| 4878 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4879 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 4880 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4881 | cast<LabelDecl>(LD), SourceLocation(), |
| 4882 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +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 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4886 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4887 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4888 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4889 | ExprResult Cond; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4890 | VarDecl *ConditionVar = 0; |
| 4891 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4892 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4893 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4894 | getDerived().TransformDefinition( |
| 4895 | S->getConditionVariable()->getLocation(), |
| 4896 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4897 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4898 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4899 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4900 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4902 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4903 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4904 | |
| 4905 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4906 | if (S->getCond()) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4907 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 4908 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4909 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4910 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4911 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4912 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4913 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4914 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4915 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4916 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4917 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4918 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4919 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4920 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4921 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4922 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4923 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4924 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4925 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4926 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4927 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4928 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4930 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4931 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4932 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4933 | Then.get() == S->getThen() && |
| 4934 | Else.get() == S->getElse()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4935 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4936 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4937 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 4938 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4939 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4943 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4944 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4945 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4946 | ExprResult Cond; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4947 | VarDecl *ConditionVar = 0; |
| 4948 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4949 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4950 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4951 | getDerived().TransformDefinition( |
| 4952 | S->getConditionVariable()->getLocation(), |
| 4953 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4954 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4955 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4956 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4957 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4958 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4959 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4960 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4963 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4964 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4965 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 4966 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4967 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4968 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4969 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4970 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4971 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4972 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4973 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4974 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4975 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4976 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 4977 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4980 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4981 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4982 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4983 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4984 | ExprResult Cond; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4985 | VarDecl *ConditionVar = 0; |
| 4986 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4987 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4988 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4989 | getDerived().TransformDefinition( |
| 4990 | S->getConditionVariable()->getLocation(), |
| 4991 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4992 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4993 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4994 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4995 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4996 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4997 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4998 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4999 | |
| 5000 | if (S->getCond()) { |
| 5001 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5002 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 5003 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5004 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5005 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5006 | Cond = CondE; |
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 body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5015 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5016 | if (Body.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 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5019 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5020 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5021 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5022 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5023 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5024 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5025 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5026 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5028 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5029 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5030 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5031 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5032 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5033 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5034 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5035 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5037 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5038 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5039 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5040 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5041 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5042 | if (!getDerived().AlwaysRebuild() && |
| 5043 | Cond.get() == S->getCond() && |
| 5044 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5045 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5047 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 5048 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5049 | S->getRParenLoc()); |
| 5050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5052 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5053 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5054 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5055 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5056 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5057 | if (Init.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 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5061 | ExprResult Cond; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5062 | VarDecl *ConditionVar = 0; |
| 5063 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5064 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5065 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5066 | getDerived().TransformDefinition( |
| 5067 | S->getConditionVariable()->getLocation(), |
| 5068 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5069 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5070 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5071 | } else { |
| 5072 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5073 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5074 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5075 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5076 | |
| 5077 | if (S->getCond()) { |
| 5078 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 5079 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 5080 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5081 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5082 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5083 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5084 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 5085 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 5086 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5088 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 5089 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5090 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5091 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5092 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5093 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5094 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5095 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5096 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5097 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 5098 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5099 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 5100 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5101 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5102 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5103 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5104 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5105 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5106 | if (!getDerived().AlwaysRebuild() && |
| 5107 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5108 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5109 | Inc.get() == S->getInc() && |
| 5110 | Body.get() == S->getBody()) |
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 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5113 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5114 | Init.get(), FullCond, ConditionVar, |
| 5115 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5119 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5120 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5121 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5122 | S->getLabel()); |
| 5123 | if (!LD) |
| 5124 | return StmtError(); |
| 5125 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5126 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5127 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5128 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5132 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5133 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5134 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5135 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5136 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5138 | if (!getDerived().AlwaysRebuild() && |
| 5139 | Target.get() == S->getTarget()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5140 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5141 | |
| 5142 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5143 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5147 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5148 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5149 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5151 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5152 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5153 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5155 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5157 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5158 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5159 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5161 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5162 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5163 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5164 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5165 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5166 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5167 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5170 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5171 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5173 | bool DeclChanged = false; |
| 5174 | llvm::SmallVector<Decl *, 4> Decls; |
| 5175 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5176 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5177 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5178 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5179 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5180 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5181 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5182 | if (Transformed != *D) |
| 5183 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5184 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5185 | Decls.push_back(Transformed); |
| 5186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5188 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5189 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | |
| 5191 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5192 | S->getStartLoc(), S->getEndLoc()); |
| 5193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5195 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5196 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5197 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5198 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5199 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5200 | ASTOwningVector<Expr*> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5201 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5202 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5203 | ExprResult AsmString; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5204 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5205 | |
| 5206 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5207 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5208 | // Go through the outputs. |
| 5209 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5210 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5211 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5212 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5213 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5214 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5215 | // Transform the output expr. |
| 5216 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5217 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5218 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5219 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5220 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5221 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5222 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5223 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5224 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5225 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5226 | // Go through the inputs. |
| 5227 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5228 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5229 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5230 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5231 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5232 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5233 | // Transform the input expr. |
| 5234 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5235 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5236 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5237 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5238 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5239 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5240 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5241 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5242 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5243 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5244 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5245 | return SemaRef.Owned(S); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5246 | |
| 5247 | // Go through the clobbers. |
| 5248 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5249 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5250 | |
| 5251 | // No need to transform the asm string literal. |
| 5252 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5253 | |
| 5254 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5255 | S->isSimple(), |
| 5256 | S->isVolatile(), |
| 5257 | S->getNumOutputs(), |
| 5258 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5259 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5260 | move_arg(Constraints), |
| 5261 | move_arg(Exprs), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5262 | AsmString.get(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5263 | move_arg(Clobbers), |
| 5264 | S->getRParenLoc(), |
| 5265 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | |
| 5269 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5270 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5272 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5273 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5274 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5275 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5276 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5277 | // Transform the @catch statements (if present). |
| 5278 | bool AnyCatchChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5279 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5280 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5281 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5282 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5283 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5284 | if (Catch.get() != S->getCatchStmt(I)) |
| 5285 | AnyCatchChanged = true; |
| 5286 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5287 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5288 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5289 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5290 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5291 | if (S->getFinallyStmt()) { |
| 5292 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5293 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5294 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | // If nothing changed, just retain this statement. |
| 5298 | if (!getDerived().AlwaysRebuild() && |
| 5299 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5300 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5301 | Finally.get() == S->getFinallyStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5302 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5303 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5304 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5305 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5306 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5308 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5309 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5310 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5312 | // Transform the @catch parameter, if there is one. |
| 5313 | VarDecl *Var = 0; |
| 5314 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5315 | TypeSourceInfo *TSInfo = 0; |
| 5316 | if (FromVar->getTypeSourceInfo()) { |
| 5317 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5318 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5319 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5320 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5321 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5322 | QualType T; |
| 5323 | if (TSInfo) |
| 5324 | T = TSInfo->getType(); |
| 5325 | else { |
| 5326 | T = getDerived().TransformType(FromVar->getType()); |
| 5327 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5328 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5329 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5330 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5331 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5332 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5333 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5334 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5335 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5336 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5337 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5338 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5339 | |
| 5340 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5341 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5342 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5345 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5346 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5347 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5348 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5349 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5350 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5351 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5352 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5353 | // If nothing changed, just retain this statement. |
| 5354 | if (!getDerived().AlwaysRebuild() && |
| 5355 | Body.get() == S->getFinallyBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5356 | return SemaRef.Owned(S); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5357 | |
| 5358 | // Build a new statement. |
| 5359 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5360 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5362 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5363 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5364 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5365 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5366 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5367 | if (S->getThrowExpr()) { |
| 5368 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5369 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5370 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5371 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5372 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5373 | if (!getDerived().AlwaysRebuild() && |
| 5374 | Operand.get() == S->getThrowExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5375 | return getSema().Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5376 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5377 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5379 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5380 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5381 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5382 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5383 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5384 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5385 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5386 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5387 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5388 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5389 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5390 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5391 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5392 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5393 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5394 | // If nothing change, just retain the current statement. |
| 5395 | if (!getDerived().AlwaysRebuild() && |
| 5396 | Object.get() == S->getSynchExpr() && |
| 5397 | Body.get() == S->getSynchBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5398 | return SemaRef.Owned(S); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5399 | |
| 5400 | // Build a new statement. |
| 5401 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5402 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5406 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5407 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5408 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5409 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5410 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5411 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5412 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5413 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5414 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5415 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5416 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5417 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5419 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5420 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5421 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5422 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5423 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5424 | // If nothing changed, just retain this statement. |
| 5425 | if (!getDerived().AlwaysRebuild() && |
| 5426 | Element.get() == S->getElement() && |
| 5427 | Collection.get() == S->getCollection() && |
| 5428 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5429 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5430 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5431 | // Build a new statement. |
| 5432 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5433 | /*FIXME:*/S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5434 | Element.get(), |
| 5435 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5436 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5437 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | |
| 5441 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5442 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5443 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5444 | // Transform the exception declaration, if any. |
| 5445 | VarDecl *Var = 0; |
| 5446 | if (S->getExceptionDecl()) { |
| 5447 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5448 | TypeSourceInfo *T = getDerived().TransformType( |
| 5449 | ExceptionDecl->getTypeSourceInfo()); |
| 5450 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5451 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5453 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 5454 | ExceptionDecl->getInnerLocStart(), |
| 5455 | ExceptionDecl->getLocation(), |
| 5456 | ExceptionDecl->getIdentifier()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5457 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5458 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5459 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5461 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5462 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5463 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5464 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5466 | if (!getDerived().AlwaysRebuild() && |
| 5467 | !Var && |
| 5468 | Handler.get() == S->getHandlerBlock()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5469 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5470 | |
| 5471 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5472 | Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5473 | Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5475 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5476 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5477 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5478 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5479 | // Transform the try block itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5480 | StmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5481 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5482 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5483 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5484 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5485 | // Transform the handlers. |
| 5486 | bool HandlerChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5487 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5488 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5489 | StmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5490 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5491 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5492 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5494 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5495 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5496 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5497 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5498 | if (!getDerived().AlwaysRebuild() && |
| 5499 | TryBlock.get() == S->getTryBlock() && |
| 5500 | !HandlerChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5501 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5502 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5503 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 5507 | template<typename Derived> |
| 5508 | StmtResult |
| 5509 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5510 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 5511 | if (Range.isInvalid()) |
| 5512 | return StmtError(); |
| 5513 | |
| 5514 | StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); |
| 5515 | if (BeginEnd.isInvalid()) |
| 5516 | return StmtError(); |
| 5517 | |
| 5518 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 5519 | if (Cond.isInvalid()) |
| 5520 | return StmtError(); |
| 5521 | |
| 5522 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 5523 | if (Inc.isInvalid()) |
| 5524 | return StmtError(); |
| 5525 | |
| 5526 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 5527 | if (LoopVar.isInvalid()) |
| 5528 | return StmtError(); |
| 5529 | |
| 5530 | StmtResult NewStmt = S; |
| 5531 | if (getDerived().AlwaysRebuild() || |
| 5532 | Range.get() != S->getRangeStmt() || |
| 5533 | BeginEnd.get() != S->getBeginEndStmt() || |
| 5534 | Cond.get() != S->getCond() || |
| 5535 | Inc.get() != S->getInc() || |
| 5536 | LoopVar.get() != S->getLoopVarStmt()) |
| 5537 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5538 | S->getColonLoc(), Range.get(), |
| 5539 | BeginEnd.get(), Cond.get(), |
| 5540 | Inc.get(), LoopVar.get(), |
| 5541 | S->getRParenLoc()); |
| 5542 | |
| 5543 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 5544 | if (Body.isInvalid()) |
| 5545 | return StmtError(); |
| 5546 | |
| 5547 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 5548 | // it now so we have a new statement to attach the body to. |
| 5549 | if (Body.get() != S->getBody() && NewStmt.get() == S) |
| 5550 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 5551 | S->getColonLoc(), Range.get(), |
| 5552 | BeginEnd.get(), Cond.get(), |
| 5553 | Inc.get(), LoopVar.get(), |
| 5554 | S->getRParenLoc()); |
| 5555 | |
| 5556 | if (NewStmt.get() == S) |
| 5557 | return SemaRef.Owned(S); |
| 5558 | |
| 5559 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 5560 | } |
| 5561 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 5562 | template<typename Derived> |
| 5563 | StmtResult |
| 5564 | TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 5565 | StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5566 | if(TryBlock.isInvalid()) return StmtError(); |
| 5567 | |
| 5568 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 5569 | if(!getDerived().AlwaysRebuild() && |
| 5570 | TryBlock.get() == S->getTryBlock() && |
| 5571 | Handler.get() == S->getHandler()) |
| 5572 | return SemaRef.Owned(S); |
| 5573 | |
| 5574 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), |
| 5575 | S->getTryLoc(), |
| 5576 | TryBlock.take(), |
| 5577 | Handler.take()); |
| 5578 | } |
| 5579 | |
| 5580 | template<typename Derived> |
| 5581 | StmtResult |
| 5582 | TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 5583 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5584 | if(Block.isInvalid()) return StmtError(); |
| 5585 | |
| 5586 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), |
| 5587 | Block.take()); |
| 5588 | } |
| 5589 | |
| 5590 | template<typename Derived> |
| 5591 | StmtResult |
| 5592 | TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 5593 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 5594 | if(FilterExpr.isInvalid()) return StmtError(); |
| 5595 | |
| 5596 | StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); |
| 5597 | if(Block.isInvalid()) return StmtError(); |
| 5598 | |
| 5599 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), |
| 5600 | FilterExpr.take(), |
| 5601 | Block.take()); |
| 5602 | } |
| 5603 | |
| 5604 | template<typename Derived> |
| 5605 | StmtResult |
| 5606 | TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 5607 | if(isa<SEHFinallyStmt>(Handler)) |
| 5608 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 5609 | else |
| 5610 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 5611 | } |
| 5612 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5613 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5614 | // Expression transformation |
| 5615 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5617 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5618 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5619 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5620 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5621 | |
| 5622 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5623 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5624 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5625 | NestedNameSpecifierLoc QualifierLoc; |
| 5626 | if (E->getQualifierLoc()) { |
| 5627 | QualifierLoc |
| 5628 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5629 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5630 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5631 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5632 | |
| 5633 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5634 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5635 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5636 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5637 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5638 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5639 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5640 | if (NameInfo.getName()) { |
| 5641 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5642 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5643 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5644 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5645 | |
| 5646 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5647 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5648 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5649 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5650 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5651 | |
| 5652 | // Mark it referenced in the new context regardless. |
| 5653 | // FIXME: this is a bit instantiation-specific. |
| 5654 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5655 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5656 | return SemaRef.Owned(E); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5657 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5658 | |
| 5659 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5660 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5661 | TemplateArgs = &TransArgs; |
| 5662 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5663 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5664 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5665 | E->getNumTemplateArgs(), |
| 5666 | TransArgs)) |
| 5667 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5668 | } |
| 5669 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5670 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 5671 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5673 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5674 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5675 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5676 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5677 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5680 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5681 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5682 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5683 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5687 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5688 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5689 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5692 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5693 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5694 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5695 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5696 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5698 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5699 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5700 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
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 | } |
| 5703 | |
| 5704 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5705 | ExprResult |
Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 5706 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 5707 | ExprResult ControllingExpr = |
| 5708 | getDerived().TransformExpr(E->getControllingExpr()); |
| 5709 | if (ControllingExpr.isInvalid()) |
| 5710 | return ExprError(); |
| 5711 | |
| 5712 | llvm::SmallVector<Expr *, 4> AssocExprs; |
| 5713 | llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes; |
| 5714 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 5715 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 5716 | if (TS) { |
| 5717 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 5718 | if (!AssocType) |
| 5719 | return ExprError(); |
| 5720 | AssocTypes.push_back(AssocType); |
| 5721 | } else { |
| 5722 | AssocTypes.push_back(0); |
| 5723 | } |
| 5724 | |
| 5725 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 5726 | if (AssocExpr.isInvalid()) |
| 5727 | return ExprError(); |
| 5728 | AssocExprs.push_back(AssocExpr.release()); |
| 5729 | } |
| 5730 | |
| 5731 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 5732 | E->getDefaultLoc(), |
| 5733 | E->getRParenLoc(), |
| 5734 | ControllingExpr.release(), |
| 5735 | AssocTypes.data(), |
| 5736 | AssocExprs.data(), |
| 5737 | E->getNumAssocs()); |
| 5738 | } |
| 5739 | |
| 5740 | template<typename Derived> |
| 5741 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5742 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5743 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5744 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5745 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5746 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5747 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5748 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5749 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5750 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5751 | E->getRParen()); |
| 5752 | } |
| 5753 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5755 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5756 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5757 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5758 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5759 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5760 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5761 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5762 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5764 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5765 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5766 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5769 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5770 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5771 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5772 | // Transform the type. |
| 5773 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5774 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5775 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5776 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5777 | // Transform all of the components into components similar to what the |
| 5778 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5779 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5780 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5781 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5782 | // template code that we don't care. |
| 5783 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5784 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5785 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 5786 | llvm::SmallVector<Component, 4> Components; |
| 5787 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5788 | const Node &ON = E->getComponent(I); |
| 5789 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5790 | Comp.isBrackets = true; |
Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 5791 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 5792 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5793 | switch (ON.getKind()) { |
| 5794 | case Node::Array: { |
| 5795 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5796 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5797 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5798 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5799 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5800 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5801 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5802 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5803 | break; |
| 5804 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5805 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5806 | case Node::Field: |
| 5807 | case Node::Identifier: |
| 5808 | Comp.isBrackets = false; |
| 5809 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5810 | if (!Comp.U.IdentInfo) |
| 5811 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5812 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5813 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5814 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5815 | case Node::Base: |
| 5816 | // Will be recomputed during the rebuild. |
| 5817 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5818 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5819 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5820 | Components.push_back(Comp); |
| 5821 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5822 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5823 | // If nothing changed, retain the existing expression. |
| 5824 | if (!getDerived().AlwaysRebuild() && |
| 5825 | Type == E->getTypeSourceInfo() && |
| 5826 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5827 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5828 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5829 | // Build a new offsetof expression. |
| 5830 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5831 | Components.data(), Components.size(), |
| 5832 | E->getRParenLoc()); |
| 5833 | } |
| 5834 | |
| 5835 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5836 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5837 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5838 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5839 | "opaque value expression requires transformation"); |
| 5840 | return SemaRef.Owned(E); |
| 5841 | } |
| 5842 | |
| 5843 | template<typename Derived> |
| 5844 | ExprResult |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5845 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 5846 | UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5847 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5848 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5849 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5850 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5851 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5852 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5853 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5854 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5855 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5856 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5857 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 5858 | E->getKind(), |
| 5859 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5860 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5861 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5862 | ExprResult SubExpr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5863 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5864 | // C++0x [expr.sizeof]p1: |
| 5865 | // The operand is either an expression, which is an unevaluated operand |
| 5866 | // [...] |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5867 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5868 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5869 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5870 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5871 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5873 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5874 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5876 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5877 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 5878 | E->getOperatorLoc(), |
| 5879 | E->getKind(), |
| 5880 | E->getSourceRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5881 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5882 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5883 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5884 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5885 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5886 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5887 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5888 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5889 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5890 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5891 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5892 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5893 | |
| 5894 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5895 | if (!getDerived().AlwaysRebuild() && |
| 5896 | LHS.get() == E->getLHS() && |
| 5897 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5898 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5899 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5900 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5901 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5902 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5903 | E->getRBracketLoc()); |
| 5904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5905 | |
| 5906 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5907 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5908 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5909 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5910 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5911 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5912 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5913 | |
| 5914 | // Transform arguments. |
| 5915 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5916 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5917 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5918 | &ArgChanged)) |
| 5919 | return ExprError(); |
| 5920 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5921 | if (!getDerived().AlwaysRebuild() && |
| 5922 | Callee.get() == E->getCallee() && |
| 5923 | !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5924 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5925 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5926 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5927 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5928 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5929 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5930 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5931 | E->getRParenLoc()); |
| 5932 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5933 | |
| 5934 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5935 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5936 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5937 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5938 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5939 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5940 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5941 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5942 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5943 | QualifierLoc |
| 5944 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5945 | |
| 5946 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5947 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5949 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 5950 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5951 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 5952 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5953 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5954 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5955 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5956 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 5957 | if (FoundDecl == E->getMemberDecl()) { |
| 5958 | FoundDecl = Member; |
| 5959 | } else { |
| 5960 | FoundDecl = cast_or_null<NamedDecl>( |
| 5961 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 5962 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5963 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5966 | if (!getDerived().AlwaysRebuild() && |
| 5967 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5968 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5969 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5970 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5971 | !E->hasExplicitTemplateArgs()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5972 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5973 | // Mark it referenced in the new context regardless. |
| 5974 | // FIXME: this is a bit instantiation-specific. |
| 5975 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5976 | return SemaRef.Owned(E); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5977 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5978 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5979 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5980 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5981 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5982 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5983 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5984 | E->getNumTemplateArgs(), |
| 5985 | TransArgs)) |
| 5986 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5987 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5989 | // FIXME: Bogus source location for the operator |
| 5990 | SourceLocation FakeOperatorLoc |
| 5991 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 5992 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5993 | // FIXME: to do this check properly, we will need to preserve the |
| 5994 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5995 | // base (and therefore couldn't do the check) and a |
| 5996 | // nested-name-qualifier (and therefore could do the lookup). |
| 5997 | NamedDecl *FirstQualifierInScope = 0; |
| 5998 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5999 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6000 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 6001 | QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6002 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 6003 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 6004 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 6005 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6006 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6007 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6010 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6011 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6012 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6013 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6014 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6015 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6016 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6017 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6018 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6019 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6021 | if (!getDerived().AlwaysRebuild() && |
| 6022 | LHS.get() == E->getLHS() && |
| 6023 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6024 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6025 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6026 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6027 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6028 | } |
| 6029 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6030 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6031 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6032 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6033 | CompoundAssignOperator *E) { |
| 6034 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6037 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 6038 | ExprResult TreeTransform<Derived>:: |
| 6039 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 6040 | // Just rebuild the common and RHS expressions and see whether we |
| 6041 | // get any changes. |
| 6042 | |
| 6043 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 6044 | if (commonExpr.isInvalid()) |
| 6045 | return ExprError(); |
| 6046 | |
| 6047 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 6048 | if (rhs.isInvalid()) |
| 6049 | return ExprError(); |
| 6050 | |
| 6051 | if (!getDerived().AlwaysRebuild() && |
| 6052 | commonExpr.get() == e->getCommon() && |
| 6053 | rhs.get() == e->getFalseExpr()) |
| 6054 | return SemaRef.Owned(e); |
| 6055 | |
| 6056 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 6057 | e->getQuestionLoc(), |
| 6058 | 0, |
| 6059 | e->getColonLoc(), |
| 6060 | rhs.get()); |
| 6061 | } |
| 6062 | |
| 6063 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6064 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6065 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6066 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6067 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6068 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6069 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6070 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6071 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6072 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6073 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6074 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6075 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6076 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6077 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6078 | if (!getDerived().AlwaysRebuild() && |
| 6079 | Cond.get() == E->getCond() && |
| 6080 | LHS.get() == E->getLHS() && |
| 6081 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6082 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6083 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6084 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6085 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6086 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 6087 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6088 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6090 | |
| 6091 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6092 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6093 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 6094 | // Implicit casts are eliminated during transformation, since they |
| 6095 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6096 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6102 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6103 | if (!Type) |
| 6104 | return ExprError(); |
| 6105 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6106 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6107 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6108 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6109 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6110 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6111 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6112 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6113 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6114 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6115 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 6116 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6117 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6118 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6119 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6121 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6122 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6123 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6124 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6125 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 6126 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 6127 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6128 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6129 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6130 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6131 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6132 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6133 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6134 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6135 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6136 | Init.get() == E->getInitializer()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6137 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6138 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 6139 | // Note: the expression type doesn't necessarily match the |
| 6140 | // type-as-written, but that's okay, because it should always be |
| 6141 | // derivable from the initializer. |
| 6142 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 6143 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6144 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6145 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6147 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6151 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6152 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6153 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6155 | if (!getDerived().AlwaysRebuild() && |
| 6156 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6157 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6159 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6160 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6161 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6162 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6163 | E->getAccessorLoc(), |
| 6164 | E->getAccessor()); |
| 6165 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6166 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6167 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6168 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6169 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6170 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6171 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6172 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6173 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 6174 | Inits, &InitChanged)) |
| 6175 | return ExprError(); |
| 6176 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6177 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6178 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6180 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 6181 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6183 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6184 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6185 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6186 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6187 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6188 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6189 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6190 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6191 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6192 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6193 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6194 | // transform the designators. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6195 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6196 | bool ExprChanged = false; |
| 6197 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 6198 | DEnd = E->designators_end(); |
| 6199 | D != DEnd; ++D) { |
| 6200 | if (D->isFieldDesignator()) { |
| 6201 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 6202 | D->getDotLoc(), |
| 6203 | D->getFieldLoc())); |
| 6204 | continue; |
| 6205 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6206 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6207 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6208 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6209 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6210 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6211 | |
| 6212 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6213 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6215 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 6216 | ArrayExprs.push_back(Index.release()); |
| 6217 | continue; |
| 6218 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6219 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6220 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6221 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6222 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 6223 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6224 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6225 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6226 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6227 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6228 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6229 | |
| 6230 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6231 | End.get(), |
| 6232 | D->getLBracketLoc(), |
| 6233 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6234 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6235 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 6236 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6238 | ArrayExprs.push_back(Start.release()); |
| 6239 | ArrayExprs.push_back(End.release()); |
| 6240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6242 | if (!getDerived().AlwaysRebuild() && |
| 6243 | Init.get() == E->getInit() && |
| 6244 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6245 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6247 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6248 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6249 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6250 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6251 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6252 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6253 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6254 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6255 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6256 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6257 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6258 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6259 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6260 | QualType T = getDerived().TransformType(E->getType()); |
| 6261 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6262 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6264 | if (!getDerived().AlwaysRebuild() && |
| 6265 | T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6266 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6267 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6268 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6269 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6271 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6272 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6273 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6274 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6275 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6276 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6277 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6278 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6279 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6280 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6282 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6283 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6284 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6285 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6286 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6287 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6288 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6292 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6293 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6294 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6295 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6296 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6297 | &ArgumentChanged)) |
| 6298 | return ExprError(); |
| 6299 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6300 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6301 | move_arg(Inits), |
| 6302 | E->getRParenLoc()); |
| 6303 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6304 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6305 | /// \brief Transform an address-of-label expression. |
| 6306 | /// |
| 6307 | /// By default, the transformation of an address-of-label expression always |
| 6308 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6309 | /// the corresponding label statement by semantic analysis. |
| 6310 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6311 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6312 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6313 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6314 | E->getLabel()); |
| 6315 | if (!LD) |
| 6316 | return ExprError(); |
| 6317 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6318 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6319 | cast<LabelDecl>(LD)); |
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 | |
| 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>::TransformStmtExpr(StmtExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6325 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6326 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 6327 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6328 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6329 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6330 | if (!getDerived().AlwaysRebuild() && |
| 6331 | SubStmt.get() == E->getSubStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6332 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6333 | |
| 6334 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6335 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6336 | E->getRParenLoc()); |
| 6337 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6338 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6339 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6340 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6341 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6342 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6343 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6344 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6345 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6346 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6347 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6348 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6349 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6350 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6351 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6352 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6353 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6354 | if (!getDerived().AlwaysRebuild() && |
| 6355 | Cond.get() == E->getCond() && |
| 6356 | LHS.get() == E->getLHS() && |
| 6357 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6358 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6359 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6360 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6361 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6362 | E->getRParenLoc()); |
| 6363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6364 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6365 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6366 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6367 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6368 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6372 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6373 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6374 | switch (E->getOperator()) { |
| 6375 | case OO_New: |
| 6376 | case OO_Delete: |
| 6377 | case OO_Array_New: |
| 6378 | case OO_Array_Delete: |
| 6379 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6380 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6381 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6382 | case OO_Call: { |
| 6383 | // This is a call to an object's operator(). |
| 6384 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6385 | |
| 6386 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6387 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6388 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6389 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6390 | |
| 6391 | // FIXME: Poor location information |
| 6392 | SourceLocation FakeLParenLoc |
| 6393 | = SemaRef.PP.getLocForEndOfToken( |
| 6394 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6395 | |
| 6396 | // Transform the call arguments. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6397 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6398 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6399 | Args)) |
| 6400 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6401 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6402 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6403 | move_arg(Args), |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6404 | E->getLocEnd()); |
| 6405 | } |
| 6406 | |
| 6407 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6408 | case OO_##Name: |
| 6409 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6410 | #include "clang/Basic/OperatorKinds.def" |
| 6411 | case OO_Subscript: |
| 6412 | // Handled below. |
| 6413 | break; |
| 6414 | |
| 6415 | case OO_Conditional: |
| 6416 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6417 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6418 | |
| 6419 | case OO_None: |
| 6420 | case NUM_OVERLOADED_OPERATORS: |
| 6421 | llvm_unreachable("not an overloaded operator?"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6422 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6423 | } |
| 6424 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6425 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6426 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6427 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6428 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6429 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6430 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6431 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6432 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6433 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6434 | if (E->getNumArgs() == 2) { |
| 6435 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6436 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6437 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6439 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6440 | if (!getDerived().AlwaysRebuild() && |
| 6441 | Callee.get() == E->getCallee() && |
| 6442 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6443 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6444 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6445 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6446 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6447 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6448 | Callee.get(), |
| 6449 | First.get(), |
| 6450 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6451 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6452 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6453 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6454 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6455 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6456 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6457 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6458 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6460 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6461 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6462 | // Transform the callee. |
| 6463 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6464 | if (Callee.isInvalid()) |
| 6465 | return ExprError(); |
| 6466 | |
| 6467 | // Transform exec config. |
| 6468 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6469 | if (EC.isInvalid()) |
| 6470 | return ExprError(); |
| 6471 | |
| 6472 | // Transform arguments. |
| 6473 | bool ArgChanged = false; |
| 6474 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6475 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6476 | &ArgChanged)) |
| 6477 | return ExprError(); |
| 6478 | |
| 6479 | if (!getDerived().AlwaysRebuild() && |
| 6480 | Callee.get() == E->getCallee() && |
| 6481 | !ArgChanged) |
| 6482 | return SemaRef.Owned(E); |
| 6483 | |
| 6484 | // FIXME: Wrong source location information for the '('. |
| 6485 | SourceLocation FakeLParenLoc |
| 6486 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6487 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6488 | move_arg(Args), |
| 6489 | E->getRParenLoc(), EC.get()); |
| 6490 | } |
| 6491 | |
| 6492 | template<typename Derived> |
| 6493 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6494 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6495 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6496 | if (!Type) |
| 6497 | return ExprError(); |
| 6498 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6499 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6500 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6501 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6502 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6503 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6504 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6505 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6506 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6507 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6508 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6509 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6511 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6512 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6513 | SourceLocation FakeRParenLoc |
| 6514 | = SemaRef.PP.getLocForEndOfToken( |
| 6515 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6516 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6517 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6518 | FakeLAngleLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6519 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6520 | FakeRAngleLoc, |
| 6521 | FakeRAngleLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6522 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6523 | FakeRParenLoc); |
| 6524 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6526 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6527 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6528 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6529 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6531 | |
| 6532 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6533 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6534 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6535 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6536 | } |
| 6537 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6538 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6539 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6540 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6541 | CXXReinterpretCastExpr *E) { |
| 6542 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6544 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6545 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6546 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6547 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6548 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6549 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6550 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6551 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6552 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6553 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6554 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6555 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6556 | if (!Type) |
| 6557 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6558 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6559 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6560 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6561 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6562 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6563 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6564 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6565 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6566 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6567 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6568 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6569 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6570 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6571 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6572 | E->getRParenLoc()); |
| 6573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6575 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6576 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6577 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6578 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6579 | TypeSourceInfo *TInfo |
| 6580 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6581 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6582 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6584 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6585 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6586 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6587 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6588 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6589 | E->getLocStart(), |
| 6590 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6591 | E->getLocEnd()); |
| 6592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6593 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6594 | // We don't know whether the expression is potentially evaluated until |
| 6595 | // after we perform semantic analysis, so the expression is potentially |
| 6596 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6597 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6598 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6599 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6600 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6601 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6602 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6603 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6604 | if (!getDerived().AlwaysRebuild() && |
| 6605 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6606 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6607 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6608 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6609 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6610 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6611 | E->getLocEnd()); |
| 6612 | } |
| 6613 | |
| 6614 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6615 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6616 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6617 | if (E->isTypeOperand()) { |
| 6618 | TypeSourceInfo *TInfo |
| 6619 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6620 | if (!TInfo) |
| 6621 | return ExprError(); |
| 6622 | |
| 6623 | if (!getDerived().AlwaysRebuild() && |
| 6624 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6625 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6626 | |
Douglas Gregor | 6973511 | 2011-03-06 17:40:41 +0000 | [diff] [blame] | 6627 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6628 | E->getLocStart(), |
| 6629 | TInfo, |
| 6630 | E->getLocEnd()); |
| 6631 | } |
| 6632 | |
| 6633 | // We don't know whether the expression is potentially evaluated until |
| 6634 | // after we perform semantic analysis, so the expression is potentially |
| 6635 | // potentially evaluated. |
| 6636 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6637 | |
| 6638 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6639 | if (SubExpr.isInvalid()) |
| 6640 | return ExprError(); |
| 6641 | |
| 6642 | if (!getDerived().AlwaysRebuild() && |
| 6643 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6644 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6645 | |
| 6646 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6647 | E->getLocStart(), |
| 6648 | SubExpr.get(), |
| 6649 | E->getLocEnd()); |
| 6650 | } |
| 6651 | |
| 6652 | template<typename Derived> |
| 6653 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6654 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6655 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6658 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6659 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6660 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6661 | CXXNullPtrLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6662 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6665 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6666 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6667 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6668 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
| 6669 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); |
| 6670 | QualType T = MD->getThisType(getSema().Context); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6671 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6672 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6673 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6674 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6675 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6677 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6678 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6679 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6680 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6681 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6682 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6683 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6684 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6685 | if (!getDerived().AlwaysRebuild() && |
| 6686 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6687 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6688 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6689 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6692 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6693 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6694 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6695 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6696 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6697 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6698 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6699 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6700 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6701 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6702 | Param == E->getParam()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6703 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6704 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6705 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6706 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6707 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6708 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6709 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6710 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6711 | CXXScalarValueInitExpr *E) { |
| 6712 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6713 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6714 | return ExprError(); |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6715 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6716 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6717 | T == E->getTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6718 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6719 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6720 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6721 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6722 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6723 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6724 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6725 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6726 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6727 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6728 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6729 | TypeSourceInfo *AllocTypeInfo |
| 6730 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6731 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6732 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6733 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6734 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6735 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6736 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6737 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6738 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6739 | // Transform the placement arguments (if any). |
| 6740 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6741 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6742 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6743 | E->getNumPlacementArgs(), true, |
| 6744 | PlacementArgs, &ArgumentChanged)) |
| 6745 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6746 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6747 | // transform the constructor arguments (if any). |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6748 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6749 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6750 | ConstructorArgs, &ArgumentChanged)) |
| 6751 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6752 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6753 | // Transform constructor, new operator, and delete operator. |
| 6754 | CXXConstructorDecl *Constructor = 0; |
| 6755 | if (E->getConstructor()) { |
| 6756 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6757 | getDerived().TransformDecl(E->getLocStart(), |
| 6758 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6759 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6760 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | FunctionDecl *OperatorNew = 0; |
| 6764 | if (E->getOperatorNew()) { |
| 6765 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6766 | getDerived().TransformDecl(E->getLocStart(), |
| 6767 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6768 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6769 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | FunctionDecl *OperatorDelete = 0; |
| 6773 | if (E->getOperatorDelete()) { |
| 6774 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6775 | getDerived().TransformDecl(E->getLocStart(), |
| 6776 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6777 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6778 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6779 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6780 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6781 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6782 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6783 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6784 | Constructor == E->getConstructor() && |
| 6785 | OperatorNew == E->getOperatorNew() && |
| 6786 | OperatorDelete == E->getOperatorDelete() && |
| 6787 | !ArgumentChanged) { |
| 6788 | // Mark any declarations we need as referenced. |
| 6789 | // FIXME: instantiation-specific. |
| 6790 | if (Constructor) |
| 6791 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6792 | if (OperatorNew) |
| 6793 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6794 | if (OperatorDelete) |
| 6795 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6796 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6797 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6798 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6799 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6800 | if (!ArraySize.get()) { |
| 6801 | // If no array size was specified, but the new expression was |
| 6802 | // instantiated with an array type (e.g., "new T" where T is |
| 6803 | // instantiated with "int[4]"), extract the outer bound from the |
| 6804 | // array type as our array size. We do this with constant and |
| 6805 | // dependently-sized array types. |
| 6806 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6807 | if (!ArrayT) { |
| 6808 | // Do nothing |
| 6809 | } else if (const ConstantArrayType *ConsArrayT |
| 6810 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6811 | ArraySize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6812 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6813 | ConsArrayT->getSize(), |
| 6814 | SemaRef.Context.getSizeType(), |
| 6815 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6816 | AllocType = ConsArrayT->getElementType(); |
| 6817 | } else if (const DependentSizedArrayType *DepArrayT |
| 6818 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6819 | if (DepArrayT->getSizeExpr()) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6820 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6821 | AllocType = DepArrayT->getElementType(); |
| 6822 | } |
| 6823 | } |
| 6824 | } |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6826 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6827 | E->isGlobalNew(), |
| 6828 | /*FIXME:*/E->getLocStart(), |
| 6829 | move_arg(PlacementArgs), |
| 6830 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6831 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6832 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6833 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6834 | ArraySize.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6835 | /*FIXME:*/E->getLocStart(), |
| 6836 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6837 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6840 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6841 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6842 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6843 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6844 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6845 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6846 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6847 | // Transform the delete operator, if known. |
| 6848 | FunctionDecl *OperatorDelete = 0; |
| 6849 | if (E->getOperatorDelete()) { |
| 6850 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6851 | getDerived().TransformDecl(E->getLocStart(), |
| 6852 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6853 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6854 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6855 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6856 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6857 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6858 | Operand.get() == E->getArgument() && |
| 6859 | OperatorDelete == E->getOperatorDelete()) { |
| 6860 | // Mark any declarations we need as referenced. |
| 6861 | // FIXME: instantiation-specific. |
| 6862 | if (OperatorDelete) |
| 6863 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 6864 | |
| 6865 | if (!E->getArgument()->isTypeDependent()) { |
| 6866 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 6867 | E->getDestroyedType()); |
| 6868 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 6869 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 6870 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 6871 | SemaRef.LookupDestructor(Record)); |
| 6872 | } |
| 6873 | } |
| 6874 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6875 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6877 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6878 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 6879 | E->isGlobalDelete(), |
| 6880 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6881 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6882 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6883 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6884 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6885 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6886 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6887 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6888 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6889 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6890 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6891 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6892 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6893 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6894 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6895 | E->getOperatorLoc(), |
| 6896 | E->isArrow()? tok::arrow : tok::period, |
| 6897 | ObjectTypePtr, |
| 6898 | MayBePseudoDestructor); |
| 6899 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6900 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6901 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6902 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6903 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 6904 | if (QualifierLoc) { |
| 6905 | QualifierLoc |
| 6906 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 6907 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6908 | return ExprError(); |
| 6909 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6910 | CXXScopeSpec SS; |
| 6911 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6912 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6913 | PseudoDestructorTypeStorage Destroyed; |
| 6914 | if (E->getDestroyedTypeInfo()) { |
| 6915 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6916 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 6917 | ObjectType, 0, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6918 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6919 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6920 | Destroyed = DestroyedTypeInfo; |
| 6921 | } else if (ObjectType->isDependentType()) { |
| 6922 | // We aren't likely to be able to resolve the identifier down to a type |
| 6923 | // now anyway, so just retain the identifier. |
| 6924 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 6925 | E->getDestroyedTypeLoc()); |
| 6926 | } else { |
| 6927 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6928 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6929 | *E->getDestroyedTypeIdentifier(), |
| 6930 | E->getDestroyedTypeLoc(), |
| 6931 | /*Scope=*/0, |
| 6932 | SS, ObjectTypePtr, |
| 6933 | false); |
| 6934 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6935 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6936 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6937 | Destroyed |
| 6938 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 6939 | E->getDestroyedTypeLoc()); |
| 6940 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6941 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6942 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 6943 | if (E->getScopeTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6944 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6945 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6946 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6947 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6948 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6949 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6950 | E->getOperatorLoc(), |
| 6951 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6952 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6953 | ScopeTypeInfo, |
| 6954 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6955 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6956 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6957 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6958 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6959 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6960 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6961 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6962 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6963 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 6964 | Sema::LookupOrdinaryName); |
| 6965 | |
| 6966 | // Transform all the decls. |
| 6967 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 6968 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6969 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6970 | getDerived().TransformDecl(Old->getNameLoc(), |
| 6971 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6972 | if (!InstD) { |
| 6973 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6974 | // This can happen because of dependent hiding. |
| 6975 | if (isa<UsingShadowDecl>(*I)) |
| 6976 | continue; |
| 6977 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6978 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6979 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6980 | |
| 6981 | // Expand using declarations. |
| 6982 | if (isa<UsingDecl>(InstD)) { |
| 6983 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6984 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6985 | E = UD->shadow_end(); I != E; ++I) |
| 6986 | R.addDecl(*I); |
| 6987 | continue; |
| 6988 | } |
| 6989 | |
| 6990 | R.addDecl(InstD); |
| 6991 | } |
| 6992 | |
| 6993 | // Resolve a kind, but don't do any further analysis. If it's |
| 6994 | // ambiguous, the callee needs to deal with it. |
| 6995 | R.resolveKind(); |
| 6996 | |
| 6997 | // Rebuild the nested-name qualifier, if present. |
| 6998 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6999 | if (Old->getQualifierLoc()) { |
| 7000 | NestedNameSpecifierLoc QualifierLoc |
| 7001 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7002 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7003 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7004 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7005 | SS.Adopt(QualifierLoc); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7006 | } |
| 7007 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7008 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7009 | CXXRecordDecl *NamingClass |
| 7010 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 7011 | Old->getNameLoc(), |
| 7012 | Old->getNamingClass())); |
| 7013 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7014 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7015 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7016 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | // If we have no template arguments, it's a normal declaration name. |
| 7020 | if (!Old->hasExplicitTemplateArgs()) |
| 7021 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 7022 | |
| 7023 | // If we have template arguments, rebuild them, then rebuild the |
| 7024 | // templateid expression. |
| 7025 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7026 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7027 | Old->getNumTemplateArgs(), |
| 7028 | TransArgs)) |
| 7029 | return ExprError(); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7030 | |
| 7031 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 7032 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7033 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7034 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7035 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7036 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7037 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7038 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7039 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7040 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7042 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 7043 | T == E->getQueriedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7044 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7045 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7046 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7047 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7048 | T, |
| 7049 | E->getLocEnd()); |
| 7050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7051 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7052 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7053 | ExprResult |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 7054 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 7055 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 7056 | if (!LhsT) |
| 7057 | return ExprError(); |
| 7058 | |
| 7059 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 7060 | if (!RhsT) |
| 7061 | return ExprError(); |
| 7062 | |
| 7063 | if (!getDerived().AlwaysRebuild() && |
| 7064 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 7065 | return SemaRef.Owned(E); |
| 7066 | |
| 7067 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 7068 | E->getLocStart(), |
| 7069 | LhsT, RhsT, |
| 7070 | E->getLocEnd()); |
| 7071 | } |
| 7072 | |
| 7073 | template<typename Derived> |
| 7074 | ExprResult |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 7075 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 7076 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 7077 | if (!T) |
| 7078 | return ExprError(); |
| 7079 | |
| 7080 | if (!getDerived().AlwaysRebuild() && |
| 7081 | T == E->getQueriedTypeSourceInfo()) |
| 7082 | return SemaRef.Owned(E); |
| 7083 | |
| 7084 | ExprResult SubExpr; |
| 7085 | { |
| 7086 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7087 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 7088 | if (SubExpr.isInvalid()) |
| 7089 | return ExprError(); |
| 7090 | |
| 7091 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 7092 | return SemaRef.Owned(E); |
| 7093 | } |
| 7094 | |
| 7095 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), |
| 7096 | E->getLocStart(), |
| 7097 | T, |
| 7098 | SubExpr.get(), |
| 7099 | E->getLocEnd()); |
| 7100 | } |
| 7101 | |
| 7102 | template<typename Derived> |
| 7103 | ExprResult |
John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 7104 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 7105 | ExprResult SubExpr; |
| 7106 | { |
| 7107 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 7108 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 7109 | if (SubExpr.isInvalid()) |
| 7110 | return ExprError(); |
| 7111 | |
| 7112 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 7113 | return SemaRef.Owned(E); |
| 7114 | } |
| 7115 | |
| 7116 | return getDerived().RebuildExpressionTrait( |
| 7117 | E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); |
| 7118 | } |
| 7119 | |
| 7120 | template<typename Derived> |
| 7121 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7122 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7123 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7124 | NestedNameSpecifierLoc QualifierLoc |
| 7125 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7126 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7127 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7128 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7129 | // TODO: If this is a conversion-function-id, verify that the |
| 7130 | // destination type name (if present) resolves the same way after |
| 7131 | // instantiation as it did in the local scope. |
| 7132 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7133 | DeclarationNameInfo NameInfo |
| 7134 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 7135 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7136 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7137 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7138 | if (!E->hasExplicitTemplateArgs()) { |
| 7139 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7140 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7141 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 7142 | // if name has not changed, DNLoc has not changed either. |
| 7143 | NameInfo.getName() == E->getDeclName()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7144 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7145 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7146 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7147 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7148 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 7149 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7150 | |
| 7151 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7152 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7153 | E->getNumTemplateArgs(), |
| 7154 | TransArgs)) |
| 7155 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7156 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 7157 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7158 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 7159 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7163 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7164 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 7165 | // CXXConstructExprs are always implicit, so when we have a |
| 7166 | // 1-argument construction we just transform that argument. |
| 7167 | if (E->getNumArgs() == 1 || |
| 7168 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 7169 | return getDerived().TransformExpr(E->getArg(0)); |
| 7170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7171 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 7172 | |
| 7173 | QualType T = getDerived().TransformType(E->getType()); |
| 7174 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7175 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7176 | |
| 7177 | CXXConstructorDecl *Constructor |
| 7178 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7179 | getDerived().TransformDecl(E->getLocStart(), |
| 7180 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7181 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7182 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7183 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7184 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7185 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7186 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7187 | &ArgumentChanged)) |
| 7188 | return ExprError(); |
| 7189 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7190 | if (!getDerived().AlwaysRebuild() && |
| 7191 | T == E->getType() && |
| 7192 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7193 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 7194 | // Mark the constructor as referenced. |
| 7195 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7196 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7197 | return SemaRef.Owned(E); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 7198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7199 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 7200 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 7201 | Constructor, E->isElidable(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 7202 | move_arg(Args), |
| 7203 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 7204 | E->getConstructionKind(), |
| 7205 | E->getParenRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7206 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7207 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7208 | /// \brief Transform a C++ temporary-binding expression. |
| 7209 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7210 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 7211 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7212 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7213 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7214 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7215 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7216 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7217 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7218 | /// \brief Transform a C++ expression that contains cleanups that should |
| 7219 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7220 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7221 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7222 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7223 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7224 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 7225 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 7226 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7229 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7230 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7231 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7232 | CXXTemporaryObjectExpr *E) { |
| 7233 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7234 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7235 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7237 | CXXConstructorDecl *Constructor |
| 7238 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7239 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7240 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7241 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7242 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7243 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7244 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7245 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7246 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7247 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 7248 | &ArgumentChanged)) |
| 7249 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7250 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7251 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7252 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7253 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7254 | !ArgumentChanged) { |
| 7255 | // FIXME: Instantiation-specific |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7256 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7257 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 7258 | } |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7259 | |
| 7260 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 7261 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7262 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7263 | E->getLocEnd()); |
| 7264 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7265 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7266 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7267 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7268 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7269 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7270 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 7271 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7272 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7273 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7274 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7275 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7276 | Args.reserve(E->arg_size()); |
| 7277 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 7278 | &ArgumentChanged)) |
| 7279 | return ExprError(); |
| 7280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7281 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7282 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7283 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7284 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7286 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 7287 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7288 | E->getLParenLoc(), |
| 7289 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7290 | E->getRParenLoc()); |
| 7291 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7292 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7293 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7294 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7295 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7296 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7297 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7298 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7299 | Expr *OldBase; |
| 7300 | QualType BaseType; |
| 7301 | QualType ObjectType; |
| 7302 | if (!E->isImplicitAccess()) { |
| 7303 | OldBase = E->getBase(); |
| 7304 | Base = getDerived().TransformExpr(OldBase); |
| 7305 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7306 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7307 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7308 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7309 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7310 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7311 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7312 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7313 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7314 | ObjectTy, |
| 7315 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7316 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7317 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7318 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7319 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7320 | BaseType = ((Expr*) Base.get())->getType(); |
| 7321 | } else { |
| 7322 | OldBase = 0; |
| 7323 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 7324 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 7325 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7326 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7327 | // Transform the first part of the nested-name-specifier that qualifies |
| 7328 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7329 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7330 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7331 | E->getFirstQualifierFoundInScope(), |
| 7332 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7333 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7334 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7335 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7336 | QualifierLoc |
| 7337 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 7338 | ObjectType, |
| 7339 | FirstQualifierInScope); |
| 7340 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7341 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7343 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7344 | // TODO: If this is a conversion-function-id, verify that the |
| 7345 | // destination type name (if present) resolves the same way after |
| 7346 | // instantiation as it did in the local scope. |
| 7347 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7348 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7349 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7350 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7351 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7352 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7353 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7354 | // This is a reference to a member without an explicitly-specified |
| 7355 | // template argument list. Optimize for this common case. |
| 7356 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7357 | Base.get() == OldBase && |
| 7358 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7359 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7360 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7361 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7362 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7363 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7364 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7365 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7366 | E->isArrow(), |
| 7367 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7368 | QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7369 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7370 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7371 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7372 | } |
| 7373 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7374 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7375 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7376 | E->getNumTemplateArgs(), |
| 7377 | TransArgs)) |
| 7378 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7379 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7380 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7381 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7382 | E->isArrow(), |
| 7383 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7384 | QualifierLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7385 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7386 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7387 | &TransArgs); |
| 7388 | } |
| 7389 | |
| 7390 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7391 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7392 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7393 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7394 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7395 | QualType BaseType; |
| 7396 | if (!Old->isImplicitAccess()) { |
| 7397 | Base = getDerived().TransformExpr(Old->getBase()); |
| 7398 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7399 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7400 | BaseType = ((Expr*) Base.get())->getType(); |
| 7401 | } else { |
| 7402 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 7403 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7404 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7405 | NestedNameSpecifierLoc QualifierLoc; |
| 7406 | if (Old->getQualifierLoc()) { |
| 7407 | QualifierLoc |
| 7408 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7409 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7410 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7411 | } |
| 7412 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7413 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7414 | Sema::LookupOrdinaryName); |
| 7415 | |
| 7416 | // Transform all the decls. |
| 7417 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 7418 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7419 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7420 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 7421 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7422 | if (!InstD) { |
| 7423 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7424 | // This can happen because of dependent hiding. |
| 7425 | if (isa<UsingShadowDecl>(*I)) |
| 7426 | continue; |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 7427 | else { |
| 7428 | R.clear(); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7429 | return ExprError(); |
Argyrios Kyrtzidis | 98feafe | 2011-04-22 01:18:40 +0000 | [diff] [blame] | 7430 | } |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7431 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7432 | |
| 7433 | // Expand using declarations. |
| 7434 | if (isa<UsingDecl>(InstD)) { |
| 7435 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7436 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7437 | E = UD->shadow_end(); I != E; ++I) |
| 7438 | R.addDecl(*I); |
| 7439 | continue; |
| 7440 | } |
| 7441 | |
| 7442 | R.addDecl(InstD); |
| 7443 | } |
| 7444 | |
| 7445 | R.resolveKind(); |
| 7446 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7447 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 7448 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7449 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7450 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7451 | Old->getMemberLoc(), |
| 7452 | Old->getNamingClass())); |
| 7453 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7454 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7455 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7456 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7457 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7458 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7459 | TemplateArgumentListInfo TransArgs; |
| 7460 | if (Old->hasExplicitTemplateArgs()) { |
| 7461 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 7462 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7463 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7464 | Old->getNumTemplateArgs(), |
| 7465 | TransArgs)) |
| 7466 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7467 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7468 | |
| 7469 | // FIXME: to do this check properly, we will need to preserve the |
| 7470 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7471 | // base (and therefore couldn't do the check) and a |
| 7472 | // nested-name-qualifier (and therefore could do the lookup). |
| 7473 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7474 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7475 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7476 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7477 | Old->getOperatorLoc(), |
| 7478 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7479 | QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7480 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7481 | R, |
| 7482 | (Old->hasExplicitTemplateArgs() |
| 7483 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7487 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7488 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 7489 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 7490 | if (SubExpr.isInvalid()) |
| 7491 | return ExprError(); |
| 7492 | |
| 7493 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7494 | return SemaRef.Owned(E); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7495 | |
| 7496 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 7497 | } |
| 7498 | |
| 7499 | template<typename Derived> |
| 7500 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7501 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 7502 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 7503 | if (Pattern.isInvalid()) |
| 7504 | return ExprError(); |
| 7505 | |
| 7506 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 7507 | return SemaRef.Owned(E); |
| 7508 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 7509 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 7510 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7511 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7512 | |
| 7513 | template<typename Derived> |
| 7514 | ExprResult |
| 7515 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7516 | // If E is not value-dependent, then nothing will change when we transform it. |
| 7517 | // Note: This is an instantiation-centric view. |
| 7518 | if (!E->isValueDependent()) |
| 7519 | return SemaRef.Owned(E); |
| 7520 | |
| 7521 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 7522 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 7523 | // so |
| 7524 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 7525 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7526 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7527 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7528 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 7529 | &Unexpanded, 1, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7530 | ShouldExpand, RetainExpansion, |
| 7531 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7532 | return ExprError(); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7533 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7534 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7535 | return SemaRef.Owned(E); |
| 7536 | |
| 7537 | // We now know the length of the parameter pack, so build a new expression |
| 7538 | // that stores that length. |
| 7539 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 7540 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7541 | *NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7542 | } |
| 7543 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7544 | template<typename Derived> |
| 7545 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 7546 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 7547 | SubstNonTypeTemplateParmPackExpr *E) { |
| 7548 | // Default behavior is to do nothing with this transformation. |
| 7549 | return SemaRef.Owned(E); |
| 7550 | } |
| 7551 | |
| 7552 | template<typename Derived> |
| 7553 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7554 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7555 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7556 | } |
| 7557 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7558 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7559 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7560 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7561 | TypeSourceInfo *EncodedTypeInfo |
| 7562 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 7563 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7564 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7565 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7566 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7567 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7568 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7569 | |
| 7570 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7571 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7572 | E->getRParenLoc()); |
| 7573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7575 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7576 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7577 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7578 | // Transform arguments. |
| 7579 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7580 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7581 | Args.reserve(E->getNumArgs()); |
| 7582 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 7583 | &ArgChanged)) |
| 7584 | return ExprError(); |
| 7585 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7586 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 7587 | // Class message: transform the receiver type. |
| 7588 | TypeSourceInfo *ReceiverTypeInfo |
| 7589 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 7590 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7591 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7592 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7593 | // If nothing changed, just retain the existing message send. |
| 7594 | if (!getDerived().AlwaysRebuild() && |
| 7595 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7596 | return SemaRef.Owned(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7597 | |
| 7598 | // Build a new class message send. |
| 7599 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7600 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7601 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7602 | E->getMethodDecl(), |
| 7603 | E->getLeftLoc(), |
| 7604 | move_arg(Args), |
| 7605 | E->getRightLoc()); |
| 7606 | } |
| 7607 | |
| 7608 | // Instance message: transform the receiver |
| 7609 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7610 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7611 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7612 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7613 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7614 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7615 | |
| 7616 | // If nothing changed, just retain the existing message send. |
| 7617 | if (!getDerived().AlwaysRebuild() && |
| 7618 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7619 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7620 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7621 | // Build a new instance message send. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7622 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7623 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7624 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7625 | E->getMethodDecl(), |
| 7626 | E->getLeftLoc(), |
| 7627 | move_arg(Args), |
| 7628 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7629 | } |
| 7630 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7631 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7632 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7633 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7634 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7635 | } |
| 7636 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7637 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7638 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7639 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7640 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7641 | } |
| 7642 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7643 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7644 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7645 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7646 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7647 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7648 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7649 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7650 | |
| 7651 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7652 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7653 | // If nothing changed, just retain the existing expression. |
| 7654 | if (!getDerived().AlwaysRebuild() && |
| 7655 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7656 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7657 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7658 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7659 | E->getLocation(), |
| 7660 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7661 | } |
| 7662 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7663 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7664 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7665 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7666 | // 'super' and types never change. Property never changes. Just |
| 7667 | // retain the existing expression. |
| 7668 | if (!E->isObjectReceiver()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7669 | return SemaRef.Owned(E); |
Fariborz Jahanian | 681c075 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7670 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7671 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7672 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7673 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7674 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7675 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7676 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7677 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7678 | // If nothing changed, just retain the existing expression. |
| 7679 | if (!getDerived().AlwaysRebuild() && |
| 7680 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7681 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7682 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7683 | if (E->isExplicitProperty()) |
| 7684 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7685 | E->getExplicitProperty(), |
| 7686 | E->getLocation()); |
| 7687 | |
| 7688 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7689 | E->getType(), |
| 7690 | E->getImplicitPropertyGetter(), |
| 7691 | E->getImplicitPropertySetter(), |
| 7692 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7693 | } |
| 7694 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7695 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7696 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7697 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7698 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7699 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7700 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7701 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7702 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7703 | // If nothing changed, just retain the existing expression. |
| 7704 | if (!getDerived().AlwaysRebuild() && |
| 7705 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7706 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7707 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7708 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7709 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7710 | } |
| 7711 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7712 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7713 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7714 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7715 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7716 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7717 | SubExprs.reserve(E->getNumSubExprs()); |
| 7718 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7719 | SubExprs, &ArgumentChanged)) |
| 7720 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7722 | if (!getDerived().AlwaysRebuild() && |
| 7723 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7724 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7725 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7726 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7727 | move_arg(SubExprs), |
| 7728 | E->getRParenLoc()); |
| 7729 | } |
| 7730 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7731 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7732 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7733 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7734 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7735 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7736 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7737 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7738 | |
| 7739 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
Fariborz Jahanian | 4cc5df7 | 2011-05-05 17:18:12 +0000 | [diff] [blame] | 7740 | // We built a new blockScopeInfo in call to ActOnBlockStart |
| 7741 | // in above, CapturesCXXThis need be set here from the block |
| 7742 | // expression. |
| 7743 | blockScope->CapturesCXXThis = oldBlock->capturesCXXThis(); |
| 7744 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7745 | llvm::SmallVector<ParmVarDecl*, 4> params; |
| 7746 | llvm::SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7747 | |
| 7748 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7749 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7750 | oldBlock->param_begin(), |
| 7751 | oldBlock->param_size(), |
| 7752 | 0, paramTypes, ¶ms)) |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7753 | return true; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7754 | |
| 7755 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7756 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7757 | if (!exprResultType.isNull()) { |
| 7758 | if (!exprResultType->isDependentType()) |
| 7759 | blockScope->ReturnType = exprResultType; |
| 7760 | else if (exprResultType != getSema().Context.DependentTy) |
| 7761 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7762 | } |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7763 | |
| 7764 | // If the return type has not been determined yet, leave it as a dependent |
| 7765 | // type; it'll get set when we process the body. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7766 | if (blockScope->ReturnType.isNull()) |
| 7767 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7768 | |
| 7769 | // Don't allow returning a objc interface by value. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7770 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7771 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7772 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7773 | << 0 << blockScope->ReturnType; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7774 | return ExprError(); |
| 7775 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7776 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7777 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7778 | blockScope->ReturnType, |
| 7779 | paramTypes.data(), |
| 7780 | paramTypes.size(), |
| 7781 | oldBlock->isVariadic(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7782 | 0, RQ_None, |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7783 | exprFunctionType->getExtInfo()); |
| 7784 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7785 | |
| 7786 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7787 | if (!params.empty()) |
| 7788 | blockScope->TheDecl->setParams(params.data(), params.size()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7789 | |
| 7790 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7791 | // dependent type (DependentTy); clear out the return type setting so |
| 7792 | // 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] | 7793 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7794 | blockScope->ReturnType = QualType(); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7795 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7796 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7797 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7798 | if (body.isInvalid()) |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7799 | return ExprError(); |
| 7800 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7801 | #ifndef NDEBUG |
| 7802 | // In builds with assertions, make sure that we captured everything we |
| 7803 | // captured before. |
| 7804 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7805 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 7806 | e = oldBlock->capture_end(); i != e; ++i) { |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7807 | VarDecl *oldCapture = i->getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7808 | |
| 7809 | // Ignore parameter packs. |
| 7810 | if (isa<ParmVarDecl>(oldCapture) && |
| 7811 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 7812 | continue; |
| 7813 | |
| 7814 | VarDecl *newCapture = |
| 7815 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 7816 | oldCapture)); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7817 | assert(blockScope->CaptureMap.count(newCapture)); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7818 | } |
| 7819 | #endif |
| 7820 | |
| 7821 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 7822 | /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7823 | } |
| 7824 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7825 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7826 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7827 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7828 | ValueDecl *ND |
| 7829 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7830 | E->getDecl())); |
| 7831 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7832 | return ExprError(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7833 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7834 | if (!getDerived().AlwaysRebuild() && |
| 7835 | ND == E->getDecl()) { |
| 7836 | // Mark it referenced in the new context regardless. |
| 7837 | // FIXME: this is a bit instantiation-specific. |
| 7838 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 7839 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7840 | return SemaRef.Owned(E); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7841 | } |
| 7842 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7843 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7844 | return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7845 | ND, NameInfo, 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7846 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7847 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7848 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7849 | // Type reconstruction |
| 7850 | //===----------------------------------------------------------------------===// |
| 7851 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7852 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7853 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 7854 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7855 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7856 | getDerived().getBaseEntity()); |
| 7857 | } |
| 7858 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7859 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7860 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 7861 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7862 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7863 | getDerived().getBaseEntity()); |
| 7864 | } |
| 7865 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7866 | template<typename Derived> |
| 7867 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7868 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 7869 | bool WrittenAsLValue, |
| 7870 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7871 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7872 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7876 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7877 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 7878 | QualType ClassType, |
| 7879 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7880 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7881 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7882 | } |
| 7883 | |
| 7884 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7885 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7886 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 7887 | ArrayType::ArraySizeModifier SizeMod, |
| 7888 | const llvm::APInt *Size, |
| 7889 | Expr *SizeExpr, |
| 7890 | unsigned IndexTypeQuals, |
| 7891 | SourceRange BracketsRange) { |
| 7892 | if (SizeExpr || !Size) |
| 7893 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 7894 | IndexTypeQuals, BracketsRange, |
| 7895 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7896 | |
| 7897 | QualType Types[] = { |
| 7898 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 7899 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 7900 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7901 | }; |
| 7902 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 7903 | QualType SizeType; |
| 7904 | for (unsigned I = 0; I != NumTypes; ++I) |
| 7905 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 7906 | SizeType = Types[I]; |
| 7907 | break; |
| 7908 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7909 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7910 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 7911 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7912 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7913 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7914 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7915 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7916 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7917 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7918 | QualType |
| 7919 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7920 | ArrayType::ArraySizeModifier SizeMod, |
| 7921 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7922 | unsigned IndexTypeQuals, |
| 7923 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7924 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7925 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7926 | } |
| 7927 | |
| 7928 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7929 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7930 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7931 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7932 | unsigned IndexTypeQuals, |
| 7933 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7934 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7935 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7937 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7938 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7939 | QualType |
| 7940 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7941 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7942 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7943 | unsigned IndexTypeQuals, |
| 7944 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7945 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7946 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7947 | IndexTypeQuals, BracketsRange); |
| 7948 | } |
| 7949 | |
| 7950 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7951 | QualType |
| 7952 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7953 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7954 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7955 | unsigned IndexTypeQuals, |
| 7956 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7957 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7958 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7959 | IndexTypeQuals, BracketsRange); |
| 7960 | } |
| 7961 | |
| 7962 | template<typename Derived> |
| 7963 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7964 | unsigned NumElements, |
| 7965 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7966 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7967 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7969 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7970 | template<typename Derived> |
| 7971 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 7972 | unsigned NumElements, |
| 7973 | SourceLocation AttributeLoc) { |
| 7974 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 7975 | NumElements, true); |
| 7976 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7977 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 7978 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7979 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7981 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7982 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7983 | QualType |
| 7984 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7985 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7986 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7987 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7988 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7989 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7990 | template<typename Derived> |
| 7991 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7992 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7993 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7994 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7995 | unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7996 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7997 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7998 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7999 | Quals, RefQualifier, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8000 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 8001 | getDerived().getBaseEntity(), |
| 8002 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8003 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8004 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8005 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 8006 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 8007 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 8008 | } |
| 8009 | |
| 8010 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8011 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 8012 | assert(D && "no decl found"); |
| 8013 | if (D->isInvalidDecl()) return QualType(); |
| 8014 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 8015 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8016 | TypeDecl *Ty; |
| 8017 | if (isa<UsingDecl>(D)) { |
| 8018 | UsingDecl *Using = cast<UsingDecl>(D); |
| 8019 | assert(Using->isTypeName() && |
| 8020 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 8021 | |
| 8022 | // A valid resolved using typename decl points to exactly one type decl. |
| 8023 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 8024 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8025 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 8026 | } else { |
| 8027 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 8028 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 8029 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 8030 | } |
| 8031 | |
| 8032 | return SemaRef.Context.getTypeDeclType(Ty); |
| 8033 | } |
| 8034 | |
| 8035 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 8036 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 8037 | SourceLocation Loc) { |
| 8038 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8039 | } |
| 8040 | |
| 8041 | template<typename Derived> |
| 8042 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 8043 | return SemaRef.Context.getTypeOfType(Underlying); |
| 8044 | } |
| 8045 | |
| 8046 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 8047 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 8048 | SourceLocation Loc) { |
| 8049 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | template<typename Derived> |
| 8053 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 8054 | TemplateName Template, |
| 8055 | SourceLocation TemplateNameLoc, |
Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 8056 | TemplateArgumentListInfo &TemplateArgs) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 8057 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8059 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 8060 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8061 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8062 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8063 | bool TemplateKW, |
| 8064 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8065 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8066 | Template); |
| 8067 | } |
| 8068 | |
| 8069 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8070 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8071 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 8072 | const IdentifierInfo &Name, |
| 8073 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8074 | QualType ObjectType, |
| 8075 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8076 | UnqualifiedId TemplateName; |
| 8077 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8078 | Sema::TemplateTy Template; |
| 8079 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8080 | /*FIXME:*/SourceLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8081 | SS, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8082 | TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8083 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8084 | /*EnteringContext=*/false, |
| 8085 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 8086 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 8087 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8089 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8090 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8091 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8092 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8093 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8094 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8095 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8096 | // FIXME: Bogus location information. |
| 8097 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| 8098 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8099 | Sema::TemplateTy Template; |
| 8100 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 8101 | /*FIXME:*/SourceLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8102 | SS, |
| 8103 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 8104 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 8105 | /*EnteringContext=*/false, |
| 8106 | Template); |
| 8107 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8108 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8109 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 8110 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8111 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8112 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 8113 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8114 | Expr *OrigCallee, |
| 8115 | Expr *First, |
| 8116 | Expr *Second) { |
| 8117 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 8118 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8120 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8121 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8122 | if (!First->getType()->isOverloadableType() && |
| 8123 | !Second->getType()->isOverloadableType()) |
| 8124 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 8125 | Callee->getLocStart(), |
| 8126 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 8127 | } else if (Op == OO_Arrow) { |
| 8128 | // -> is never a builtin operation. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8129 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 8130 | } else if (Second == 0 || isPostIncDec) { |
| 8131 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8132 | // The argument is not of overloadable type, so try to create a |
| 8133 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8134 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8135 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8136 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8137 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8138 | } |
| 8139 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8140 | if (!First->getType()->isOverloadableType() && |
| 8141 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8142 | // Neither of the arguments is an overloadable type, so try to |
| 8143 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8144 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8145 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8146 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8147 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8148 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8150 | return move(Result); |
| 8151 | } |
| 8152 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8153 | |
| 8154 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8155 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8156 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8157 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8158 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8159 | assert(ULE->requiresADL()); |
| 8160 | |
| 8161 | // FIXME: Do we have to check |
| 8162 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 8163 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8164 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8165 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8168 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8169 | Expr *Args[2] = { First, Second }; |
| 8170 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8172 | // Create the overloaded operator invocation for unary operators. |
| 8173 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8174 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8175 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8176 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8178 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8179 | if (Op == OO_Subscript) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8180 | return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 8181 | OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8182 | First, |
| 8183 | Second); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 8184 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8185 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 8186 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8187 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8188 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 8189 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8190 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8191 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8192 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8194 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8195 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8196 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8197 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8198 | SourceLocation OperatorLoc, |
| 8199 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 8200 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8201 | TypeSourceInfo *ScopeType, |
| 8202 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8203 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8204 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8205 | QualType BaseType = Base->getType(); |
| 8206 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8207 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 8208 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 8209 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 8210 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8211 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8212 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8213 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 8214 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8215 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8216 | /*FIXME?*/true); |
| 8217 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8218 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 8219 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8220 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 8221 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 8222 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 8223 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 8224 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8225 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8226 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 8227 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8228 | OperatorLoc, isArrow, |
| 8229 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8230 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 8231 | /*TemplateArgs*/ 0); |
| 8232 | } |
| 8233 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8234 | } // end namespace clang |
| 8235 | |
| 8236 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |