Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 16 | |
John McCall | 8302463 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaInternal.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 18 | #include "clang/Sema/Lookup.h" |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 19 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 20 | #include "clang/Sema/SemaDiagnostic.h" |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ScopeInfo.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
| 26 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 27 | #include "clang/AST/Stmt.h" |
| 28 | #include "clang/AST/StmtCXX.h" |
| 29 | #include "clang/AST/StmtObjC.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Ownership.h" |
| 31 | #include "clang/Sema/Designator.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 451d1b1 | 2010-12-02 00:05:49 +0000 | [diff] [blame] | 34 | #include "TypeLocBuilder.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | |
| 37 | namespace clang { |
John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 38 | using namespace sema; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 40 | /// \brief A semantic tree transformation that allows one to transform one |
| 41 | /// abstract syntax tree into another. |
| 42 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 44 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 45 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 46 | /// instantiation is implemented as a tree transformation where the |
| 47 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 48 | /// template arguments for their corresponding template parameters; a similar |
| 49 | /// transformation is performed for non-type template parameters and |
| 50 | /// template template parameters. |
| 51 | /// |
| 52 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 54 | /// override any of the transformation or rebuild operators by providing an |
| 55 | /// operation with the same signature as the default implementation. The |
| 56 | /// overridding function should not be virtual. |
| 57 | /// |
| 58 | /// Semantic tree transformations are split into two stages, either of which |
| 59 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 60 | /// or the parts of an AST node using the various transformation functions, |
| 61 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 62 | /// node of the appropriate kind from the pieces. The default transformation |
| 63 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 64 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 65 | /// were changed by the transformation, invokes the rebuild operation to create |
| 66 | /// a new AST node. |
| 67 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 69 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame^] | 70 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 71 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 72 | /// new implementations. |
| 73 | /// |
| 74 | /// For more fine-grained transformations, subclasses can replace any of the |
| 75 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 76 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 77 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 78 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 79 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 80 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 81 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 82 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 83 | /// be able to use more efficient rebuild steps. |
| 84 | /// |
| 85 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 87 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 88 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 89 | /// default locations and entity names used for type-checking |
| 90 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 91 | template<typename Derived> |
| 92 | class TreeTransform { |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 93 | /// \brief Private RAII object that helps us forget and then re-remember |
| 94 | /// the template argument corresponding to a partially-substituted parameter |
| 95 | /// pack. |
| 96 | class ForgetPartiallySubstitutedPackRAII { |
| 97 | Derived &Self; |
| 98 | TemplateArgument Old; |
| 99 | |
| 100 | public: |
| 101 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 102 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 103 | } |
| 104 | |
| 105 | ~ForgetPartiallySubstitutedPackRAII() { |
| 106 | Self.RememberPartiallySubstitutedPack(Old); |
| 107 | } |
| 108 | }; |
| 109 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 110 | protected: |
| 111 | Sema &SemaRef; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 112 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | public: |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 114 | /// \brief Initializes a new tree transformer. |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 115 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 117 | /// \brief Retrieves a reference to the derived class. |
| 118 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 119 | |
| 120 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | const Derived &getDerived() const { |
| 122 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 123 | } |
| 124 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 125 | static inline ExprResult Owned(Expr *E) { return E; } |
| 126 | static inline StmtResult Owned(Stmt *S) { return S; } |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 128 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 129 | /// this tree transform. |
| 130 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 131 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 132 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 133 | /// if none of the children have changed. |
| 134 | /// |
| 135 | /// Subclasses may override this function to specify when the transformation |
| 136 | /// should rebuild all AST nodes. |
| 137 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 139 | /// \brief Returns the location of the entity being transformed, if that |
| 140 | /// information was not available elsewhere in the AST. |
| 141 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 143 | /// provide an alternative implementation that provides better location |
| 144 | /// information. |
| 145 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 147 | /// \brief Returns the name of the entity being transformed, if that |
| 148 | /// information was not available elsewhere in the AST. |
| 149 | /// |
| 150 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 151 | /// implementation with a more precise name. |
| 152 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | /// \brief Sets the "base" location and entity when that |
| 155 | /// information is known based on another transformation. |
| 156 | /// |
| 157 | /// By default, the source location and entity are ignored. Subclasses can |
| 158 | /// override this function to provide a customized implementation. |
| 159 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 161 | /// \brief RAII object that temporarily sets the base location and entity |
| 162 | /// used for reporting diagnostics in types. |
| 163 | class TemporaryBase { |
| 164 | TreeTransform &Self; |
| 165 | SourceLocation OldLocation; |
| 166 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 168 | public: |
| 169 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 171 | OldLocation = Self.getDerived().getBaseLocation(); |
| 172 | OldEntity = Self.getDerived().getBaseEntity(); |
Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 173 | |
| 174 | if (Location.isValid()) |
| 175 | Self.getDerived().setBase(Location, Entity); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 178 | ~TemporaryBase() { |
| 179 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 180 | } |
| 181 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | |
| 183 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 184 | /// transformed. |
| 185 | /// |
| 186 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 188 | /// not change. For example, template instantiation need not traverse |
| 189 | /// non-dependent types. |
| 190 | bool AlreadyTransformed(QualType T) { |
| 191 | return T.isNull(); |
| 192 | } |
| 193 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 194 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 195 | /// because it is a default argument. |
| 196 | /// |
| 197 | /// Subclasses can provide an alternative implementation of this routine to |
| 198 | /// determine which kinds of call arguments get dropped. By default, |
| 199 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 200 | bool DropCallArgument(Expr *E) { |
| 201 | return E->isDefaultArgument(); |
| 202 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 203 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 204 | /// \brief Determine whether we should expand a pack expansion with the |
| 205 | /// given set of parameter packs into separate arguments by repeatedly |
| 206 | /// transforming the pattern. |
| 207 | /// |
Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 208 | /// By default, the transformer never tries to expand pack expansions. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 209 | /// Subclasses can override this routine to provide different behavior. |
| 210 | /// |
| 211 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 212 | /// pack expansion. |
| 213 | /// |
| 214 | /// \param PatternRange The source range that covers the entire pattern of |
| 215 | /// the pack expansion. |
| 216 | /// |
| 217 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 218 | /// pattern. |
| 219 | /// |
| 220 | /// \param NumUnexpanded The number of unexpanded parameter packs in |
| 221 | /// \p Unexpanded. |
| 222 | /// |
| 223 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 224 | /// expand the corresponding pack expansions into separate arguments. When |
| 225 | /// set, \c NumExpansions must also be set. |
| 226 | /// |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 227 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 228 | /// pack expansion after all of the expanded arguments. This is used |
| 229 | /// when extending explicitly-specified template argument packs per |
| 230 | /// C++0x [temp.arg.explicit]p9. |
| 231 | /// |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 232 | /// \param NumExpansions The number of separate arguments that will be in |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 233 | /// the expanded form of the corresponding pack expansion. This is both an |
| 234 | /// input and an output parameter, which can be set by the caller if the |
| 235 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 236 | /// and will be set by the callee when the number of expansions is known. |
| 237 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 238 | /// set this value in other cases. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 239 | /// |
| 240 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 241 | /// are to be instantiated with arguments of different lengths), false |
| 242 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 243 | /// must be set. |
| 244 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 245 | SourceRange PatternRange, |
| 246 | const UnexpandedParameterPack *Unexpanded, |
| 247 | unsigned NumUnexpanded, |
| 248 | bool &ShouldExpand, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 249 | bool &RetainExpansion, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 250 | llvm::Optional<unsigned> &NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 251 | ShouldExpand = false; |
| 252 | return false; |
| 253 | } |
| 254 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 255 | /// \brief "Forget" about the partially-substituted pack template argument, |
| 256 | /// when performing an instantiation that must preserve the parameter pack |
| 257 | /// use. |
| 258 | /// |
| 259 | /// This routine is meant to be overridden by the template instantiator. |
| 260 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 261 | return TemplateArgument(); |
| 262 | } |
| 263 | |
| 264 | /// \brief "Remember" the partially-substituted pack template argument |
| 265 | /// after performing an instantiation that must preserve the parameter pack |
| 266 | /// use. |
| 267 | /// |
| 268 | /// This routine is meant to be overridden by the template instantiator. |
| 269 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 270 | |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 271 | /// \brief Note to the derived class when a function parameter pack is |
| 272 | /// being expanded. |
| 273 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 274 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 275 | /// \brief Transforms the given type into another type. |
| 276 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 277 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 278 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 279 | /// function. This is expensive, but we don't mind, because |
| 280 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 281 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// |
| 283 | /// \returns the transformed type. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 284 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 286 | /// \brief Transforms the given type-with-location into a new |
| 287 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 288 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 289 | /// By default, this routine transforms a type by delegating to the |
| 290 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 291 | /// may override this function (to take over all type |
| 292 | /// transformations) or some set of the TransformXXXType functions |
| 293 | /// to alter the transformation. |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 294 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 295 | |
| 296 | /// \brief Transform the given type-with-location into a new |
| 297 | /// type, collecting location information in the given builder |
| 298 | /// as necessary. |
| 299 | /// |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 300 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 302 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 303 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 305 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 306 | /// statement or the TransformExpr() function to transform an expression. |
| 307 | /// Subclasses may override this function to transform statements using some |
| 308 | /// other mechanism. |
| 309 | /// |
| 310 | /// \returns the transformed statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 311 | StmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 313 | /// \brief Transform the given expression. |
| 314 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 315 | /// By default, this routine transforms an expression by delegating to the |
| 316 | /// appropriate TransformXXXExpr function to build a new expression. |
| 317 | /// Subclasses may override this function to transform expressions using some |
| 318 | /// other mechanism. |
| 319 | /// |
| 320 | /// \returns the transformed expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 321 | ExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 323 | /// \brief Transform the given list of expressions. |
| 324 | /// |
| 325 | /// This routine transforms a list of expressions by invoking |
| 326 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 327 | /// support for variadic templates by expanding any pack expansions (if the |
| 328 | /// derived class permits such expansion) along the way. When pack expansions |
| 329 | /// are present, the number of outputs may not equal the number of inputs. |
| 330 | /// |
| 331 | /// \param Inputs The set of expressions to be transformed. |
| 332 | /// |
| 333 | /// \param NumInputs The number of expressions in \c Inputs. |
| 334 | /// |
| 335 | /// \param IsCall If \c true, then this transform is being performed on |
| 336 | /// function-call arguments, and any arguments that should be dropped, will |
| 337 | /// be. |
| 338 | /// |
| 339 | /// \param Outputs The transformed input expressions will be added to this |
| 340 | /// vector. |
| 341 | /// |
| 342 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 343 | /// due to transformation. |
| 344 | /// |
| 345 | /// \returns true if an error occurred, false otherwise. |
| 346 | bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, |
| 347 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 348 | bool *ArgChanged = 0); |
| 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Transform the given declaration, which is referenced from a type |
| 351 | /// or expression. |
| 352 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 353 | /// By default, acts as the identity function on declarations. Subclasses |
| 354 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 355 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 356 | |
| 357 | /// \brief Transform the definition of the given declaration. |
| 358 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 360 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 361 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 362 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 365 | /// \brief Transform the given declaration, which was the first part of a |
| 366 | /// nested-name-specifier in a member access expression. |
| 367 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 368 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 369 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 370 | /// the \c T in \c x->T::member |
| 371 | /// |
| 372 | /// By default, invokes TransformDecl() to transform the declaration. |
| 373 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 374 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 375 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 376 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 377 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 378 | /// \brief Transform the given nested-name-specifier with source-location |
| 379 | /// information. |
| 380 | /// |
| 381 | /// By default, transforms all of the types and declarations within the |
| 382 | /// nested-name-specifier. Subclasses may override this function to provide |
| 383 | /// alternate behavior. |
| 384 | NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( |
| 385 | NestedNameSpecifierLoc NNS, |
| 386 | QualType ObjectType = QualType(), |
| 387 | NamedDecl *FirstQualifierInScope = 0); |
| 388 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 389 | /// \brief Transform the given declaration name. |
| 390 | /// |
| 391 | /// By default, transforms the types of conversion function, constructor, |
| 392 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 393 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 394 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 395 | DeclarationNameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 396 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 398 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | /// |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 400 | /// \param SS The nested-name-specifier that qualifies the template |
| 401 | /// name. This nested-name-specifier must already have been transformed. |
| 402 | /// |
| 403 | /// \param Name The template name to transform. |
| 404 | /// |
| 405 | /// \param NameLoc The source location of the template name. |
| 406 | /// |
| 407 | /// \param ObjectType If we're translating a template name within a member |
| 408 | /// access expression, this is the type of the object whose member template |
| 409 | /// is being referenced. |
| 410 | /// |
| 411 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 412 | /// also refers to a name within the current (lexical) scope, this is the |
| 413 | /// declaration it refers to. |
| 414 | /// |
| 415 | /// By default, transforms the template name by transforming the declarations |
| 416 | /// and nested-name-specifiers that occur within the template name. |
| 417 | /// Subclasses may override this function to provide alternate behavior. |
| 418 | TemplateName TransformTemplateName(CXXScopeSpec &SS, |
| 419 | TemplateName Name, |
| 420 | SourceLocation NameLoc, |
| 421 | QualType ObjectType = QualType(), |
| 422 | NamedDecl *FirstQualifierInScope = 0); |
| 423 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 424 | /// \brief Transform the given template argument. |
| 425 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | /// By default, this operation transforms the type, expression, or |
| 427 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 428 | /// new template argument from the transformed result. Subclasses may |
| 429 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 430 | /// |
| 431 | /// Returns true if there was an error. |
| 432 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 433 | TemplateArgumentLoc &Output); |
| 434 | |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 435 | /// \brief Transform the given set of template arguments. |
| 436 | /// |
| 437 | /// By default, this operation transforms all of the template arguments |
| 438 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 439 | /// the transformed arguments to the output list. |
| 440 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 441 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 442 | /// a convenience function. Subclasses that wish to override this behavior |
| 443 | /// should override the iterator-based member template version. |
| 444 | /// |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 445 | /// \param Inputs The set of template arguments to be transformed. |
| 446 | /// |
| 447 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 448 | /// |
| 449 | /// \param Outputs The set of transformed template arguments output by this |
| 450 | /// routine. |
| 451 | /// |
| 452 | /// Returns true if an error occurred. |
| 453 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 454 | unsigned NumInputs, |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 455 | TemplateArgumentListInfo &Outputs) { |
| 456 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); |
| 457 | } |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 458 | |
| 459 | /// \brief Transform the given set of template arguments. |
| 460 | /// |
| 461 | /// By default, this operation transforms all of the template arguments |
| 462 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 463 | /// the transformed arguments to the output list. |
| 464 | /// |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 465 | /// \param First An iterator to the first template argument. |
| 466 | /// |
| 467 | /// \param Last An iterator one step past the last template argument. |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 468 | /// |
| 469 | /// \param Outputs The set of transformed template arguments output by this |
| 470 | /// routine. |
| 471 | /// |
| 472 | /// Returns true if an error occurred. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 473 | template<typename InputIterator> |
| 474 | bool TransformTemplateArguments(InputIterator First, |
| 475 | InputIterator Last, |
| 476 | TemplateArgumentListInfo &Outputs); |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 477 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 478 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 479 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 480 | TemplateArgumentLoc &ArgLoc); |
| 481 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 482 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 483 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 484 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 485 | getDerived().getBaseLocation()); |
| 486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 488 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 489 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 490 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 491 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 492 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 493 | QualType |
| 494 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 495 | TemplateSpecializationTypeLoc TL, |
| 496 | TemplateName Template); |
| 497 | |
| 498 | QualType |
| 499 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 500 | DependentTemplateSpecializationTypeLoc TL, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 501 | TemplateName Template); |
| 502 | |
| 503 | QualType |
| 504 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 505 | DependentTemplateSpecializationTypeLoc TL, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 506 | NestedNameSpecifier *Prefix); |
| 507 | |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 508 | QualType |
| 509 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 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. |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 528 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 529 | llvm::Optional<unsigned> NumExpansions); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 530 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 531 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 532 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 533 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 534 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 536 | #define STMT(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 537 | StmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 538 | #define EXPR(Node, Parent) \ |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 539 | ExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 540 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 541 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 543 | /// \brief Build a new pointer type given its pointee type. |
| 544 | /// |
| 545 | /// By default, performs semantic analysis when building the pointer type. |
| 546 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 547 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 548 | |
| 549 | /// \brief Build a new block pointer type given its pointee type. |
| 550 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 552 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 553 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 554 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 555 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 556 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 557 | /// By default, performs semantic analysis when building the |
| 558 | /// reference type. Subclasses may override this routine to provide |
| 559 | /// different behavior. |
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 | /// \param LValue whether the type was written with an lvalue sigil |
| 562 | /// or an rvalue sigil. |
| 563 | QualType RebuildReferenceType(QualType ReferentType, |
| 564 | bool LValue, |
| 565 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 566 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 567 | /// \brief Build a new member pointer type given the pointee type and the |
| 568 | /// class type it refers into. |
| 569 | /// |
| 570 | /// By default, performs semantic analysis when building the member pointer |
| 571 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 572 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 573 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 575 | /// \brief Build a new array type given the element type, size |
| 576 | /// modifier, size of the array (if known), size expression, and index type |
| 577 | /// qualifiers. |
| 578 | /// |
| 579 | /// By default, performs semantic analysis when building the array type. |
| 580 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 581 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 582 | QualType RebuildArrayType(QualType ElementType, |
| 583 | ArrayType::ArraySizeModifier SizeMod, |
| 584 | const llvm::APInt *Size, |
| 585 | Expr *SizeExpr, |
| 586 | unsigned IndexTypeQuals, |
| 587 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 588 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 589 | /// \brief Build a new constant array type given the element type, size |
| 590 | /// modifier, (known) size of the array, and index type qualifiers. |
| 591 | /// |
| 592 | /// By default, performs semantic analysis when building the array type. |
| 593 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 594 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 595 | ArrayType::ArraySizeModifier SizeMod, |
| 596 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 597 | unsigned IndexTypeQuals, |
| 598 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 599 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 600 | /// \brief Build a new incomplete array type given the element type, size |
| 601 | /// modifier, and index type qualifiers. |
| 602 | /// |
| 603 | /// By default, performs semantic analysis when building the array type. |
| 604 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 606 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 607 | unsigned IndexTypeQuals, |
| 608 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 609 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 611 | /// size modifier, size expression, and index type qualifiers. |
| 612 | /// |
| 613 | /// By default, performs semantic analysis when building the array type. |
| 614 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 615 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 616 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 617 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 618 | unsigned IndexTypeQuals, |
| 619 | SourceRange BracketsRange); |
| 620 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 622 | /// size modifier, size expression, and index type qualifiers. |
| 623 | /// |
| 624 | /// By default, performs semantic analysis when building the array type. |
| 625 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 627 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 628 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 629 | unsigned IndexTypeQuals, |
| 630 | SourceRange BracketsRange); |
| 631 | |
| 632 | /// \brief Build a new vector type given the element type and |
| 633 | /// number of elements. |
| 634 | /// |
| 635 | /// By default, performs semantic analysis when building the vector type. |
| 636 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 637 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 638 | VectorType::VectorKind VecKind); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 640 | /// \brief Build a new extended vector type given the element type and |
| 641 | /// number of elements. |
| 642 | /// |
| 643 | /// By default, performs semantic analysis when building the vector type. |
| 644 | /// Subclasses may override this routine to provide different behavior. |
| 645 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 646 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 647 | |
| 648 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 649 | /// given the element type and number of elements. |
| 650 | /// |
| 651 | /// By default, performs semantic analysis when building the vector type. |
| 652 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 654 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 655 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 657 | /// \brief Build a new function type. |
| 658 | /// |
| 659 | /// By default, performs semantic analysis when building the function type. |
| 660 | /// Subclasses may override this routine to provide different behavior. |
| 661 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 663 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 664 | bool Variadic, unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 665 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 666 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 667 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 668 | /// \brief Build a new unprototyped function type. |
| 669 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 670 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 671 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 672 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 673 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 674 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 675 | /// \brief Build a new typedef type. |
| 676 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 677 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 678 | } |
| 679 | |
| 680 | /// \brief Build a new class/struct/union type. |
| 681 | QualType RebuildRecordType(RecordDecl *Record) { |
| 682 | return SemaRef.Context.getTypeDeclType(Record); |
| 683 | } |
| 684 | |
| 685 | /// \brief Build a new Enum type. |
| 686 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 687 | return SemaRef.Context.getTypeDeclType(Enum); |
| 688 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 689 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 691 | /// |
| 692 | /// By default, performs semantic analysis when building the typeof type. |
| 693 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 694 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 695 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 697 | /// |
| 698 | /// By default, builds a new TypeOfType with the given underlying type. |
| 699 | QualType RebuildTypeOfType(QualType Underlying); |
| 700 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 702 | /// |
| 703 | /// By default, performs semantic analysis when building the decltype type. |
| 704 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 705 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 707 | /// \brief Build a new C++0x auto type. |
| 708 | /// |
| 709 | /// By default, builds a new AutoType with the given deduced type. |
| 710 | QualType RebuildAutoType(QualType Deduced) { |
| 711 | return SemaRef.Context.getAutoType(Deduced); |
| 712 | } |
| 713 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 714 | /// \brief Build a new template specialization type. |
| 715 | /// |
| 716 | /// By default, performs semantic analysis when building the template |
| 717 | /// specialization type. Subclasses may override this routine to provide |
| 718 | /// different behavior. |
| 719 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 720 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 721 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 723 | /// \brief Build a new parenthesized type. |
| 724 | /// |
| 725 | /// By default, builds a new ParenType type from the inner type. |
| 726 | /// Subclasses may override this routine to provide different behavior. |
| 727 | QualType RebuildParenType(QualType InnerType) { |
| 728 | return SemaRef.Context.getParenType(InnerType); |
| 729 | } |
| 730 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 731 | /// \brief Build a new qualified name type. |
| 732 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 733 | /// By default, builds a new ElaboratedType type from the keyword, |
| 734 | /// the nested-name-specifier and the named type. |
| 735 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 736 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 737 | ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 738 | NestedNameSpecifierLoc QualifierLoc, |
| 739 | QualType Named) { |
| 740 | return SemaRef.Context.getElaboratedType(Keyword, |
| 741 | QualifierLoc.getNestedNameSpecifier(), |
| 742 | Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 744 | |
| 745 | /// \brief Build a new typename type that refers to a template-id. |
| 746 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 747 | /// By default, builds a new DependentNameType type from the |
| 748 | /// nested-name-specifier and the given type. Subclasses may override |
| 749 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 750 | QualType RebuildDependentTemplateSpecializationType( |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 751 | ElaboratedTypeKeyword Keyword, |
| 752 | NestedNameSpecifierLoc QualifierLoc, |
| 753 | const IdentifierInfo *Name, |
| 754 | SourceLocation NameLoc, |
| 755 | const TemplateArgumentListInfo &Args) { |
| 756 | // Rebuild the template name. |
| 757 | // TODO: avoid TemplateName abstraction |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 758 | CXXScopeSpec SS; |
| 759 | SS.Adopt(QualifierLoc); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 760 | TemplateName InstName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 761 | = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 762 | |
| 763 | if (InstName.isNull()) |
| 764 | return QualType(); |
| 765 | |
| 766 | // If it's still dependent, make a dependent specialization. |
| 767 | if (InstName.getAsDependentTemplateName()) |
| 768 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 769 | QualifierLoc.getNestedNameSpecifier(), |
| 770 | Name, |
| 771 | Args); |
| 772 | |
| 773 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 774 | // specialization. |
| 775 | QualType T = |
| 776 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 777 | if (T.isNull()) return QualType(); |
| 778 | |
| 779 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) |
| 780 | return T; |
| 781 | |
| 782 | return SemaRef.Context.getElaboratedType(Keyword, |
| 783 | QualifierLoc.getNestedNameSpecifier(), |
| 784 | T); |
| 785 | } |
| 786 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 787 | /// \brief Build a new typename type that refers to an identifier. |
| 788 | /// |
| 789 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 790 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 791 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 792 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 793 | SourceLocation KeywordLoc, |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 794 | NestedNameSpecifierLoc QualifierLoc, |
| 795 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 796 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 797 | CXXScopeSpec SS; |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 798 | SS.Adopt(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 800 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 801 | // If the name is still dependent, just build a new dependent name type. |
| 802 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 803 | return SemaRef.Context.getDependentNameType(Keyword, |
| 804 | QualifierLoc.getNestedNameSpecifier(), |
| 805 | Id); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 808 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 809 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
Douglas Gregor | 9cbc22b | 2011-02-28 22:42:13 +0000 | [diff] [blame] | 810 | *Id, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 811 | |
| 812 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 813 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 814 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 815 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 816 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 817 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 818 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 819 | if (!DC) |
| 820 | return QualType(); |
| 821 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 822 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 823 | return QualType(); |
| 824 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 825 | TagDecl *Tag = 0; |
| 826 | SemaRef.LookupQualifiedName(Result, DC); |
| 827 | switch (Result.getResultKind()) { |
| 828 | case LookupResult::NotFound: |
| 829 | case LookupResult::NotFoundInCurrentInstantiation: |
| 830 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 831 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 832 | case LookupResult::Found: |
| 833 | Tag = Result.getAsSingle<TagDecl>(); |
| 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::FoundOverloaded: |
| 837 | case LookupResult::FoundUnresolvedValue: |
| 838 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 839 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 840 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 841 | case LookupResult::Ambiguous: |
| 842 | // Let the LookupResult structure handle ambiguities. |
| 843 | return QualType(); |
| 844 | } |
| 845 | |
| 846 | if (!Tag) { |
Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 847 | // Check where the name exists but isn't a tag type and use that to emit |
| 848 | // better diagnostics. |
| 849 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 850 | SemaRef.LookupQualifiedName(Result, DC); |
| 851 | switch (Result.getResultKind()) { |
| 852 | case LookupResult::Found: |
| 853 | case LookupResult::FoundOverloaded: |
| 854 | case LookupResult::FoundUnresolvedValue: { |
| 855 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| 856 | unsigned Kind = 0; |
| 857 | if (isa<TypedefDecl>(SomeDecl)) Kind = 1; |
| 858 | else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2; |
| 859 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; |
| 860 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 861 | break; |
| 862 | } |
| 863 | default: |
| 864 | // FIXME: Would be nice to highlight just the source range. |
| 865 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 866 | << Kind << Id << DC; |
| 867 | break; |
| 868 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 869 | return QualType(); |
| 870 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 871 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 872 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 873 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 874 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 875 | return QualType(); |
| 876 | } |
| 877 | |
| 878 | // Build the elaborated-type-specifier type. |
| 879 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 880 | return SemaRef.Context.getElaboratedType(Keyword, |
| 881 | QualifierLoc.getNestedNameSpecifier(), |
| 882 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 885 | /// \brief Build a new pack expansion type. |
| 886 | /// |
| 887 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 888 | /// Subclasses may override this routine to provide different behavior. |
| 889 | QualType RebuildPackExpansionType(QualType Pattern, |
| 890 | SourceRange PatternRange, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 891 | SourceLocation EllipsisLoc, |
| 892 | llvm::Optional<unsigned> NumExpansions) { |
| 893 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 894 | NumExpansions); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 897 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 898 | /// identifier that names the next step in the nested-name-specifier. |
| 899 | /// |
| 900 | /// By default, performs semantic analysis when building the new |
| 901 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 902 | /// different behavior. |
| 903 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 904 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 905 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 906 | QualType ObjectType, |
| 907 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 908 | |
| 909 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 910 | /// namespace named in the next step in the nested-name-specifier. |
| 911 | /// |
| 912 | /// By default, performs semantic analysis when building the new |
| 913 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 914 | /// different behavior. |
| 915 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 916 | SourceRange Range, |
| 917 | NamespaceDecl *NS); |
| 918 | |
| 919 | /// \brief Build a new nested-name-specifier given the prefix and the |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 920 | /// namespace alias named in the next step in the nested-name-specifier. |
| 921 | /// |
| 922 | /// By default, performs semantic analysis when building the new |
| 923 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 924 | /// different behavior. |
| 925 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 926 | SourceRange Range, |
| 927 | NamespaceAliasDecl *Alias); |
| 928 | |
| 929 | /// \brief Build a new nested-name-specifier given the prefix and the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 930 | /// type named in the next step in the nested-name-specifier. |
| 931 | /// |
| 932 | /// By default, performs semantic analysis when building the new |
| 933 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 934 | /// different behavior. |
| 935 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 936 | SourceRange Range, |
| 937 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 938 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 939 | |
| 940 | /// \brief Build a new template name given a nested name specifier, a flag |
| 941 | /// indicating whether the "template" keyword was provided, and the template |
| 942 | /// that the template name refers to. |
| 943 | /// |
| 944 | /// By default, builds the new template name directly. Subclasses may override |
| 945 | /// this routine to provide different behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 946 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 947 | bool TemplateKW, |
| 948 | TemplateDecl *Template); |
| 949 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 950 | /// \brief Build a new template name given a nested name specifier and the |
| 951 | /// name that is referred to as a template. |
| 952 | /// |
| 953 | /// By default, performs semantic analysis to determine whether the name can |
| 954 | /// be resolved to a specific template, then builds the appropriate kind of |
| 955 | /// template name. Subclasses may override this routine to provide different |
| 956 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 957 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 958 | const IdentifierInfo &Name, |
| 959 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 960 | QualType ObjectType, |
| 961 | NamedDecl *FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 962 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 963 | /// \brief Build a new template name given a nested name specifier and the |
| 964 | /// overloaded operator name that is referred to as a template. |
| 965 | /// |
| 966 | /// By default, performs semantic analysis to determine whether the name can |
| 967 | /// be resolved to a specific template, then builds the appropriate kind of |
| 968 | /// template name. Subclasses may override this routine to provide different |
| 969 | /// behavior. |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 970 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 971 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 972 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 973 | QualType ObjectType); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 974 | |
| 975 | /// \brief Build a new template name given a template template parameter pack |
| 976 | /// and the |
| 977 | /// |
| 978 | /// By default, performs semantic analysis to determine whether the name can |
| 979 | /// be resolved to a specific template, then builds the appropriate kind of |
| 980 | /// template name. Subclasses may override this routine to provide different |
| 981 | /// behavior. |
| 982 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 983 | const TemplateArgument &ArgPack) { |
| 984 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 985 | } |
| 986 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 987 | /// \brief Build a new compound statement. |
| 988 | /// |
| 989 | /// By default, performs semantic analysis to build the new statement. |
| 990 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 991 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 992 | MultiStmtArg Statements, |
| 993 | SourceLocation RBraceLoc, |
| 994 | bool IsStmtExpr) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 995 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 996 | IsStmtExpr); |
| 997 | } |
| 998 | |
| 999 | /// \brief Build a new case statement. |
| 1000 | /// |
| 1001 | /// By default, performs semantic analysis to build the new statement. |
| 1002 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1003 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1004 | Expr *LHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1005 | SourceLocation EllipsisLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1006 | Expr *RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1007 | SourceLocation ColonLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1008 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1009 | ColonLoc); |
| 1010 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1012 | /// \brief Attach the body to a new case statement. |
| 1013 | /// |
| 1014 | /// By default, performs semantic analysis to build the new statement. |
| 1015 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1016 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1017 | getSema().ActOnCaseStmtBody(S, Body); |
| 1018 | return S; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1019 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1021 | /// \brief Build a new default statement. |
| 1022 | /// |
| 1023 | /// By default, performs semantic analysis to build the new statement. |
| 1024 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1025 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1026 | SourceLocation ColonLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1027 | Stmt *SubStmt) { |
| 1028 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1029 | /*CurScope=*/0); |
| 1030 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1032 | /// \brief Build a new label 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 RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1037 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1038 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
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 "if" 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 RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1046 | VarDecl *CondVar, Stmt *Then, |
| 1047 | SourceLocation ElseLoc, Stmt *Else) { |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 1048 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1051 | /// \brief Start building a new switch statement. |
| 1052 | /// |
| 1053 | /// By default, performs semantic analysis to build the new statement. |
| 1054 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1055 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1056 | Expr *Cond, VarDecl *CondVar) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1057 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1058 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1059 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1061 | /// \brief Attach the body to the switch statement. |
| 1062 | /// |
| 1063 | /// By default, performs semantic analysis to build the new statement. |
| 1064 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1065 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1066 | Stmt *Switch, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1067 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /// \brief Build a new while statement. |
| 1071 | /// |
| 1072 | /// By default, performs semantic analysis to build the new statement. |
| 1073 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1074 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, |
| 1075 | VarDecl *CondVar, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1076 | return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1079 | /// \brief Build a new do-while statement. |
| 1080 | /// |
| 1081 | /// By default, performs semantic analysis to build the new statement. |
| 1082 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1083 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1084 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1085 | Expr *Cond, SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1086 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1087 | Cond, RParenLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /// \brief Build a new for statement. |
| 1091 | /// |
| 1092 | /// By default, performs semantic analysis to build the new statement. |
| 1093 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1094 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1095 | Stmt *Init, Sema::FullExprArg Cond, |
| 1096 | VarDecl *CondVar, Sema::FullExprArg Inc, |
| 1097 | SourceLocation RParenLoc, Stmt *Body) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1098 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1099 | CondVar, Inc, RParenLoc, Body); |
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 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1102 | /// \brief Build a new goto statement. |
| 1103 | /// |
| 1104 | /// By default, performs semantic analysis to build the new statement. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1106 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1107 | LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1108 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /// \brief Build a new indirect goto statement. |
| 1112 | /// |
| 1113 | /// By default, performs semantic analysis to build the new statement. |
| 1114 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1115 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1116 | SourceLocation StarLoc, |
| 1117 | Expr *Target) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1118 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1119 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1121 | /// \brief Build a new return statement. |
| 1122 | /// |
| 1123 | /// By default, performs semantic analysis to build the new statement. |
| 1124 | /// Subclasses may override this routine to provide different behavior. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1125 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1126 | return getSema().ActOnReturnStmt(ReturnLoc, Result); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1127 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1129 | /// \brief Build a new declaration statement. |
| 1130 | /// |
| 1131 | /// By default, performs semantic analysis to build the new statement. |
| 1132 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1133 | StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1134 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1135 | SourceLocation EndLoc) { |
Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1136 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); |
| 1137 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1138 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1140 | /// \brief Build a new inline asm statement. |
| 1141 | /// |
| 1142 | /// By default, performs semantic analysis to build the new statement. |
| 1143 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1144 | StmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1145 | bool IsSimple, |
| 1146 | bool IsVolatile, |
| 1147 | unsigned NumOutputs, |
| 1148 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 1149 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1150 | MultiExprArg Constraints, |
| 1151 | MultiExprArg Exprs, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1152 | Expr *AsmString, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1153 | MultiExprArg Clobbers, |
| 1154 | SourceLocation RParenLoc, |
| 1155 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1156 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1157 | NumInputs, Names, move(Constraints), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1158 | Exprs, AsmString, Clobbers, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1159 | RParenLoc, MSAsm); |
| 1160 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1161 | |
| 1162 | /// \brief Build a new Objective-C @try statement. |
| 1163 | /// |
| 1164 | /// By default, performs semantic analysis to build the new statement. |
| 1165 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1166 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1167 | Stmt *TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1168 | MultiStmtArg CatchStmts, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1169 | Stmt *Finally) { |
| 1170 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), |
| 1171 | Finally); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1174 | /// \brief Rebuild an Objective-C exception declaration. |
| 1175 | /// |
| 1176 | /// By default, performs semantic analysis to build the new declaration. |
| 1177 | /// Subclasses may override this routine to provide different behavior. |
| 1178 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1179 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1180 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1181 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1182 | ExceptionDecl->getLocation()); |
| 1183 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1185 | /// \brief Build a new Objective-C @catch statement. |
| 1186 | /// |
| 1187 | /// By default, performs semantic analysis to build the new statement. |
| 1188 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1189 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1190 | SourceLocation RParenLoc, |
| 1191 | VarDecl *Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1192 | Stmt *Body) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1193 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1194 | Var, Body); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1195 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1197 | /// \brief Build a new Objective-C @finally statement. |
| 1198 | /// |
| 1199 | /// By default, performs semantic analysis to build the new statement. |
| 1200 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1201 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1202 | Stmt *Body) { |
| 1203 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1204 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1206 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1207 | /// |
| 1208 | /// By default, performs semantic analysis to build the new statement. |
| 1209 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1210 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1211 | Expr *Operand) { |
| 1212 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1213 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1214 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1215 | /// \brief Build a new Objective-C @synchronized statement. |
| 1216 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1217 | /// By default, performs semantic analysis to build the new statement. |
| 1218 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1219 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1220 | Expr *Object, |
| 1221 | Stmt *Body) { |
| 1222 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, |
| 1223 | Body); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1224 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1225 | |
| 1226 | /// \brief Build a new Objective-C fast enumeration statement. |
| 1227 | /// |
| 1228 | /// By default, performs semantic analysis to build the new statement. |
| 1229 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1230 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1231 | SourceLocation LParenLoc, |
| 1232 | Stmt *Element, |
| 1233 | Expr *Collection, |
| 1234 | SourceLocation RParenLoc, |
| 1235 | Stmt *Body) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1236 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1237 | Element, |
| 1238 | Collection, |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1239 | RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1240 | Body); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1241 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1243 | /// \brief Build a new C++ exception declaration. |
| 1244 | /// |
| 1245 | /// By default, performs semantic analysis to build the new decaration. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1247 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1248 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1249 | IdentifierInfo *Name, |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 1250 | SourceLocation Loc) { |
| 1251 | return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | /// \brief Build a new C++ catch statement. |
| 1255 | /// |
| 1256 | /// By default, performs semantic analysis to build the new statement. |
| 1257 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1258 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1259 | VarDecl *ExceptionDecl, |
| 1260 | Stmt *Handler) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1261 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 1262 | Handler)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1265 | /// \brief Build a new C++ try statement. |
| 1266 | /// |
| 1267 | /// By default, performs semantic analysis to build the new statement. |
| 1268 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1269 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1270 | Stmt *TryBlock, |
| 1271 | MultiStmtArg Handlers) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1272 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1274 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1275 | /// \brief Build a new expression that references a declaration. |
| 1276 | /// |
| 1277 | /// By default, performs semantic analysis to build the new expression. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1279 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1280 | LookupResult &R, |
| 1281 | bool RequiresADL) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1282 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | /// \brief Build a new expression that references a declaration. |
| 1287 | /// |
| 1288 | /// By default, performs semantic analysis to build the new expression. |
| 1289 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1290 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1291 | ValueDecl *VD, |
| 1292 | const DeclarationNameInfo &NameInfo, |
| 1293 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1294 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1295 | SS.Adopt(QualifierLoc); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1296 | |
| 1297 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1298 | |
| 1299 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1302 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | /// By default, performs semantic analysis to build the new expression. |
| 1305 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1306 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | SourceLocation RParen) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1308 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1311 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1313 | /// By default, performs semantic analysis to build the new expression. |
| 1314 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1315 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 1316 | SourceLocation OperatorLoc, |
| 1317 | bool isArrow, |
| 1318 | CXXScopeSpec &SS, |
| 1319 | TypeSourceInfo *ScopeType, |
| 1320 | SourceLocation CCLoc, |
| 1321 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1322 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// By default, performs semantic analysis to build the new expression. |
| 1327 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1328 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1329 | UnaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1330 | Expr *SubExpr) { |
| 1331 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1334 | /// \brief Build a new builtin offsetof expression. |
| 1335 | /// |
| 1336 | /// By default, performs semantic analysis to build the new expression. |
| 1337 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1338 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1339 | TypeSourceInfo *Type, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1340 | Sema::OffsetOfComponent *Components, |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1341 | unsigned NumComponents, |
| 1342 | SourceLocation RParenLoc) { |
| 1343 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1344 | NumComponents, RParenLoc); |
| 1345 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1346 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | /// By default, performs semantic analysis to build the new expression. |
| 1350 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1351 | ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1352 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1354 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1360 | /// By default, performs semantic analysis to build the new expression. |
| 1361 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1362 | ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | bool isSizeOf, SourceRange R) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1364 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1365 | = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1366 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1367 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1368 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1369 | return move(Result); |
| 1370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1374 | /// By default, performs semantic analysis to build the new expression. |
| 1375 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1376 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1377 | SourceLocation LBracketLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1378 | Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | SourceLocation RBracketLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1380 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, |
| 1381 | LBracketLoc, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1382 | RBracketLoc); |
| 1383 | } |
| 1384 | |
| 1385 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1386 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1387 | /// By default, performs semantic analysis to build the new expression. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1389 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1390 | MultiExprArg Args, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1391 | SourceLocation RParenLoc, |
| 1392 | Expr *ExecConfig = 0) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1393 | return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1394 | move(Args), RParenLoc, ExecConfig); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// By default, performs semantic analysis to build the new expression. |
| 1400 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1401 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1402 | bool isArrow, |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1403 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1404 | const DeclarationNameInfo &MemberNameInfo, |
| 1405 | ValueDecl *Member, |
| 1406 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1407 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1408 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1409 | if (!Member->getDeclName()) { |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1410 | // We have a reference to an unnamed field. This is always the |
| 1411 | // base of an anonymous struct/union member access, i.e. the |
| 1412 | // field is always of record type. |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1413 | assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1414 | assert(Member->getType()->isRecordType() && |
| 1415 | "unnamed member not of record type?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1417 | if (getSema().PerformObjectMemberConversion(Base, |
| 1418 | QualifierLoc.getNestedNameSpecifier(), |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1419 | FoundDecl, Member)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1420 | return ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1421 | |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1422 | ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | MemberExpr *ME = |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1424 | new (getSema().Context) MemberExpr(Base, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1425 | Member, MemberNameInfo, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 1426 | cast<FieldDecl>(Member)->getType(), |
| 1427 | VK, OK_Ordinary); |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1428 | return getSema().Owned(ME); |
| 1429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1431 | CXXScopeSpec SS; |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 1432 | SS.Adopt(QualifierLoc); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1433 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1434 | getSema().DefaultFunctionArrayConversion(Base); |
| 1435 | QualType BaseType = Base->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1436 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1437 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1438 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1439 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1440 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1441 | R.resolveKind(); |
| 1442 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1443 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1444 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1445 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1450 | /// By default, performs semantic analysis to build the new expression. |
| 1451 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1452 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 1453 | BinaryOperatorKind Opc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1454 | Expr *LHS, Expr *RHS) { |
| 1455 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1459 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | /// By default, performs semantic analysis to build the new expression. |
| 1461 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1462 | ExprResult RebuildConditionalOperator(Expr *Cond, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1463 | SourceLocation QuestionLoc, |
| 1464 | Expr *LHS, |
| 1465 | SourceLocation ColonLoc, |
| 1466 | Expr *RHS) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1467 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 1468 | LHS, RHS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1472 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1473 | /// By default, performs semantic analysis to build the new expression. |
| 1474 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1475 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1476 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1478 | Expr *SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1479 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1480 | SubExpr); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1482 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1483 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1484 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | /// By default, performs semantic analysis to build the new expression. |
| 1486 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1487 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1488 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | SourceLocation RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1490 | Expr *Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1491 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1492 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1496 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1497 | /// By default, performs semantic analysis to build the new expression. |
| 1498 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1499 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | SourceLocation OpLoc, |
| 1501 | SourceLocation AccessorLoc, |
| 1502 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1503 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1504 | CXXScopeSpec SS; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1505 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1506 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1507 | OpLoc, /*IsArrow*/ false, |
| 1508 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1509 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1510 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1514 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1515 | /// By default, performs semantic analysis to build the new expression. |
| 1516 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1517 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1519 | SourceLocation RBraceLoc, |
| 1520 | QualType ResultTy) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1521 | ExprResult Result |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1522 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1523 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1524 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1525 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1526 | // Patch in the result type we were given, which may have been computed |
| 1527 | // when the initial InitListExpr was built. |
| 1528 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1529 | ILE->setType(ResultTy); |
| 1530 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1534 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1535 | /// By default, performs semantic analysis to build the new expression. |
| 1536 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1537 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1538 | MultiExprArg ArrayExprs, |
| 1539 | SourceLocation EqualOrColonLoc, |
| 1540 | bool GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1541 | Expr *Init) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1542 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1543 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1544 | Init); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1545 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1546 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | ArrayExprs.release(); |
| 1549 | return move(Result); |
| 1550 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1551 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1553 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1554 | /// By default, builds the implicit value initialization without performing |
| 1555 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1556 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1557 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1562 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1563 | /// By default, performs semantic analysis to build the new expression. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1565 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1566 | Expr *SubExpr, TypeSourceInfo *TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1567 | SourceLocation RParenLoc) { |
| 1568 | return getSema().BuildVAArgExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1569 | SubExpr, TInfo, |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1570 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1574 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1575 | /// By default, performs semantic analysis to build the new expression. |
| 1576 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1577 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | MultiExprArg SubExprs, |
| 1579 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1580 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1581 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1584 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1585 | /// |
| 1586 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | /// rather than attempting to map the label statement itself. |
| 1588 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1589 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1590 | SourceLocation LabelLoc, LabelDecl *Label) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1591 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1595 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1596 | /// By default, performs semantic analysis to build the new expression. |
| 1597 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1598 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1599 | Stmt *SubStmt, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1601 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1602 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1603 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | /// \brief Build a new __builtin_choose_expr expression. |
| 1605 | /// |
| 1606 | /// By default, performs semantic analysis to build the new expression. |
| 1607 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1608 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1609 | Expr *Cond, Expr *LHS, Expr *RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | SourceLocation RParenLoc) { |
| 1611 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1612 | Cond, LHS, RHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1613 | RParenLoc); |
| 1614 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | /// \brief Build a new overloaded operator call expression. |
| 1617 | /// |
| 1618 | /// By default, performs semantic analysis to build the new expression. |
| 1619 | /// The semantic analysis provides the behavior of template instantiation, |
| 1620 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1621 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1623 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1624 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1626 | Expr *Callee, |
| 1627 | Expr *First, |
| 1628 | Expr *Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | |
| 1630 | /// \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] | 1631 | /// reinterpret_cast. |
| 1632 | /// |
| 1633 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1636 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | Stmt::StmtClass Class, |
| 1638 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1639 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | SourceLocation RAngleLoc, |
| 1641 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1642 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | SourceLocation RParenLoc) { |
| 1644 | switch (Class) { |
| 1645 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1646 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1648 | SubExpr, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | |
| 1650 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1651 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1653 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1656 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1658 | SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1659 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1662 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1663 | RAngleLoc, LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1664 | SubExpr, RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | default: |
| 1667 | assert(false && "Invalid C++ named cast"); |
| 1668 | break; |
| 1669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1671 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1673 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1674 | /// \brief Build a new C++ static_cast expression. |
| 1675 | /// |
| 1676 | /// By default, performs semantic analysis to build the new expression. |
| 1677 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1678 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1680 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | SourceLocation RAngleLoc, |
| 1682 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1683 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1684 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1685 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1686 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1687 | SourceRange(LAngleLoc, RAngleLoc), |
| 1688 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | /// \brief Build a new C++ dynamic_cast expression. |
| 1692 | /// |
| 1693 | /// By default, performs semantic analysis to build the new expression. |
| 1694 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1695 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1697 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | SourceLocation RAngleLoc, |
| 1699 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1700 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1702 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1703 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1704 | SourceRange(LAngleLoc, RAngleLoc), |
| 1705 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1709 | /// |
| 1710 | /// By default, performs semantic analysis to build the new expression. |
| 1711 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1712 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1713 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1714 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1715 | SourceLocation RAngleLoc, |
| 1716 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1717 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1719 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1720 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1721 | SourceRange(LAngleLoc, RAngleLoc), |
| 1722 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | /// \brief Build a new C++ const_cast expression. |
| 1726 | /// |
| 1727 | /// By default, performs semantic analysis to build the new expression. |
| 1728 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1729 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1731 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | SourceLocation RAngleLoc, |
| 1733 | SourceLocation LParenLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1734 | Expr *SubExpr, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1735 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1736 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1737 | TInfo, SubExpr, |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1738 | SourceRange(LAngleLoc, RAngleLoc), |
| 1739 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | /// \brief Build a new C++ functional-style cast expression. |
| 1743 | /// |
| 1744 | /// By default, performs semantic analysis to build the new expression. |
| 1745 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1746 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 1747 | SourceLocation LParenLoc, |
| 1748 | Expr *Sub, |
| 1749 | SourceLocation RParenLoc) { |
| 1750 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1751 | MultiExprArg(&Sub, 1), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1752 | RParenLoc); |
| 1753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1755 | /// \brief Build a new C++ typeid(type) expression. |
| 1756 | /// |
| 1757 | /// By default, performs semantic analysis to build the new expression. |
| 1758 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1759 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1760 | SourceLocation TypeidLoc, |
| 1761 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1762 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1763 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1764 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1765 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1768 | /// \brief Build a new C++ typeid(expr) expression. |
| 1769 | /// |
| 1770 | /// By default, performs semantic analysis to build the new expression. |
| 1771 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1772 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1773 | SourceLocation TypeidLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1774 | Expr *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1775 | SourceLocation RParenLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1776 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1777 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1780 | /// \brief Build a new C++ __uuidof(type) expression. |
| 1781 | /// |
| 1782 | /// By default, performs semantic analysis to build the new expression. |
| 1783 | /// Subclasses may override this routine to provide different behavior. |
| 1784 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1785 | SourceLocation TypeidLoc, |
| 1786 | TypeSourceInfo *Operand, |
| 1787 | SourceLocation RParenLoc) { |
| 1788 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1789 | RParenLoc); |
| 1790 | } |
| 1791 | |
| 1792 | /// \brief Build a new C++ __uuidof(expr) expression. |
| 1793 | /// |
| 1794 | /// By default, performs semantic analysis to build the new expression. |
| 1795 | /// Subclasses may override this routine to provide different behavior. |
| 1796 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 1797 | SourceLocation TypeidLoc, |
| 1798 | Expr *Operand, |
| 1799 | SourceLocation RParenLoc) { |
| 1800 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 1801 | RParenLoc); |
| 1802 | } |
| 1803 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1804 | /// \brief Build a new C++ "this" expression. |
| 1805 | /// |
| 1806 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1808 | /// different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1809 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 1810 | QualType ThisType, |
| 1811 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1812 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1813 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1814 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /// \brief Build a new C++ throw expression. |
| 1818 | /// |
| 1819 | /// By default, performs semantic analysis to build the new expression. |
| 1820 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1821 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1822 | return getSema().ActOnCXXThrow(ThrowLoc, Sub); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | /// \brief Build a new C++ default-argument expression. |
| 1826 | /// |
| 1827 | /// By default, builds a new default-argument expression, which does not |
| 1828 | /// require any semantic analysis. Subclasses may override this routine to |
| 1829 | /// provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1830 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1831 | ParmVarDecl *Param) { |
| 1832 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1833 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /// \brief Build a new C++ zero-initialization expression. |
| 1837 | /// |
| 1838 | /// By default, performs semantic analysis to build the new expression. |
| 1839 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1840 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 1841 | SourceLocation LParenLoc, |
| 1842 | SourceLocation RParenLoc) { |
| 1843 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1845 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1846 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1848 | /// \brief Build a new C++ "new" expression. |
| 1849 | /// |
| 1850 | /// By default, performs semantic analysis to build the new expression. |
| 1851 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1852 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1853 | bool UseGlobal, |
| 1854 | SourceLocation PlacementLParen, |
| 1855 | MultiExprArg PlacementArgs, |
| 1856 | SourceLocation PlacementRParen, |
| 1857 | SourceRange TypeIdParens, |
| 1858 | QualType AllocatedType, |
| 1859 | TypeSourceInfo *AllocatedTypeInfo, |
| 1860 | Expr *ArraySize, |
| 1861 | SourceLocation ConstructorLParen, |
| 1862 | MultiExprArg ConstructorArgs, |
| 1863 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1865 | PlacementLParen, |
| 1866 | move(PlacementArgs), |
| 1867 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1868 | TypeIdParens, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 1869 | AllocatedType, |
| 1870 | AllocatedTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1871 | ArraySize, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1872 | ConstructorLParen, |
| 1873 | move(ConstructorArgs), |
| 1874 | ConstructorRParen); |
| 1875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1877 | /// \brief Build a new C++ "delete" expression. |
| 1878 | /// |
| 1879 | /// By default, performs semantic analysis to build the new expression. |
| 1880 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1881 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1882 | bool IsGlobalDelete, |
| 1883 | bool IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1884 | Expr *Operand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1885 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1886 | Operand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1887 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1889 | /// \brief Build a new unary type trait expression. |
| 1890 | /// |
| 1891 | /// By default, performs semantic analysis to build the new expression. |
| 1892 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1893 | ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 1894 | SourceLocation StartLoc, |
| 1895 | TypeSourceInfo *T, |
| 1896 | SourceLocation RParenLoc) { |
| 1897 | return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1900 | /// \brief Build a new binary type trait expression. |
| 1901 | /// |
| 1902 | /// By default, performs semantic analysis to build the new expression. |
| 1903 | /// Subclasses may override this routine to provide different behavior. |
| 1904 | ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, |
| 1905 | SourceLocation StartLoc, |
| 1906 | TypeSourceInfo *LhsT, |
| 1907 | TypeSourceInfo *RhsT, |
| 1908 | SourceLocation RParenLoc) { |
| 1909 | return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); |
| 1910 | } |
| 1911 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1913 | /// expression. |
| 1914 | /// |
| 1915 | /// By default, performs semantic analysis to build the new expression. |
| 1916 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1917 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 1918 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1919 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1920 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1921 | CXXScopeSpec SS; |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 1922 | SS.Adopt(QualifierLoc); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1923 | |
| 1924 | if (TemplateArgs) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1925 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1926 | *TemplateArgs); |
| 1927 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1928 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | /// \brief Build a new template-id expression. |
| 1932 | /// |
| 1933 | /// By default, performs semantic analysis to build the new expression. |
| 1934 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1935 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1936 | LookupResult &R, |
| 1937 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1938 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1939 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /// \brief Build a new object-construction expression. |
| 1943 | /// |
| 1944 | /// By default, performs semantic analysis to build the new expression. |
| 1945 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1946 | ExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1947 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1948 | CXXConstructorDecl *Constructor, |
| 1949 | bool IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1950 | MultiExprArg Args, |
| 1951 | bool RequiresZeroInit, |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1952 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 1953 | SourceRange ParenRange) { |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1954 | ASTOwningVector<Expr*> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1955 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1956 | ConvertedArgs)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1957 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1959 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 1960 | move_arg(ConvertedArgs), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 1961 | RequiresZeroInit, ConstructKind, |
| 1962 | ParenRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /// \brief Build a new object-construction expression. |
| 1966 | /// |
| 1967 | /// By default, performs semantic analysis to build the new expression. |
| 1968 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1969 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 1970 | SourceLocation LParenLoc, |
| 1971 | MultiExprArg Args, |
| 1972 | SourceLocation RParenLoc) { |
| 1973 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1974 | LParenLoc, |
| 1975 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1976 | RParenLoc); |
| 1977 | } |
| 1978 | |
| 1979 | /// \brief Build a new object-construction expression. |
| 1980 | /// |
| 1981 | /// By default, performs semantic analysis to build the new expression. |
| 1982 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 1983 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 1984 | SourceLocation LParenLoc, |
| 1985 | MultiExprArg Args, |
| 1986 | SourceLocation RParenLoc) { |
| 1987 | return getSema().BuildCXXTypeConstructExpr(TSInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1988 | LParenLoc, |
| 1989 | move(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1990 | RParenLoc); |
| 1991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | /// \brief Build a new member reference expression. |
| 1994 | /// |
| 1995 | /// By default, performs semantic analysis to build the new expression. |
| 1996 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1997 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 1998 | QualType BaseType, |
| 1999 | bool IsArrow, |
| 2000 | SourceLocation OperatorLoc, |
| 2001 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2002 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2003 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2004 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2005 | CXXScopeSpec SS; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2006 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2008 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2009 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2010 | SS, FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2011 | MemberNameInfo, |
| 2012 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2015 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2016 | /// |
| 2017 | /// By default, performs semantic analysis to build the new expression. |
| 2018 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2019 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2020 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2021 | SourceLocation OperatorLoc, |
| 2022 | bool IsArrow, |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2023 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2024 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2025 | LookupResult &R, |
| 2026 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2027 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2028 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2030 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2031 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2032 | SS, FirstQualifierInScope, |
| 2033 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2036 | /// \brief Build a new noexcept expression. |
| 2037 | /// |
| 2038 | /// By default, performs semantic analysis to build the new expression. |
| 2039 | /// Subclasses may override this routine to provide different behavior. |
| 2040 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2041 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2042 | } |
| 2043 | |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2044 | /// \brief Build a new expression to compute the length of a parameter pack. |
| 2045 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 2046 | SourceLocation PackLoc, |
| 2047 | SourceLocation RParenLoc, |
| 2048 | unsigned Length) { |
| 2049 | return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), |
| 2050 | OperatorLoc, Pack, PackLoc, |
| 2051 | RParenLoc, Length); |
| 2052 | } |
| 2053 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2054 | /// \brief Build a new Objective-C @encode expression. |
| 2055 | /// |
| 2056 | /// By default, performs semantic analysis to build the new expression. |
| 2057 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2058 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2059 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2060 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2061 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2062 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2063 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2064 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2065 | /// \brief Build a new Objective-C class message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2066 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2067 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2068 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2069 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2070 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2071 | MultiExprArg Args, |
| 2072 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2073 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2074 | ReceiverTypeInfo->getType(), |
| 2075 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2076 | Sel, Method, LBracLoc, SelectorLoc, |
| 2077 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /// \brief Build a new Objective-C instance message. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2081 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2082 | Selector Sel, |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2083 | SourceLocation SelectorLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2084 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2085 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2086 | MultiExprArg Args, |
| 2087 | SourceLocation RBracLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2088 | return SemaRef.BuildInstanceMessage(Receiver, |
| 2089 | Receiver->getType(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2090 | /*SuperLoc=*/SourceLocation(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 2091 | Sel, Method, LBracLoc, SelectorLoc, |
| 2092 | RBracLoc, move(Args)); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2095 | /// \brief Build a new Objective-C ivar reference expression. |
| 2096 | /// |
| 2097 | /// By default, performs semantic analysis to build the new expression. |
| 2098 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2099 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2100 | SourceLocation IvarLoc, |
| 2101 | bool IsArrow, bool IsFreeIvar) { |
| 2102 | // FIXME: We lose track of the IsFreeIvar bit. |
| 2103 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2104 | Expr *Base = BaseArg; |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2105 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 2106 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2107 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2108 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2109 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 2110 | false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2111 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2112 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2113 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2114 | if (Result.get()) |
| 2115 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2116 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2117 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2118 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2119 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2120 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2121 | /*TemplateArgs=*/0); |
| 2122 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2123 | |
| 2124 | /// \brief Build a new Objective-C property reference expression. |
| 2125 | /// |
| 2126 | /// By default, performs semantic analysis to build the new expression. |
| 2127 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2128 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2129 | ObjCPropertyDecl *Property, |
| 2130 | SourceLocation PropertyLoc) { |
| 2131 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2132 | Expr *Base = BaseArg; |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2133 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 2134 | Sema::LookupMemberName); |
| 2135 | bool IsArrow = false; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2136 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2137 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2138 | SS, 0, false); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2139 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2140 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2141 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2142 | if (Result.get()) |
| 2143 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2144 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2145 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2146 | /*FIXME:*/PropertyLoc, IsArrow, |
| 2147 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2148 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2149 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 2150 | /*TemplateArgs=*/0); |
| 2151 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2152 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2153 | /// \brief Build a new Objective-C property reference expression. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2154 | /// |
| 2155 | /// By default, performs semantic analysis to build the new expression. |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 2156 | /// Subclasses may override this routine to provide different behavior. |
| 2157 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 2158 | ObjCMethodDecl *Getter, |
| 2159 | ObjCMethodDecl *Setter, |
| 2160 | SourceLocation PropertyLoc) { |
| 2161 | // Since these expressions can only be value-dependent, we do not |
| 2162 | // need to perform semantic analysis again. |
| 2163 | return Owned( |
| 2164 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 2165 | VK_LValue, OK_ObjCProperty, |
| 2166 | PropertyLoc, Base)); |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2169 | /// \brief Build a new Objective-C "isa" expression. |
| 2170 | /// |
| 2171 | /// By default, performs semantic analysis to build the new expression. |
| 2172 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2173 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2174 | bool IsArrow) { |
| 2175 | CXXScopeSpec SS; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2176 | Expr *Base = BaseArg; |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2177 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 2178 | Sema::LookupMemberName); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2179 | ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2180 | /*FIME:*/IsaLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2181 | SS, 0, false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2182 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2183 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2184 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2185 | if (Result.get()) |
| 2186 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2187 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2188 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2189 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2190 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2191 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 2192 | /*TemplateArgs=*/0); |
| 2193 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2194 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2195 | /// \brief Build a new shuffle vector expression. |
| 2196 | /// |
| 2197 | /// By default, performs semantic analysis to build the new expression. |
| 2198 | /// Subclasses may override this routine to provide different behavior. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2199 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2200 | MultiExprArg SubExprs, |
| 2201 | SourceLocation RParenLoc) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2202 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2203 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2204 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 2205 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 2206 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 2207 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2209 | // Build a reference to the __builtin_shufflevector builtin |
| 2210 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2211 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2212 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2213 | VK_LValue, BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2214 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2215 | |
| 2216 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2217 | unsigned NumSubExprs = SubExprs.size(); |
| 2218 | Expr **Subs = (Expr **)SubExprs.release(); |
| 2219 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 2220 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2221 | Builtin->getCallResultType(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2222 | Expr::getValueKindForType(Builtin->getResultType()), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2223 | RParenLoc); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2224 | ExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2226 | // Type-check the __builtin_shufflevector expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2227 | ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2228 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2229 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2230 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2231 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2232 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2233 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2234 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2235 | /// \brief Build a new template argument pack expansion. |
| 2236 | /// |
| 2237 | /// By default, performs semantic analysis to build a new pack expansion |
| 2238 | /// for a template argument. Subclasses may override this routine to provide |
| 2239 | /// different behavior. |
| 2240 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2241 | SourceLocation EllipsisLoc, |
| 2242 | llvm::Optional<unsigned> NumExpansions) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2243 | switch (Pattern.getArgument().getKind()) { |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2244 | case TemplateArgument::Expression: { |
| 2245 | ExprResult Result |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2246 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 2247 | EllipsisLoc, NumExpansions); |
Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 2248 | if (Result.isInvalid()) |
| 2249 | return TemplateArgumentLoc(); |
| 2250 | |
| 2251 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 2252 | } |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2253 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2254 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2255 | return TemplateArgumentLoc(TemplateArgument( |
| 2256 | Pattern.getArgument().getAsTemplate(), |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 2257 | NumExpansions), |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2258 | Pattern.getTemplateQualifierLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2259 | Pattern.getTemplateNameLoc(), |
| 2260 | EllipsisLoc); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2261 | |
| 2262 | case TemplateArgument::Null: |
| 2263 | case TemplateArgument::Integral: |
| 2264 | case TemplateArgument::Declaration: |
| 2265 | case TemplateArgument::Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2266 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2267 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 2268 | |
| 2269 | case TemplateArgument::Type: |
| 2270 | if (TypeSourceInfo *Expansion |
| 2271 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2272 | EllipsisLoc, |
| 2273 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2274 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 2275 | Expansion); |
| 2276 | break; |
| 2277 | } |
| 2278 | |
| 2279 | return TemplateArgumentLoc(); |
| 2280 | } |
| 2281 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2282 | /// \brief Build a new expression pack expansion. |
| 2283 | /// |
| 2284 | /// By default, performs semantic analysis to build a new pack expansion |
| 2285 | /// for an expression. Subclasses may override this routine to provide |
| 2286 | /// different behavior. |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2287 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 2288 | llvm::Optional<unsigned> NumExpansions) { |
| 2289 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2292 | private: |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2293 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 2294 | QualType ObjectType, |
| 2295 | NamedDecl *FirstQualifierInScope, |
| 2296 | CXXScopeSpec &SS); |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 2297 | |
| 2298 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 2299 | QualType ObjectType, |
| 2300 | NamedDecl *FirstQualifierInScope, |
| 2301 | CXXScopeSpec &SS); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2302 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2303 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2304 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2305 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2306 | if (!S) |
| 2307 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2308 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2309 | switch (S->getStmtClass()) { |
| 2310 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2312 | // Transform individual statement nodes |
| 2313 | #define STMT(Node, Parent) \ |
| 2314 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 2315 | #define ABSTRACT_STMT(Node) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2316 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2317 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2318 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2319 | // Transform expressions by calling TransformExpr. |
| 2320 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2321 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2322 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2323 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2324 | { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2325 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2326 | if (E.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2327 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2328 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2329 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2333 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2334 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2335 | |
| 2336 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2337 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2338 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2339 | if (!E) |
| 2340 | return SemaRef.Owned(E); |
| 2341 | |
| 2342 | switch (E->getStmtClass()) { |
| 2343 | case Stmt::NoStmtClass: break; |
| 2344 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2345 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2346 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2347 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2348 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 2351 | return SemaRef.Owned(E); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | template<typename Derived> |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2355 | bool TreeTransform<Derived>::TransformExprs(Expr **Inputs, |
| 2356 | unsigned NumInputs, |
| 2357 | bool IsCall, |
| 2358 | llvm::SmallVectorImpl<Expr *> &Outputs, |
| 2359 | bool *ArgChanged) { |
| 2360 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 2361 | // If requested, drop call arguments that need to be dropped. |
| 2362 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 2363 | if (ArgChanged) |
| 2364 | *ArgChanged = true; |
| 2365 | |
| 2366 | break; |
| 2367 | } |
| 2368 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2369 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 2370 | Expr *Pattern = Expansion->getPattern(); |
| 2371 | |
| 2372 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2373 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2374 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2375 | |
| 2376 | // Determine whether the set of unexpanded parameter packs can and should |
| 2377 | // be expanded. |
| 2378 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2379 | bool RetainExpansion = false; |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2380 | llvm::Optional<unsigned> OrigNumExpansions |
| 2381 | = Expansion->getNumExpansions(); |
| 2382 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2383 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 2384 | Pattern->getSourceRange(), |
| 2385 | Unexpanded.data(), |
| 2386 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2387 | Expand, RetainExpansion, |
| 2388 | NumExpansions)) |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2389 | return true; |
| 2390 | |
| 2391 | if (!Expand) { |
| 2392 | // The transform has determined that we should perform a simple |
| 2393 | // transformation on the pack expansion, producing another pack |
| 2394 | // expansion. |
| 2395 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2396 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 2397 | if (OutPattern.isInvalid()) |
| 2398 | return true; |
| 2399 | |
| 2400 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2401 | Expansion->getEllipsisLoc(), |
| 2402 | NumExpansions); |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2403 | if (Out.isInvalid()) |
| 2404 | return true; |
| 2405 | |
| 2406 | if (ArgChanged) |
| 2407 | *ArgChanged = true; |
| 2408 | Outputs.push_back(Out.get()); |
| 2409 | continue; |
| 2410 | } |
| 2411 | |
| 2412 | // The transform has determined that we should perform an elementwise |
| 2413 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2414 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2415 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2416 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 2417 | if (Out.isInvalid()) |
| 2418 | return true; |
| 2419 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2420 | if (Out.get()->containsUnexpandedParameterPack()) { |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 2421 | Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), |
| 2422 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2423 | if (Out.isInvalid()) |
| 2424 | return true; |
| 2425 | } |
| 2426 | |
Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 2427 | if (ArgChanged) |
| 2428 | *ArgChanged = true; |
| 2429 | Outputs.push_back(Out.get()); |
| 2430 | } |
| 2431 | |
| 2432 | continue; |
| 2433 | } |
| 2434 | |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 2435 | ExprResult Result = getDerived().TransformExpr(Inputs[I]); |
| 2436 | if (Result.isInvalid()) |
| 2437 | return true; |
| 2438 | |
| 2439 | if (Result.get() != Inputs[I] && ArgChanged) |
| 2440 | *ArgChanged = true; |
| 2441 | |
| 2442 | Outputs.push_back(Result.get()); |
| 2443 | } |
| 2444 | |
| 2445 | return false; |
| 2446 | } |
| 2447 | |
| 2448 | template<typename Derived> |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2449 | NestedNameSpecifierLoc |
| 2450 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 2451 | NestedNameSpecifierLoc NNS, |
| 2452 | QualType ObjectType, |
| 2453 | NamedDecl *FirstQualifierInScope) { |
| 2454 | llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 2455 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 2456 | Qualifier = Qualifier.getPrefix()) |
| 2457 | Qualifiers.push_back(Qualifier); |
| 2458 | |
| 2459 | CXXScopeSpec SS; |
| 2460 | while (!Qualifiers.empty()) { |
| 2461 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 2462 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 2463 | |
| 2464 | switch (QNNS->getKind()) { |
| 2465 | case NestedNameSpecifier::Identifier: |
| 2466 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, |
| 2467 | *QNNS->getAsIdentifier(), |
| 2468 | Q.getLocalBeginLoc(), |
| 2469 | Q.getLocalEndLoc(), |
| 2470 | ObjectType, false, SS, |
| 2471 | FirstQualifierInScope, false)) |
| 2472 | return NestedNameSpecifierLoc(); |
| 2473 | |
| 2474 | break; |
| 2475 | |
| 2476 | case NestedNameSpecifier::Namespace: { |
| 2477 | NamespaceDecl *NS |
| 2478 | = cast_or_null<NamespaceDecl>( |
| 2479 | getDerived().TransformDecl( |
| 2480 | Q.getLocalBeginLoc(), |
| 2481 | QNNS->getAsNamespace())); |
| 2482 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 2483 | break; |
| 2484 | } |
| 2485 | |
| 2486 | case NestedNameSpecifier::NamespaceAlias: { |
| 2487 | NamespaceAliasDecl *Alias |
| 2488 | = cast_or_null<NamespaceAliasDecl>( |
| 2489 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 2490 | QNNS->getAsNamespaceAlias())); |
| 2491 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 2492 | Q.getLocalEndLoc()); |
| 2493 | break; |
| 2494 | } |
| 2495 | |
| 2496 | case NestedNameSpecifier::Global: |
| 2497 | // There is no meaningful transformation that one could perform on the |
| 2498 | // global scope. |
| 2499 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 2500 | break; |
| 2501 | |
| 2502 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2503 | case NestedNameSpecifier::TypeSpec: { |
| 2504 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 2505 | FirstQualifierInScope, SS); |
| 2506 | |
| 2507 | if (!TL) |
| 2508 | return NestedNameSpecifierLoc(); |
| 2509 | |
| 2510 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 2511 | (SemaRef.getLangOptions().CPlusPlus0x && |
| 2512 | TL.getType()->isEnumeralType())) { |
| 2513 | assert(!TL.getType().hasLocalQualifiers() && |
| 2514 | "Can't get cv-qualifiers here"); |
| 2515 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 2516 | Q.getLocalEndLoc()); |
| 2517 | break; |
| 2518 | } |
| 2519 | |
| 2520 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 2521 | << TL.getType() << SS.getRange(); |
| 2522 | return NestedNameSpecifierLoc(); |
| 2523 | } |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2524 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2525 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2526 | // 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] | 2527 | FirstQualifierInScope = 0; |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2528 | ObjectType = QualType(); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 2532 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 2533 | !getDerived().AlwaysRebuild()) |
| 2534 | return NNS; |
| 2535 | |
| 2536 | // If we can re-use the source-location data from the original |
| 2537 | // nested-name-specifier, do so. |
| 2538 | if (SS.location_size() == NNS.getDataLength() && |
| 2539 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 2540 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 2541 | |
| 2542 | // Allocate new nested-name-specifier location information. |
| 2543 | return SS.getWithLocInContext(SemaRef.Context); |
| 2544 | } |
| 2545 | |
| 2546 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2547 | DeclarationNameInfo |
| 2548 | TreeTransform<Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2549 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2550 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2551 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2552 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2553 | |
| 2554 | switch (Name.getNameKind()) { |
| 2555 | case DeclarationName::Identifier: |
| 2556 | case DeclarationName::ObjCZeroArgSelector: |
| 2557 | case DeclarationName::ObjCOneArgSelector: |
| 2558 | case DeclarationName::ObjCMultiArgSelector: |
| 2559 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2560 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2561 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2562 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2563 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2564 | case DeclarationName::CXXConstructorName: |
| 2565 | case DeclarationName::CXXDestructorName: |
| 2566 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2567 | TypeSourceInfo *NewTInfo; |
| 2568 | CanQualType NewCanTy; |
| 2569 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2570 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 2571 | if (!NewTInfo) |
| 2572 | return DeclarationNameInfo(); |
| 2573 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2574 | } |
| 2575 | else { |
| 2576 | NewTInfo = 0; |
| 2577 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 2578 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2579 | if (NewT.isNull()) |
| 2580 | return DeclarationNameInfo(); |
| 2581 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2583 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2584 | DeclarationName NewName |
| 2585 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2586 | NewCanTy); |
| 2587 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2588 | NewNameInfo.setName(NewName); |
| 2589 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2590 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2594 | assert(0 && "Unknown name kind."); |
| 2595 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2599 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 2600 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 2601 | TemplateName Name, |
| 2602 | SourceLocation NameLoc, |
| 2603 | QualType ObjectType, |
| 2604 | NamedDecl *FirstQualifierInScope) { |
| 2605 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 2606 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 2607 | assert(Template && "qualified template name must refer to a template"); |
| 2608 | |
| 2609 | TemplateDecl *TransTemplate |
| 2610 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2611 | Template)); |
| 2612 | if (!TransTemplate) |
| 2613 | return TemplateName(); |
| 2614 | |
| 2615 | if (!getDerived().AlwaysRebuild() && |
| 2616 | SS.getScopeRep() == QTN->getQualifier() && |
| 2617 | TransTemplate == Template) |
| 2618 | return Name; |
| 2619 | |
| 2620 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 2621 | TransTemplate); |
| 2622 | } |
| 2623 | |
| 2624 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 2625 | if (SS.getScopeRep()) { |
| 2626 | // These apply to the scope specifier, not the template. |
| 2627 | ObjectType = QualType(); |
| 2628 | FirstQualifierInScope = 0; |
| 2629 | } |
| 2630 | |
| 2631 | if (!getDerived().AlwaysRebuild() && |
| 2632 | SS.getScopeRep() == DTN->getQualifier() && |
| 2633 | ObjectType.isNull()) |
| 2634 | return Name; |
| 2635 | |
| 2636 | if (DTN->isIdentifier()) { |
| 2637 | return getDerived().RebuildTemplateName(SS, |
| 2638 | *DTN->getIdentifier(), |
| 2639 | NameLoc, |
| 2640 | ObjectType, |
| 2641 | FirstQualifierInScope); |
| 2642 | } |
| 2643 | |
| 2644 | return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, |
| 2645 | ObjectType); |
| 2646 | } |
| 2647 | |
| 2648 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 2649 | TemplateDecl *TransTemplate |
| 2650 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 2651 | Template)); |
| 2652 | if (!TransTemplate) |
| 2653 | return TemplateName(); |
| 2654 | |
| 2655 | if (!getDerived().AlwaysRebuild() && |
| 2656 | TransTemplate == Template) |
| 2657 | return Name; |
| 2658 | |
| 2659 | return TemplateName(TransTemplate); |
| 2660 | } |
| 2661 | |
| 2662 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 2663 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 2664 | TemplateTemplateParmDecl *TransParam |
| 2665 | = cast_or_null<TemplateTemplateParmDecl>( |
| 2666 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 2667 | if (!TransParam) |
| 2668 | return TemplateName(); |
| 2669 | |
| 2670 | if (!getDerived().AlwaysRebuild() && |
| 2671 | TransParam == SubstPack->getParameterPack()) |
| 2672 | return Name; |
| 2673 | |
| 2674 | return getDerived().RebuildTemplateName(TransParam, |
| 2675 | SubstPack->getArgumentPack()); |
| 2676 | } |
| 2677 | |
| 2678 | // These should be getting filtered out before they reach the AST. |
| 2679 | llvm_unreachable("overloaded function decl survived to here"); |
| 2680 | return TemplateName(); |
| 2681 | } |
| 2682 | |
| 2683 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2684 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2685 | const TemplateArgument &Arg, |
| 2686 | TemplateArgumentLoc &Output) { |
| 2687 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2688 | switch (Arg.getKind()) { |
| 2689 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2690 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2691 | break; |
| 2692 | |
| 2693 | case TemplateArgument::Type: |
| 2694 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2695 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2696 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2697 | break; |
| 2698 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2699 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2700 | case TemplateArgument::TemplateExpansion: { |
| 2701 | NestedNameSpecifierLocBuilder Builder; |
| 2702 | TemplateName Template = Arg.getAsTemplate(); |
| 2703 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 2704 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 2705 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 2706 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| 2707 | |
| 2708 | if (Arg.getKind() == TemplateArgument::Template) |
| 2709 | Output = TemplateArgumentLoc(Arg, |
| 2710 | Builder.getWithLocInContext(SemaRef.Context), |
| 2711 | Loc); |
| 2712 | else |
| 2713 | Output = TemplateArgumentLoc(Arg, |
| 2714 | Builder.getWithLocInContext(SemaRef.Context), |
| 2715 | Loc, Loc); |
| 2716 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2717 | break; |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2718 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2719 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2720 | case TemplateArgument::Expression: |
| 2721 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2722 | break; |
| 2723 | |
| 2724 | case TemplateArgument::Declaration: |
| 2725 | case TemplateArgument::Integral: |
| 2726 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2727 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2728 | break; |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | template<typename Derived> |
| 2733 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2734 | const TemplateArgumentLoc &Input, |
| 2735 | TemplateArgumentLoc &Output) { |
| 2736 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2737 | switch (Arg.getKind()) { |
| 2738 | case TemplateArgument::Null: |
| 2739 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2740 | Output = Input; |
| 2741 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2743 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2744 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2745 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2746 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2747 | |
| 2748 | DI = getDerived().TransformType(DI); |
| 2749 | if (!DI) return true; |
| 2750 | |
| 2751 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2752 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2755 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2756 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2757 | DeclarationName Name; |
| 2758 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2759 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2760 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2761 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2762 | if (!D) return true; |
| 2763 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2764 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2765 | if (SourceExpr) { |
| 2766 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2767 | Sema::Unevaluated); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2768 | ExprResult E = getDerived().TransformExpr(SourceExpr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2769 | SourceExpr = (E.isInvalid() ? 0 : E.take()); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2773 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2774 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2775 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2776 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2777 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 2778 | if (QualifierLoc) { |
| 2779 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 2780 | if (!QualifierLoc) |
| 2781 | return true; |
| 2782 | } |
| 2783 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2784 | CXXScopeSpec SS; |
| 2785 | SS.Adopt(QualifierLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2786 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 2787 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 2788 | Input.getTemplateNameLoc()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2789 | if (Template.isNull()) |
| 2790 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2791 | |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 2792 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2793 | Input.getTemplateNameLoc()); |
| 2794 | return false; |
| 2795 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2796 | |
| 2797 | case TemplateArgument::TemplateExpansion: |
| 2798 | llvm_unreachable("Caller should expand pack expansions"); |
| 2799 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2800 | case TemplateArgument::Expression: { |
| 2801 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2803 | Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2805 | Expr *InputExpr = Input.getSourceExpression(); |
| 2806 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2807 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2808 | ExprResult E |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2809 | = getDerived().TransformExpr(InputExpr); |
| 2810 | if (E.isInvalid()) return true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2811 | Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2812 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2813 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2814 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2815 | case TemplateArgument::Pack: { |
| 2816 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2817 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2818 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2819 | AEnd = Arg.pack_end(); |
| 2820 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2821 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2822 | // FIXME: preserve source information here when we start |
| 2823 | // caring about parameter packs. |
| 2824 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2825 | TemplateArgumentLoc InputArg; |
| 2826 | TemplateArgumentLoc OutputArg; |
| 2827 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2828 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2829 | return true; |
| 2830 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2831 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2832 | } |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 2833 | |
| 2834 | TemplateArgument *TransformedArgsPtr |
| 2835 | = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; |
| 2836 | std::copy(TransformedArgs.begin(), TransformedArgs.end(), |
| 2837 | TransformedArgsPtr); |
| 2838 | Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, |
| 2839 | TransformedArgs.size()), |
| 2840 | Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2841 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2842 | } |
| 2843 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2844 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2845 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2846 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2847 | } |
| 2848 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2849 | /// \brief Iterator adaptor that invents template argument location information |
| 2850 | /// for each of the template arguments in its underlying iterator. |
| 2851 | template<typename Derived, typename InputIterator> |
| 2852 | class TemplateArgumentLocInventIterator { |
| 2853 | TreeTransform<Derived> &Self; |
| 2854 | InputIterator Iter; |
| 2855 | |
| 2856 | public: |
| 2857 | typedef TemplateArgumentLoc value_type; |
| 2858 | typedef TemplateArgumentLoc reference; |
| 2859 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 2860 | difference_type; |
| 2861 | typedef std::input_iterator_tag iterator_category; |
| 2862 | |
| 2863 | class pointer { |
| 2864 | TemplateArgumentLoc Arg; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2865 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2866 | public: |
| 2867 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 2868 | |
| 2869 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 2870 | }; |
| 2871 | |
| 2872 | TemplateArgumentLocInventIterator() { } |
| 2873 | |
| 2874 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 2875 | InputIterator Iter) |
| 2876 | : Self(Self), Iter(Iter) { } |
| 2877 | |
| 2878 | TemplateArgumentLocInventIterator &operator++() { |
| 2879 | ++Iter; |
| 2880 | return *this; |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2881 | } |
| 2882 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2883 | TemplateArgumentLocInventIterator operator++(int) { |
| 2884 | TemplateArgumentLocInventIterator Old(*this); |
| 2885 | ++(*this); |
| 2886 | return Old; |
| 2887 | } |
| 2888 | |
| 2889 | reference operator*() const { |
| 2890 | TemplateArgumentLoc Result; |
| 2891 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 2892 | return Result; |
| 2893 | } |
| 2894 | |
| 2895 | pointer operator->() const { return pointer(**this); } |
| 2896 | |
| 2897 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 2898 | const TemplateArgumentLocInventIterator &Y) { |
| 2899 | return X.Iter == Y.Iter; |
| 2900 | } |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 2901 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2902 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 2903 | const TemplateArgumentLocInventIterator &Y) { |
| 2904 | return X.Iter != Y.Iter; |
| 2905 | } |
| 2906 | }; |
| 2907 | |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2908 | template<typename Derived> |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2909 | template<typename InputIterator> |
| 2910 | bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, |
| 2911 | InputIterator Last, |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2912 | TemplateArgumentListInfo &Outputs) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2913 | for (; First != Last; ++First) { |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 2914 | TemplateArgumentLoc Out; |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2915 | TemplateArgumentLoc In = *First; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2916 | |
| 2917 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 2918 | // Unpack argument packs, which we translate them into separate |
| 2919 | // arguments. |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 2920 | // FIXME: We could do much better if we could guarantee that the |
| 2921 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 2922 | // all of the template arguments in the argument pack. |
| 2923 | typedef TemplateArgumentLocInventIterator<Derived, |
| 2924 | TemplateArgument::pack_iterator> |
| 2925 | PackLocIterator; |
| 2926 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 2927 | In.getArgument().pack_begin()), |
| 2928 | PackLocIterator(*this, |
| 2929 | In.getArgument().pack_end()), |
| 2930 | Outputs)) |
| 2931 | return true; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2932 | |
| 2933 | continue; |
| 2934 | } |
| 2935 | |
| 2936 | if (In.getArgument().isPackExpansion()) { |
| 2937 | // We have a pack expansion, for which we will be substituting into |
| 2938 | // the pattern. |
| 2939 | SourceLocation Ellipsis; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2940 | llvm::Optional<unsigned> OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2941 | TemplateArgumentLoc Pattern |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2942 | = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, |
| 2943 | getSema().Context); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2944 | |
| 2945 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 2946 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 2947 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 2948 | |
| 2949 | // Determine whether the set of unexpanded parameter packs can and should |
| 2950 | // be expanded. |
| 2951 | bool Expand = true; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2952 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2953 | llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2954 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 2955 | Pattern.getSourceRange(), |
| 2956 | Unexpanded.data(), |
| 2957 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 2958 | Expand, |
| 2959 | RetainExpansion, |
| 2960 | NumExpansions)) |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2961 | return true; |
| 2962 | |
| 2963 | if (!Expand) { |
| 2964 | // The transform has determined that we should perform a simple |
| 2965 | // transformation on the pack expansion, producing another pack |
| 2966 | // expansion. |
| 2967 | TemplateArgumentLoc OutPattern; |
| 2968 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 2969 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) |
| 2970 | return true; |
| 2971 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2972 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 2973 | NumExpansions); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2974 | if (Out.getArgument().isNull()) |
| 2975 | return true; |
| 2976 | |
| 2977 | Outputs.addArgument(Out); |
| 2978 | continue; |
| 2979 | } |
| 2980 | |
| 2981 | // The transform has determined that we should perform an elementwise |
| 2982 | // expansion of the pattern. Do so. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2983 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2984 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 2985 | |
| 2986 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 2987 | return true; |
| 2988 | |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2989 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 2990 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 2991 | OrigNumExpansions); |
Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 2992 | if (Out.getArgument().isNull()) |
| 2993 | return true; |
| 2994 | } |
| 2995 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 2996 | Outputs.addArgument(Out); |
| 2997 | } |
| 2998 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 2999 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3000 | // forgetting the partially-substituted parameter pack. |
| 3001 | if (RetainExpansion) { |
| 3002 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3003 | |
| 3004 | if (getDerived().TransformTemplateArgument(Pattern, Out)) |
| 3005 | return true; |
| 3006 | |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3007 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 3008 | OrigNumExpansions); |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3009 | if (Out.getArgument().isNull()) |
| 3010 | return true; |
| 3011 | |
| 3012 | Outputs.addArgument(Out); |
| 3013 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3014 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3015 | continue; |
| 3016 | } |
| 3017 | |
| 3018 | // The simple case: |
| 3019 | if (getDerived().TransformTemplateArgument(In, Out)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 3020 | return true; |
| 3021 | |
| 3022 | Outputs.addArgument(Out); |
| 3023 | } |
| 3024 | |
| 3025 | return false; |
| 3026 | |
| 3027 | } |
| 3028 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3029 | //===----------------------------------------------------------------------===// |
| 3030 | // Type transformation |
| 3031 | //===----------------------------------------------------------------------===// |
| 3032 | |
| 3033 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3034 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3035 | if (getDerived().AlreadyTransformed(T)) |
| 3036 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | // Temporary workaround. All of these transformations should |
| 3039 | // eventually turn into transformations on TypeLocs. |
Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 3040 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 3041 | getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3042 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3043 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3044 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3045 | if (!NewDI) |
| 3046 | return QualType(); |
| 3047 | |
| 3048 | return NewDI->getType(); |
| 3049 | } |
| 3050 | |
| 3051 | template<typename Derived> |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3052 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3053 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 3054 | return DI; |
| 3055 | |
| 3056 | TypeLocBuilder TLB; |
| 3057 | |
| 3058 | TypeLoc TL = DI->getTypeLoc(); |
| 3059 | TLB.reserve(TL.getFullDataSize()); |
| 3060 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3061 | QualType Result = getDerived().TransformType(TLB, TL); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | if (Result.isNull()) |
| 3063 | return 0; |
| 3064 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3065 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | template<typename Derived> |
| 3069 | QualType |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3070 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3071 | switch (T.getTypeLocClass()) { |
| 3072 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 3073 | #define TYPELOC(CLASS, PARENT) \ |
| 3074 | case TypeLoc::CLASS: \ |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3075 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3076 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3079 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3080 | return QualType(); |
| 3081 | } |
| 3082 | |
| 3083 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 3084 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 3085 | /// that are not permitted (e.g., qualifiers on reference or function |
| 3086 | /// types). This is the right thing for template instantiation, but |
| 3087 | /// probably not for other clients. |
| 3088 | template<typename Derived> |
| 3089 | QualType |
| 3090 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3091 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 3092 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3093 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3094 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3095 | if (Result.isNull()) |
| 3096 | return QualType(); |
| 3097 | |
| 3098 | // Silently suppress qualifiers if the result type can't be qualified. |
| 3099 | // FIXME: this is the right thing for template instantiation, but |
| 3100 | // probably not for other clients. |
| 3101 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3102 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 3104 | if (!Quals.empty()) { |
| 3105 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 3106 | TLB.push<QualifiedTypeLoc>(Result); |
| 3107 | // No location information to preserve. |
| 3108 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3109 | |
| 3110 | return Result; |
| 3111 | } |
| 3112 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3113 | template<typename Derived> |
| 3114 | TypeLoc |
| 3115 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 3116 | QualType ObjectType, |
| 3117 | NamedDecl *UnqualLookup, |
| 3118 | CXXScopeSpec &SS) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3119 | QualType T = TL.getType(); |
| 3120 | if (getDerived().AlreadyTransformed(T)) |
| 3121 | return TL; |
| 3122 | |
| 3123 | TypeLocBuilder TLB; |
| 3124 | QualType Result; |
| 3125 | |
| 3126 | if (isa<TemplateSpecializationType>(T)) { |
| 3127 | TemplateSpecializationTypeLoc SpecTL |
| 3128 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3129 | |
| 3130 | TemplateName Template = |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3131 | getDerived().TransformTemplateName(SS, |
| 3132 | SpecTL.getTypePtr()->getTemplateName(), |
| 3133 | SpecTL.getTemplateNameLoc(), |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3134 | ObjectType, UnqualLookup); |
| 3135 | if (Template.isNull()) |
| 3136 | return TypeLoc(); |
| 3137 | |
| 3138 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3139 | Template); |
| 3140 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3141 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3142 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3143 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3144 | TemplateName Template |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3145 | = getDerived().RebuildTemplateName(SS, |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3146 | *SpecTL.getTypePtr()->getIdentifier(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3147 | SpecTL.getNameLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3148 | ObjectType, UnqualLookup); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3149 | if (Template.isNull()) |
| 3150 | return TypeLoc(); |
| 3151 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3152 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 3153 | SpecTL, |
| 3154 | Template); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3155 | } else { |
| 3156 | // Nothing special needs to be done for these. |
| 3157 | Result = getDerived().TransformType(TLB, TL); |
| 3158 | } |
| 3159 | |
| 3160 | if (Result.isNull()) |
| 3161 | return TypeLoc(); |
| 3162 | |
| 3163 | return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); |
| 3164 | } |
| 3165 | |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3166 | template<typename Derived> |
| 3167 | TypeSourceInfo * |
| 3168 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3169 | QualType ObjectType, |
| 3170 | NamedDecl *UnqualLookup, |
| 3171 | CXXScopeSpec &SS) { |
| 3172 | // FIXME: Painfully copy-paste from the above! |
| 3173 | |
| 3174 | QualType T = TSInfo->getType(); |
| 3175 | if (getDerived().AlreadyTransformed(T)) |
| 3176 | return TSInfo; |
| 3177 | |
| 3178 | TypeLocBuilder TLB; |
| 3179 | QualType Result; |
| 3180 | |
| 3181 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 3182 | if (isa<TemplateSpecializationType>(T)) { |
| 3183 | TemplateSpecializationTypeLoc SpecTL |
| 3184 | = cast<TemplateSpecializationTypeLoc>(TL); |
| 3185 | |
| 3186 | TemplateName Template |
| 3187 | = getDerived().TransformTemplateName(SS, |
| 3188 | SpecTL.getTypePtr()->getTemplateName(), |
| 3189 | SpecTL.getTemplateNameLoc(), |
| 3190 | ObjectType, UnqualLookup); |
| 3191 | if (Template.isNull()) |
| 3192 | return 0; |
| 3193 | |
| 3194 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 3195 | Template); |
| 3196 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 3197 | DependentTemplateSpecializationTypeLoc SpecTL |
| 3198 | = cast<DependentTemplateSpecializationTypeLoc>(TL); |
| 3199 | |
| 3200 | TemplateName Template |
| 3201 | = getDerived().RebuildTemplateName(SS, |
| 3202 | *SpecTL.getTypePtr()->getIdentifier(), |
| 3203 | SpecTL.getNameLoc(), |
| 3204 | ObjectType, UnqualLookup); |
| 3205 | if (Template.isNull()) |
| 3206 | return 0; |
| 3207 | |
| 3208 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| 3209 | SpecTL, |
| 3210 | Template); |
| 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 0; |
| 3218 | |
| 3219 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3220 | } |
| 3221 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3222 | template <class TyLoc> static inline |
| 3223 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 3224 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 3225 | NewT.setNameLoc(T.getNameLoc()); |
| 3226 | return T.getType(); |
| 3227 | } |
| 3228 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3229 | template<typename Derived> |
| 3230 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3231 | BuiltinTypeLoc T) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3232 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 3233 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 3234 | if (T.needsExtraLocalData()) |
| 3235 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 3236 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3237 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3239 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3240 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3241 | ComplexTypeLoc T) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3242 | // FIXME: recurse? |
| 3243 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3244 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3246 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3247 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3248 | PointerTypeLoc TL) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3249 | QualType PointeeType |
| 3250 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3251 | if (PointeeType.isNull()) |
| 3252 | return QualType(); |
| 3253 | |
| 3254 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3255 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3256 | // A dependent pointer type 'T *' has is being transformed such |
| 3257 | // that an Objective-C class type is being replaced for 'T'. The |
| 3258 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 3259 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3260 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3261 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3262 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 3263 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3264 | return Result; |
| 3265 | } |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3266 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3267 | if (getDerived().AlwaysRebuild() || |
| 3268 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3269 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 3270 | if (Result.isNull()) |
| 3271 | return QualType(); |
| 3272 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3274 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 3275 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3276 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3277 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | |
| 3279 | template<typename Derived> |
| 3280 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3281 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3282 | BlockPointerTypeLoc TL) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3283 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3284 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3285 | if (PointeeType.isNull()) |
| 3286 | return QualType(); |
| 3287 | |
| 3288 | QualType Result = TL.getType(); |
| 3289 | if (getDerived().AlwaysRebuild() || |
| 3290 | PointeeType != TL.getPointeeLoc().getType()) { |
| 3291 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3292 | TL.getSigilLoc()); |
| 3293 | if (Result.isNull()) |
| 3294 | return QualType(); |
| 3295 | } |
| 3296 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 3297 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 3298 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 3299 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3302 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 3303 | /// don't care whether the type itself is an l-value type or an r-value |
| 3304 | /// type; we only care if the type was *written* as an l-value type |
| 3305 | /// or an r-value type. |
| 3306 | template<typename Derived> |
| 3307 | QualType |
| 3308 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3309 | ReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3310 | const ReferenceType *T = TL.getTypePtr(); |
| 3311 | |
| 3312 | // Note that this works with the pointee-as-written. |
| 3313 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 3314 | if (PointeeType.isNull()) |
| 3315 | return QualType(); |
| 3316 | |
| 3317 | QualType Result = TL.getType(); |
| 3318 | if (getDerived().AlwaysRebuild() || |
| 3319 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 3320 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 3321 | T->isSpelledAsLValue(), |
| 3322 | TL.getSigilLoc()); |
| 3323 | if (Result.isNull()) |
| 3324 | return QualType(); |
| 3325 | } |
| 3326 | |
| 3327 | // r-value references can be rebuilt as l-value references. |
| 3328 | ReferenceTypeLoc NewTL; |
| 3329 | if (isa<LValueReferenceType>(Result)) |
| 3330 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 3331 | else |
| 3332 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 3333 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3334 | |
| 3335 | return Result; |
| 3336 | } |
| 3337 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | template<typename Derived> |
| 3339 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3340 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3341 | LValueReferenceTypeLoc TL) { |
| 3342 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3343 | } |
| 3344 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | template<typename Derived> |
| 3346 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3347 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3348 | RValueReferenceTypeLoc TL) { |
| 3349 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3351 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3352 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3354 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3355 | MemberPointerTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3356 | const MemberPointerType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3357 | |
| 3358 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3359 | if (PointeeType.isNull()) |
| 3360 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3361 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3362 | // TODO: preserve source information for this. |
| 3363 | QualType ClassType |
| 3364 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3365 | if (ClassType.isNull()) |
| 3366 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3368 | QualType Result = TL.getType(); |
| 3369 | if (getDerived().AlwaysRebuild() || |
| 3370 | PointeeType != T->getPointeeType() || |
| 3371 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3372 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 3373 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3374 | if (Result.isNull()) |
| 3375 | return QualType(); |
| 3376 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3377 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3378 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 3379 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 3380 | |
| 3381 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3384 | template<typename Derived> |
| 3385 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3386 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3387 | ConstantArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3388 | const ConstantArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3389 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3390 | if (ElementType.isNull()) |
| 3391 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3393 | QualType Result = TL.getType(); |
| 3394 | if (getDerived().AlwaysRebuild() || |
| 3395 | ElementType != T->getElementType()) { |
| 3396 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 3397 | T->getSizeModifier(), |
| 3398 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3399 | T->getIndexTypeCVRQualifiers(), |
| 3400 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3401 | if (Result.isNull()) |
| 3402 | return QualType(); |
| 3403 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3404 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3405 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 3406 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3407 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3408 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3409 | Expr *Size = TL.getSizeExpr(); |
| 3410 | if (Size) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3411 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3412 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 3413 | } |
| 3414 | NewTL.setSizeExpr(Size); |
| 3415 | |
| 3416 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3417 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3418 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3419 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3420 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3421 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3422 | IncompleteArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3423 | const IncompleteArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3424 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3425 | if (ElementType.isNull()) |
| 3426 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3428 | QualType Result = TL.getType(); |
| 3429 | if (getDerived().AlwaysRebuild() || |
| 3430 | ElementType != T->getElementType()) { |
| 3431 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3432 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3433 | T->getIndexTypeCVRQualifiers(), |
| 3434 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3435 | if (Result.isNull()) |
| 3436 | return QualType(); |
| 3437 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3438 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3439 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 3440 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3441 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3442 | NewTL.setSizeExpr(0); |
| 3443 | |
| 3444 | return Result; |
| 3445 | } |
| 3446 | |
| 3447 | template<typename Derived> |
| 3448 | QualType |
| 3449 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3450 | VariableArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3451 | const VariableArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3452 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3453 | if (ElementType.isNull()) |
| 3454 | return QualType(); |
| 3455 | |
| 3456 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3457 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3458 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3459 | ExprResult SizeResult |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3460 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 3461 | if (SizeResult.isInvalid()) |
| 3462 | return QualType(); |
| 3463 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3464 | Expr *Size = SizeResult.take(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3465 | |
| 3466 | QualType Result = TL.getType(); |
| 3467 | if (getDerived().AlwaysRebuild() || |
| 3468 | ElementType != T->getElementType() || |
| 3469 | Size != T->getSizeExpr()) { |
| 3470 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 3471 | T->getSizeModifier(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3472 | Size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3473 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3474 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3475 | if (Result.isNull()) |
| 3476 | return QualType(); |
| 3477 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3478 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3479 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 3480 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3481 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 3482 | NewTL.setSizeExpr(Size); |
| 3483 | |
| 3484 | return Result; |
| 3485 | } |
| 3486 | |
| 3487 | template<typename Derived> |
| 3488 | QualType |
| 3489 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3490 | DependentSizedArrayTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3491 | const DependentSizedArrayType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3492 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 3493 | if (ElementType.isNull()) |
| 3494 | return QualType(); |
| 3495 | |
| 3496 | // Array bounds are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3497 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3498 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3499 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 3500 | Expr *origSize = TL.getSizeExpr(); |
| 3501 | if (!origSize) origSize = T->getSizeExpr(); |
| 3502 | |
| 3503 | ExprResult sizeResult |
| 3504 | = getDerived().TransformExpr(origSize); |
| 3505 | if (sizeResult.isInvalid()) |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3506 | return QualType(); |
| 3507 | |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3508 | Expr *size = sizeResult.get(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3509 | |
| 3510 | QualType Result = TL.getType(); |
| 3511 | if (getDerived().AlwaysRebuild() || |
| 3512 | ElementType != T->getElementType() || |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3513 | size != origSize) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3514 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 3515 | T->getSizeModifier(), |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3516 | size, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3517 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 3518 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3519 | if (Result.isNull()) |
| 3520 | return QualType(); |
| 3521 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3522 | |
| 3523 | // We might have any sort of array type now, but fortunately they |
| 3524 | // all have the same location layout. |
| 3525 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 3526 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 3527 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 3528 | NewTL.setSizeExpr(size); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3529 | |
| 3530 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | |
| 3533 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3534 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3535 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3536 | DependentSizedExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3537 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3538 | |
| 3539 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3540 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3541 | if (ElementType.isNull()) |
| 3542 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3544 | // Vector sizes are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3545 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3546 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3547 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3548 | if (Size.isInvalid()) |
| 3549 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3550 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3551 | QualType Result = TL.getType(); |
| 3552 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 3553 | ElementType != T->getElementType() || |
| 3554 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3555 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3556 | Size.take(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3557 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3558 | if (Result.isNull()) |
| 3559 | return QualType(); |
| 3560 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3561 | |
| 3562 | // Result might be dependent or not. |
| 3563 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 3564 | DependentSizedExtVectorTypeLoc NewTL |
| 3565 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 3566 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3567 | } else { |
| 3568 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3569 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3570 | } |
| 3571 | |
| 3572 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | |
| 3575 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3576 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3577 | VectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3578 | const VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3579 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3580 | if (ElementType.isNull()) |
| 3581 | return QualType(); |
| 3582 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3583 | QualType Result = TL.getType(); |
| 3584 | if (getDerived().AlwaysRebuild() || |
| 3585 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3586 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3587 | T->getVectorKind()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3588 | if (Result.isNull()) |
| 3589 | return QualType(); |
| 3590 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3591 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3592 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 3593 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3594 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3595 | return Result; |
| 3596 | } |
| 3597 | |
| 3598 | template<typename Derived> |
| 3599 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3600 | ExtVectorTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3601 | const VectorType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3602 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 3603 | if (ElementType.isNull()) |
| 3604 | return QualType(); |
| 3605 | |
| 3606 | QualType Result = TL.getType(); |
| 3607 | if (getDerived().AlwaysRebuild() || |
| 3608 | ElementType != T->getElementType()) { |
| 3609 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 3610 | T->getNumElements(), |
| 3611 | /*FIXME*/ SourceLocation()); |
| 3612 | if (Result.isNull()) |
| 3613 | return QualType(); |
| 3614 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3615 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3616 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 3617 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3618 | |
| 3619 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3620 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | |
| 3622 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3623 | ParmVarDecl * |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3624 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 3625 | llvm::Optional<unsigned> NumExpansions) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3626 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3627 | TypeSourceInfo *NewDI = 0; |
| 3628 | |
| 3629 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 3630 | // If we're substituting into a pack expansion type and we know the |
| 3631 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 3632 | PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); |
| 3633 | |
| 3634 | TypeLocBuilder TLB; |
| 3635 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 3636 | TLB.reserve(NewTL.getFullDataSize()); |
| 3637 | |
| 3638 | QualType Result = getDerived().TransformType(TLB, |
| 3639 | OldExpansionTL.getPatternLoc()); |
| 3640 | if (Result.isNull()) |
| 3641 | return 0; |
| 3642 | |
| 3643 | Result = RebuildPackExpansionType(Result, |
| 3644 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 3645 | OldExpansionTL.getEllipsisLoc(), |
| 3646 | NumExpansions); |
| 3647 | if (Result.isNull()) |
| 3648 | return 0; |
| 3649 | |
| 3650 | PackExpansionTypeLoc NewExpansionTL |
| 3651 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 3652 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 3653 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 3654 | } else |
| 3655 | NewDI = getDerived().TransformType(OldDI); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3656 | if (!NewDI) |
| 3657 | return 0; |
| 3658 | |
| 3659 | if (NewDI == OldDI) |
| 3660 | return OldParm; |
| 3661 | else |
| 3662 | return ParmVarDecl::Create(SemaRef.Context, |
| 3663 | OldParm->getDeclContext(), |
| 3664 | OldParm->getLocation(), |
| 3665 | OldParm->getIdentifier(), |
| 3666 | NewDI->getType(), |
| 3667 | NewDI, |
| 3668 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 3669 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3670 | /* DefArg */ NULL); |
| 3671 | } |
| 3672 | |
| 3673 | template<typename Derived> |
| 3674 | bool TreeTransform<Derived>:: |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3675 | TransformFunctionTypeParams(SourceLocation Loc, |
| 3676 | ParmVarDecl **Params, unsigned NumParams, |
| 3677 | const QualType *ParamTypes, |
| 3678 | llvm::SmallVectorImpl<QualType> &OutParamTypes, |
| 3679 | llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { |
| 3680 | for (unsigned i = 0; i != NumParams; ++i) { |
| 3681 | if (ParmVarDecl *OldParm = Params[i]) { |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3682 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3683 | ParmVarDecl *NewParm = 0; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3684 | if (OldParm->isParameterPack()) { |
| 3685 | // We have a function parameter pack that may need to be expanded. |
| 3686 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3687 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3688 | // Find the parameter packs that could be expanded. |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3689 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 3690 | PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); |
| 3691 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 3692 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3693 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 3694 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3695 | // Determine whether we should expand the parameter packs. |
| 3696 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3697 | bool RetainExpansion = false; |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3698 | llvm::Optional<unsigned> OrigNumExpansions |
| 3699 | = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 3700 | NumExpansions = OrigNumExpansions; |
Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 3701 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 3702 | Pattern.getSourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3703 | Unexpanded.data(), |
| 3704 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3705 | ShouldExpand, |
| 3706 | RetainExpansion, |
| 3707 | NumExpansions)) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3708 | return true; |
| 3709 | } |
| 3710 | |
| 3711 | if (ShouldExpand) { |
| 3712 | // Expand the function parameter pack into multiple, separate |
| 3713 | // parameters. |
Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 3714 | getDerived().ExpandingFunctionParameterPack(OldParm); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3715 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3716 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3717 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3718 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3719 | OrigNumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3720 | if (!NewParm) |
| 3721 | return true; |
| 3722 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3723 | OutParamTypes.push_back(NewParm->getType()); |
| 3724 | if (PVars) |
| 3725 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3726 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3727 | |
| 3728 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3729 | // forgetting the partially-substituted parameter pack. |
| 3730 | if (RetainExpansion) { |
| 3731 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3732 | ParmVarDecl *NewParm |
Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 3733 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 3734 | OrigNumExpansions); |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3735 | if (!NewParm) |
| 3736 | return true; |
| 3737 | |
| 3738 | OutParamTypes.push_back(NewParm->getType()); |
| 3739 | if (PVars) |
| 3740 | PVars->push_back(NewParm); |
| 3741 | } |
| 3742 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3743 | // We're done with the pack expansion. |
| 3744 | continue; |
| 3745 | } |
| 3746 | |
| 3747 | // We'll substitute the parameter now without expanding the pack |
| 3748 | // expansion. |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3749 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3750 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3751 | NumExpansions); |
| 3752 | } else { |
| 3753 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 3754 | llvm::Optional<unsigned>()); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3755 | } |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3756 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3757 | if (!NewParm) |
| 3758 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3759 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3760 | OutParamTypes.push_back(NewParm->getType()); |
| 3761 | if (PVars) |
| 3762 | PVars->push_back(NewParm); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3763 | continue; |
| 3764 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3765 | |
| 3766 | // Deal with the possibility that we don't have a parameter |
| 3767 | // declaration for this parameter. |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3768 | QualType OldType = ParamTypes[i]; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3769 | bool IsPackExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3770 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3771 | QualType NewType; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3772 | if (const PackExpansionType *Expansion |
| 3773 | = dyn_cast<PackExpansionType>(OldType)) { |
| 3774 | // We have a function parameter pack that may need to be expanded. |
| 3775 | QualType Pattern = Expansion->getPattern(); |
| 3776 | llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3777 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3778 | |
| 3779 | // Determine whether we should expand the parameter packs. |
| 3780 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3781 | bool RetainExpansion = false; |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3782 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3783 | Unexpanded.data(), |
| 3784 | Unexpanded.size(), |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3785 | ShouldExpand, |
| 3786 | RetainExpansion, |
| 3787 | NumExpansions)) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3788 | return true; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | if (ShouldExpand) { |
| 3792 | // Expand the function parameter pack into multiple, separate |
| 3793 | // parameters. |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3794 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3795 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3796 | QualType NewType = getDerived().TransformType(Pattern); |
| 3797 | if (NewType.isNull()) |
| 3798 | return true; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3799 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3800 | OutParamTypes.push_back(NewType); |
| 3801 | if (PVars) |
| 3802 | PVars->push_back(0); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | // We're done with the pack expansion. |
| 3806 | continue; |
| 3807 | } |
| 3808 | |
Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 3809 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3810 | // forgetting the partially-substituted parameter pack. |
| 3811 | if (RetainExpansion) { |
| 3812 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3813 | QualType NewType = getDerived().TransformType(Pattern); |
| 3814 | if (NewType.isNull()) |
| 3815 | return true; |
| 3816 | |
| 3817 | OutParamTypes.push_back(NewType); |
| 3818 | if (PVars) |
| 3819 | PVars->push_back(0); |
| 3820 | } |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3821 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3822 | // We'll substitute the parameter now without expanding the pack |
| 3823 | // expansion. |
| 3824 | OldType = Expansion->getPattern(); |
| 3825 | IsPackExpansion = true; |
Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 3826 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3827 | NewType = getDerived().TransformType(OldType); |
| 3828 | } else { |
| 3829 | NewType = getDerived().TransformType(OldType); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3830 | } |
| 3831 | |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3832 | if (NewType.isNull()) |
| 3833 | return true; |
| 3834 | |
| 3835 | if (IsPackExpansion) |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3836 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 3837 | NumExpansions); |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3838 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3839 | OutParamTypes.push_back(NewType); |
| 3840 | if (PVars) |
| 3841 | PVars->push_back(0); |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | return false; |
Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 3845 | } |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 3846 | |
| 3847 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3849 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3850 | FunctionProtoTypeLoc TL) { |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3851 | // Transform the parameters and return type. |
| 3852 | // |
| 3853 | // We instantiate in source order, with the return type first followed by |
| 3854 | // the parameters, because users tend to expect this (even if they shouldn't |
| 3855 | // rely on it!). |
| 3856 | // |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3857 | // When the function has a trailing return type, we instantiate the |
| 3858 | // parameters before the return type, since the return type can then refer |
| 3859 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 3860 | // |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3861 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3862 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3863 | const FunctionProtoType *T = TL.getTypePtr(); |
Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 3864 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3865 | QualType ResultType; |
| 3866 | |
| 3867 | if (TL.getTrailingReturn()) { |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3868 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3869 | TL.getParmArray(), |
| 3870 | TL.getNumArgs(), |
| 3871 | TL.getTypePtr()->arg_type_begin(), |
| 3872 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3873 | return QualType(); |
| 3874 | |
| 3875 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3876 | if (ResultType.isNull()) |
| 3877 | return QualType(); |
| 3878 | } |
| 3879 | else { |
| 3880 | ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3881 | if (ResultType.isNull()) |
| 3882 | return QualType(); |
| 3883 | |
Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 3884 | if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), |
| 3885 | TL.getParmArray(), |
| 3886 | TL.getNumArgs(), |
| 3887 | TL.getTypePtr()->arg_type_begin(), |
| 3888 | ParamTypes, &ParamDecls)) |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3889 | return QualType(); |
| 3890 | } |
| 3891 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3892 | QualType Result = TL.getType(); |
| 3893 | if (getDerived().AlwaysRebuild() || |
| 3894 | ResultType != T->getResultType() || |
Douglas Gregor | 9f627df | 2011-01-07 19:27:47 +0000 | [diff] [blame] | 3895 | T->getNumArgs() != ParamTypes.size() || |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3896 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 3897 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 3898 | ParamTypes.data(), |
| 3899 | ParamTypes.size(), |
| 3900 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3901 | T->getTypeQuals(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3902 | T->getRefQualifier(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 3903 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3904 | if (Result.isNull()) |
| 3905 | return QualType(); |
| 3906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3908 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 3909 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3910 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3911 | NewTL.setTrailingReturn(TL.getTrailingReturn()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3912 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 3913 | NewTL.setArg(i, ParamDecls[i]); |
| 3914 | |
| 3915 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3918 | template<typename Derived> |
| 3919 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3920 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3921 | FunctionNoProtoTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3922 | const FunctionNoProtoType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3923 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 3924 | if (ResultType.isNull()) |
| 3925 | return QualType(); |
| 3926 | |
| 3927 | QualType Result = TL.getType(); |
| 3928 | if (getDerived().AlwaysRebuild() || |
| 3929 | ResultType != T->getResultType()) |
| 3930 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 3931 | |
| 3932 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 3933 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3934 | NewTL.setRParenLoc(TL.getRParenLoc()); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3935 | NewTL.setTrailingReturn(false); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3936 | |
| 3937 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3940 | template<typename Derived> QualType |
| 3941 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3942 | UnresolvedUsingTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3943 | const UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3944 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3945 | if (!D) |
| 3946 | return QualType(); |
| 3947 | |
| 3948 | QualType Result = TL.getType(); |
| 3949 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 3950 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 3951 | if (Result.isNull()) |
| 3952 | return QualType(); |
| 3953 | } |
| 3954 | |
| 3955 | // We might get an arbitrary type spec type back. We should at |
| 3956 | // least always get a type spec type, though. |
| 3957 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 3958 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3959 | |
| 3960 | return Result; |
| 3961 | } |
| 3962 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3963 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3964 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3965 | TypedefTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3966 | const TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3967 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3968 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3969 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3970 | if (!Typedef) |
| 3971 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3973 | QualType Result = TL.getType(); |
| 3974 | if (getDerived().AlwaysRebuild() || |
| 3975 | Typedef != T->getDecl()) { |
| 3976 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3977 | if (Result.isNull()) |
| 3978 | return QualType(); |
| 3979 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3981 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3982 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3983 | |
| 3984 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3987 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3988 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3989 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3990 | // typeof expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3991 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3993 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3994 | if (E.isInvalid()) |
| 3995 | return QualType(); |
| 3996 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3997 | QualType Result = TL.getType(); |
| 3998 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3999 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4000 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4001 | if (Result.isNull()) |
| 4002 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4003 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4004 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4006 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4007 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4008 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4009 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 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 | |
| 4014 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4015 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4016 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4017 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 4018 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 4019 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4020 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4021 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4022 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4023 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 4024 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4025 | if (Result.isNull()) |
| 4026 | return QualType(); |
| 4027 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4029 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4030 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 4031 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4032 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4033 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4034 | |
| 4035 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4036 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4037 | |
| 4038 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4039 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4040 | DecltypeTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4041 | const DecltypeType *T = TL.getTypePtr(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4043 | // decltype expressions are not potentially evaluated contexts |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4044 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4046 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4047 | if (E.isInvalid()) |
| 4048 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4050 | QualType Result = TL.getType(); |
| 4051 | if (getDerived().AlwaysRebuild() || |
| 4052 | E.get() != T->getUnderlyingExpr()) { |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 4053 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4054 | if (Result.isNull()) |
| 4055 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4056 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4057 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4059 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 4060 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4061 | |
| 4062 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | template<typename Derived> |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4066 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 4067 | AutoTypeLoc TL) { |
| 4068 | const AutoType *T = TL.getTypePtr(); |
| 4069 | QualType OldDeduced = T->getDeducedType(); |
| 4070 | QualType NewDeduced; |
| 4071 | if (!OldDeduced.isNull()) { |
| 4072 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 4073 | if (NewDeduced.isNull()) |
| 4074 | return QualType(); |
| 4075 | } |
| 4076 | |
| 4077 | QualType Result = TL.getType(); |
| 4078 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { |
| 4079 | Result = getDerived().RebuildAutoType(NewDeduced); |
| 4080 | if (Result.isNull()) |
| 4081 | return QualType(); |
| 4082 | } |
| 4083 | |
| 4084 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 4085 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4086 | |
| 4087 | return Result; |
| 4088 | } |
| 4089 | |
| 4090 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4091 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4092 | RecordTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4093 | const RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4094 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4095 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4096 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4097 | if (!Record) |
| 4098 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4100 | QualType Result = TL.getType(); |
| 4101 | if (getDerived().AlwaysRebuild() || |
| 4102 | Record != T->getDecl()) { |
| 4103 | Result = getDerived().RebuildRecordType(Record); |
| 4104 | if (Result.isNull()) |
| 4105 | return QualType(); |
| 4106 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4108 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 4109 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4110 | |
| 4111 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4112 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
| 4114 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4115 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4116 | EnumTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4117 | const EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4118 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4119 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 4120 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4121 | if (!Enum) |
| 4122 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4124 | QualType Result = TL.getType(); |
| 4125 | if (getDerived().AlwaysRebuild() || |
| 4126 | Enum != T->getDecl()) { |
| 4127 | Result = getDerived().RebuildEnumType(Enum); |
| 4128 | if (Result.isNull()) |
| 4129 | return QualType(); |
| 4130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4132 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 4133 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4134 | |
| 4135 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4136 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4137 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4138 | template<typename Derived> |
| 4139 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 4140 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4141 | InjectedClassNameTypeLoc TL) { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4142 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 4143 | TL.getTypePtr()->getDecl()); |
| 4144 | if (!D) return QualType(); |
| 4145 | |
| 4146 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 4147 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 4148 | return T; |
| 4149 | } |
| 4150 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4151 | template<typename Derived> |
| 4152 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4153 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4154 | TemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4155 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4159 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4160 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4161 | SubstTemplateTypeParmTypeLoc TL) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4162 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | template<typename Derived> |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4166 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 4167 | TypeLocBuilder &TLB, |
| 4168 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4169 | return TransformTypeSpecType(TLB, TL); |
| 4170 | } |
| 4171 | |
| 4172 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4173 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4174 | TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4175 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4176 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 4177 | |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4178 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 4179 | // because we can't have a dependent nested-name-specifier anyway. |
| 4180 | CXXScopeSpec SS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | TemplateName Template |
Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 4182 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 4183 | TL.getTemplateNameLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4184 | if (Template.isNull()) |
| 4185 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4186 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4187 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 4188 | } |
| 4189 | |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4190 | namespace { |
| 4191 | /// \brief Simple iterator that traverses the template arguments in a |
| 4192 | /// container that provides a \c getArgLoc() member function. |
| 4193 | /// |
| 4194 | /// This iterator is intended to be used with the iterator form of |
| 4195 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 4196 | template<typename ArgLocContainer> |
| 4197 | class TemplateArgumentLocContainerIterator { |
| 4198 | ArgLocContainer *Container; |
| 4199 | unsigned Index; |
| 4200 | |
| 4201 | public: |
| 4202 | typedef TemplateArgumentLoc value_type; |
| 4203 | typedef TemplateArgumentLoc reference; |
| 4204 | typedef int difference_type; |
| 4205 | typedef std::input_iterator_tag iterator_category; |
| 4206 | |
| 4207 | class pointer { |
| 4208 | TemplateArgumentLoc Arg; |
| 4209 | |
| 4210 | public: |
| 4211 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4212 | |
| 4213 | const TemplateArgumentLoc *operator->() const { |
| 4214 | return &Arg; |
| 4215 | } |
| 4216 | }; |
| 4217 | |
| 4218 | |
| 4219 | TemplateArgumentLocContainerIterator() {} |
| 4220 | |
| 4221 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 4222 | unsigned Index) |
| 4223 | : Container(&Container), Index(Index) { } |
| 4224 | |
| 4225 | TemplateArgumentLocContainerIterator &operator++() { |
| 4226 | ++Index; |
| 4227 | return *this; |
| 4228 | } |
| 4229 | |
| 4230 | TemplateArgumentLocContainerIterator operator++(int) { |
| 4231 | TemplateArgumentLocContainerIterator Old(*this); |
| 4232 | ++(*this); |
| 4233 | return Old; |
| 4234 | } |
| 4235 | |
| 4236 | TemplateArgumentLoc operator*() const { |
| 4237 | return Container->getArgLoc(Index); |
| 4238 | } |
| 4239 | |
| 4240 | pointer operator->() const { |
| 4241 | return pointer(Container->getArgLoc(Index)); |
| 4242 | } |
| 4243 | |
| 4244 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4245 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4246 | return X.Container == Y.Container && X.Index == Y.Index; |
| 4247 | } |
| 4248 | |
| 4249 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 4250 | const TemplateArgumentLocContainerIterator &Y) { |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4251 | return !(X == Y); |
| 4252 | } |
| 4253 | }; |
| 4254 | } |
| 4255 | |
| 4256 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4257 | template <typename Derived> |
| 4258 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 4259 | TypeLocBuilder &TLB, |
| 4260 | TemplateSpecializationTypeLoc TL, |
| 4261 | TemplateName Template) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4262 | TemplateArgumentListInfo NewTemplateArgs; |
| 4263 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4264 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4265 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 4266 | ArgIterator; |
| 4267 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4268 | ArgIterator(TL, TL.getNumArgs()), |
| 4269 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4270 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4272 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4273 | |
| 4274 | QualType Result = |
| 4275 | getDerived().RebuildTemplateSpecializationType(Template, |
| 4276 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4277 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4278 | |
| 4279 | if (!Result.isNull()) { |
| 4280 | TemplateSpecializationTypeLoc NewTL |
| 4281 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4282 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 4283 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4284 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4285 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4286 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4289 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4290 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4292 | template <typename Derived> |
| 4293 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 4294 | TypeLocBuilder &TLB, |
| 4295 | DependentTemplateSpecializationTypeLoc TL, |
| 4296 | TemplateName Template) { |
| 4297 | TemplateArgumentListInfo NewTemplateArgs; |
| 4298 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4299 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4300 | typedef TemplateArgumentLocContainerIterator< |
| 4301 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4302 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4303 | ArgIterator(TL, TL.getNumArgs()), |
| 4304 | NewTemplateArgs)) |
| 4305 | return QualType(); |
| 4306 | |
| 4307 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 4308 | |
| 4309 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 4310 | QualType Result |
| 4311 | = getSema().Context.getDependentTemplateSpecializationType( |
| 4312 | TL.getTypePtr()->getKeyword(), |
| 4313 | DTN->getQualifier(), |
| 4314 | DTN->getIdentifier(), |
| 4315 | NewTemplateArgs); |
| 4316 | |
| 4317 | DependentTemplateSpecializationTypeLoc NewTL |
| 4318 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 4319 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4320 | |
| 4321 | // FIXME: Poor nested-name-specifier source-location information. |
| 4322 | CXXScopeSpec SS; |
| 4323 | SS.MakeTrivial(SemaRef.Context, |
| 4324 | DTN->getQualifier(), TL.getQualifierLoc().getSourceRange()); |
| 4325 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4326 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4327 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4328 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4329 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4330 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4331 | return Result; |
| 4332 | } |
| 4333 | |
| 4334 | QualType Result |
| 4335 | = getDerived().RebuildTemplateSpecializationType(Template, |
| 4336 | TL.getNameLoc(), |
| 4337 | NewTemplateArgs); |
| 4338 | |
| 4339 | if (!Result.isNull()) { |
| 4340 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 4341 | TemplateSpecializationTypeLoc NewTL |
| 4342 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 4343 | NewTL.setTemplateNameLoc(TL.getNameLoc()); |
| 4344 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4345 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4346 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 4347 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 4348 | } |
| 4349 | |
| 4350 | return Result; |
| 4351 | } |
| 4352 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4354 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4355 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4356 | ElaboratedTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4357 | const ElaboratedType *T = TL.getTypePtr(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4358 | |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4359 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4360 | // NOTE: the qualifier in an ElaboratedType is optional. |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4361 | if (TL.getQualifierLoc()) { |
| 4362 | QualifierLoc |
| 4363 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4364 | if (!QualifierLoc) |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4365 | return QualType(); |
| 4366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4367 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4368 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 4369 | if (NamedT.isNull()) |
| 4370 | return QualType(); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 4371 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4372 | QualType Result = TL.getType(); |
| 4373 | if (getDerived().AlwaysRebuild() || |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4374 | QualifierLoc != TL.getQualifierLoc() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4375 | NamedT != T->getNamedType()) { |
John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 4376 | Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4377 | T->getKeyword(), |
| 4378 | QualifierLoc, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4379 | if (Result.isNull()) |
| 4380 | return QualType(); |
| 4381 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4382 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4383 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4384 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4385 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4386 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | |
| 4389 | template<typename Derived> |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4390 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 4391 | TypeLocBuilder &TLB, |
| 4392 | AttributedTypeLoc TL) { |
| 4393 | const AttributedType *oldType = TL.getTypePtr(); |
| 4394 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 4395 | if (modifiedType.isNull()) |
| 4396 | return QualType(); |
| 4397 | |
| 4398 | QualType result = TL.getType(); |
| 4399 | |
| 4400 | // FIXME: dependent operand expressions? |
| 4401 | if (getDerived().AlwaysRebuild() || |
| 4402 | modifiedType != oldType->getModifiedType()) { |
| 4403 | // TODO: this is really lame; we should really be rebuilding the |
| 4404 | // equivalent type from first principles. |
| 4405 | QualType equivalentType |
| 4406 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 4407 | if (equivalentType.isNull()) |
| 4408 | return QualType(); |
| 4409 | result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), |
| 4410 | modifiedType, |
| 4411 | equivalentType); |
| 4412 | } |
| 4413 | |
| 4414 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 4415 | newTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4416 | if (TL.hasAttrOperand()) |
| 4417 | newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4418 | if (TL.hasAttrExprOperand()) |
| 4419 | newTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4420 | else if (TL.hasAttrEnumOperand()) |
| 4421 | newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); |
| 4422 | |
| 4423 | return result; |
| 4424 | } |
| 4425 | |
| 4426 | template<typename Derived> |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4427 | QualType |
| 4428 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 4429 | ParenTypeLoc TL) { |
| 4430 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 4431 | if (Inner.isNull()) |
| 4432 | return QualType(); |
| 4433 | |
| 4434 | QualType Result = TL.getType(); |
| 4435 | if (getDerived().AlwaysRebuild() || |
| 4436 | Inner != TL.getInnerLoc().getType()) { |
| 4437 | Result = getDerived().RebuildParenType(Inner); |
| 4438 | if (Result.isNull()) |
| 4439 | return QualType(); |
| 4440 | } |
| 4441 | |
| 4442 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 4443 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 4444 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 4445 | return Result; |
| 4446 | } |
| 4447 | |
| 4448 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4449 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4450 | DependentNameTypeLoc TL) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4451 | const DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4453 | NestedNameSpecifierLoc QualifierLoc |
| 4454 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4455 | if (!QualifierLoc) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4456 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4457 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4458 | QualType Result |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4459 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4460 | TL.getKeywordLoc(), |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4461 | QualifierLoc, |
| 4462 | T->getIdentifier(), |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4463 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4464 | if (Result.isNull()) |
| 4465 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4466 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4467 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 4468 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4469 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 4470 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4471 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4472 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4473 | NewTL.setQualifierLoc(QualifierLoc); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4474 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4475 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 4476 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4477 | NewTL.setQualifierLoc(QualifierLoc); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 4478 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4479 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4480 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4483 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4484 | QualType TreeTransform<Derived>:: |
| 4485 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4486 | DependentTemplateSpecializationTypeLoc TL) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4487 | NestedNameSpecifierLoc QualifierLoc; |
| 4488 | if (TL.getQualifierLoc()) { |
| 4489 | QualifierLoc |
| 4490 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 4491 | if (!QualifierLoc) |
Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 4492 | return QualType(); |
| 4493 | } |
| 4494 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4495 | return getDerived() |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4496 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | template<typename Derived> |
| 4500 | QualType TreeTransform<Derived>:: |
| 4501 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4502 | DependentTemplateSpecializationTypeLoc TL, |
| 4503 | NestedNameSpecifier *NNS) { |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4504 | // FIXME: This routine needs to go away. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4505 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4506 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4507 | TemplateArgumentListInfo NewTemplateArgs; |
| 4508 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4509 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4510 | |
| 4511 | // FIXME: Nested-name-specifier source location info! |
Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4512 | typedef TemplateArgumentLocContainerIterator< |
| 4513 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4514 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4515 | ArgIterator(TL, TL.getNumArgs()), |
| 4516 | NewTemplateArgs)) |
Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4517 | return QualType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4518 | |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 4519 | CXXScopeSpec SS; |
| 4520 | SS.MakeTrivial(SemaRef.Context, NNS, |
| 4521 | TL.getQualifierLoc().getSourceRange()); |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4522 | QualType Result |
| 4523 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 4524 | SS.getWithLocInContext(SemaRef.Context), |
Douglas Gregor | a5614c5 | 2010-09-08 23:56:00 +0000 | [diff] [blame] | 4525 | T->getIdentifier(), |
| 4526 | TL.getNameLoc(), |
| 4527 | NewTemplateArgs); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4528 | if (Result.isNull()) |
| 4529 | return QualType(); |
| 4530 | |
| 4531 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4532 | QualType NamedT = ElabT->getNamedType(); |
| 4533 | |
| 4534 | // Copy information relevant to the template specialization. |
| 4535 | TemplateSpecializationTypeLoc NamedTL |
| 4536 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4537 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4538 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4539 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4540 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4541 | |
| 4542 | // Copy information relevant to the elaborated type. |
| 4543 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4544 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4545 | |
| 4546 | // FIXME: DependentTemplateSpecializationType needs better source-location |
| 4547 | // info. |
| 4548 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4549 | Builder.MakeTrivial(SemaRef.Context, |
| 4550 | NNS, TL.getQualifierLoc().getSourceRange()); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4551 | NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4552 | } else { |
Douglas Gregor | ffa2039 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 4553 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4554 | TLB.pushFullCopy(NewTL); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4555 | } |
| 4556 | return Result; |
| 4557 | } |
| 4558 | |
| 4559 | template<typename Derived> |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4560 | QualType TreeTransform<Derived>:: |
| 4561 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 4562 | DependentTemplateSpecializationTypeLoc TL, |
| 4563 | NestedNameSpecifierLoc QualifierLoc) { |
| 4564 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 4565 | |
| 4566 | TemplateArgumentListInfo NewTemplateArgs; |
| 4567 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 4568 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 4569 | |
| 4570 | typedef TemplateArgumentLocContainerIterator< |
| 4571 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 4572 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 4573 | ArgIterator(TL, TL.getNumArgs()), |
| 4574 | NewTemplateArgs)) |
| 4575 | return QualType(); |
| 4576 | |
| 4577 | QualType Result |
| 4578 | = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), |
| 4579 | QualifierLoc, |
| 4580 | T->getIdentifier(), |
| 4581 | TL.getNameLoc(), |
| 4582 | NewTemplateArgs); |
| 4583 | if (Result.isNull()) |
| 4584 | return QualType(); |
| 4585 | |
| 4586 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 4587 | QualType NamedT = ElabT->getNamedType(); |
| 4588 | |
| 4589 | // Copy information relevant to the template specialization. |
| 4590 | TemplateSpecializationTypeLoc NamedTL |
| 4591 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 4592 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 4593 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 4594 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4595 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 4596 | |
| 4597 | // Copy information relevant to the elaborated type. |
| 4598 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 4599 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 4600 | NewTL.setQualifierLoc(QualifierLoc); |
| 4601 | } else { |
| 4602 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 4603 | TLB.pushFullCopy(NewTL); |
| 4604 | } |
| 4605 | return Result; |
| 4606 | } |
| 4607 | |
| 4608 | template<typename Derived> |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4609 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 4610 | PackExpansionTypeLoc TL) { |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4611 | QualType Pattern |
| 4612 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 4613 | if (Pattern.isNull()) |
| 4614 | return QualType(); |
| 4615 | |
| 4616 | QualType Result = TL.getType(); |
| 4617 | if (getDerived().AlwaysRebuild() || |
| 4618 | Pattern != TL.getPatternLoc().getType()) { |
| 4619 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 4620 | TL.getPatternLoc().getSourceRange(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4621 | TL.getEllipsisLoc(), |
| 4622 | TL.getTypePtr()->getNumExpansions()); |
Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 4623 | if (Result.isNull()) |
| 4624 | return QualType(); |
| 4625 | } |
| 4626 | |
| 4627 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 4628 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 4629 | return Result; |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4633 | QualType |
| 4634 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4635 | ObjCInterfaceTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4636 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4637 | TLB.pushFullCopy(TL); |
| 4638 | return TL.getType(); |
| 4639 | } |
| 4640 | |
| 4641 | template<typename Derived> |
| 4642 | QualType |
| 4643 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4644 | ObjCObjectTypeLoc TL) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4645 | // ObjCObjectType is never dependent. |
| 4646 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4647 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
| 4650 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4651 | QualType |
| 4652 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4653 | ObjCObjectPointerTypeLoc TL) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4654 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4655 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 4656 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4657 | } |
| 4658 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4659 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4660 | // Statement transformation |
| 4661 | //===----------------------------------------------------------------------===// |
| 4662 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4663 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4665 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4669 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4670 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 4671 | return getDerived().TransformCompoundStmt(S, false); |
| 4672 | } |
| 4673 | |
| 4674 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4675 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4676 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4677 | bool IsStmtExpr) { |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4678 | bool SubStmtInvalid = false; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4679 | bool SubStmtChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 4680 | ASTOwningVector<Stmt*> Statements(getSema()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4681 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 4682 | B != BEnd; ++B) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4683 | StmtResult Result = getDerived().TransformStmt(*B); |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4684 | if (Result.isInvalid()) { |
| 4685 | // Immediately fail if this was a DeclStmt, since it's very |
| 4686 | // likely that this will cause problems for future statements. |
| 4687 | if (isa<DeclStmt>(*B)) |
| 4688 | return StmtError(); |
| 4689 | |
| 4690 | // Otherwise, just keep processing substatements and fail later. |
| 4691 | SubStmtInvalid = true; |
| 4692 | continue; |
| 4693 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4695 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 4696 | Statements.push_back(Result.takeAs<Stmt>()); |
| 4697 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 4699 | if (SubStmtInvalid) |
| 4700 | return StmtError(); |
| 4701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4702 | if (!getDerived().AlwaysRebuild() && |
| 4703 | !SubStmtChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4704 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4705 | |
| 4706 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 4707 | move_arg(Statements), |
| 4708 | S->getRBracLoc(), |
| 4709 | IsStmtExpr); |
| 4710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4711 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4712 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4713 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4714 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4715 | ExprResult LHS, RHS; |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4716 | { |
| 4717 | // The case value expressions are not potentially evaluated. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4718 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4719 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4720 | // Transform the left-hand case value. |
| 4721 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 4722 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4723 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4724 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4725 | // Transform the right-hand case value (for the GNU case-range extension). |
| 4726 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 4727 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4728 | return StmtError(); |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 4729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4730 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4731 | // Build the case statement. |
| 4732 | // Case statements are always rebuilt so that they will attached to their |
| 4733 | // transformed switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4734 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4735 | LHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4736 | S->getEllipsisLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4737 | RHS.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4738 | S->getColonLoc()); |
| 4739 | if (Case.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4740 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4741 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4742 | // Transform the statement following the case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4743 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4744 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4745 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4747 | // Attach the body to the case statement |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4748 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4752 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4754 | // Transform the statement following the default case |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4755 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4756 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4757 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4759 | // Default statements are always rebuilt |
| 4760 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4761 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4762 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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>::TransformLabelStmt(LabelStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4767 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4768 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4769 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4771 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 4772 | S->getDecl()); |
| 4773 | if (!LD) |
| 4774 | return StmtError(); |
| 4775 | |
| 4776 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4777 | // FIXME: Pass the real colon location in. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 4778 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 4779 | cast<LabelDecl>(LD), SourceLocation(), |
| 4780 | SubStmt.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4781 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4783 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4784 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4785 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4786 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4787 | ExprResult Cond; |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4788 | VarDecl *ConditionVar = 0; |
| 4789 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4790 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4791 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4792 | getDerived().TransformDefinition( |
| 4793 | S->getConditionVariable()->getLocation(), |
| 4794 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4795 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4796 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4797 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 4798 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4799 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4800 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4801 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4802 | |
| 4803 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4804 | if (S->getCond()) { |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4805 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), |
| 4806 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4807 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4808 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4809 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4810 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4811 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4812 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4813 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4814 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4815 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4816 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4817 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4818 | // Transform the "then" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4819 | StmtResult Then = getDerived().TransformStmt(S->getThen()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4820 | if (Then.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4821 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4823 | // Transform the "else" branch. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4824 | StmtResult Else = getDerived().TransformStmt(S->getElse()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4825 | if (Else.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4826 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4828 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4829 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4830 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4831 | Then.get() == S->getThen() && |
| 4832 | Else.get() == S->getElse()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4833 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4834 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4835 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 4836 | Then.get(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4837 | S->getElseLoc(), Else.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4841 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4843 | // Transform the condition. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4844 | ExprResult Cond; |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4845 | VarDecl *ConditionVar = 0; |
| 4846 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4847 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4848 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4849 | getDerived().TransformDefinition( |
| 4850 | S->getConditionVariable()->getLocation(), |
| 4851 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4852 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4853 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4854 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 4855 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4856 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4857 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4858 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4859 | } |
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 | // Rebuild the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4862 | StmtResult Switch |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4863 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 4864 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4865 | if (Switch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4866 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4867 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4868 | // Transform the body of the switch statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4869 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4870 | if (Body.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 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4873 | // Complete the switch statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4874 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 4875 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4877 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4878 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4879 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4880 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4881 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4882 | ExprResult Cond; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4883 | VarDecl *ConditionVar = 0; |
| 4884 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4885 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4886 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4887 | getDerived().TransformDefinition( |
| 4888 | S->getConditionVariable()->getLocation(), |
| 4889 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4890 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4891 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4892 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 4893 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4894 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4895 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4896 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4897 | |
| 4898 | if (S->getCond()) { |
| 4899 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4900 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), |
| 4901 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4902 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4903 | return StmtError(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4904 | Cond = CondE; |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4905 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4907 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4908 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4909 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
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 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4912 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4913 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4914 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4915 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4917 | if (!getDerived().AlwaysRebuild() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4918 | FullCond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4919 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4920 | Body.get() == S->getBody()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4921 | return Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4922 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4923 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4924 | ConditionVar, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4925 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4926 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4927 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4928 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4929 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4930 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4931 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4932 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4933 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4934 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4935 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4936 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4937 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4938 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4939 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4940 | if (!getDerived().AlwaysRebuild() && |
| 4941 | Cond.get() == S->getCond() && |
| 4942 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 4943 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4944 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4945 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 4946 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4947 | S->getRParenLoc()); |
| 4948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4949 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4950 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4951 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4952 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4953 | // Transform the initialization statement |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4954 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4955 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4956 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4957 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4958 | // Transform the condition |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4959 | ExprResult Cond; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4960 | VarDecl *ConditionVar = 0; |
| 4961 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4962 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4963 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 4964 | getDerived().TransformDefinition( |
| 4965 | S->getConditionVariable()->getLocation(), |
| 4966 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4967 | if (!ConditionVar) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4968 | return StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4969 | } else { |
| 4970 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4971 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4972 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4973 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4974 | |
| 4975 | if (S->getCond()) { |
| 4976 | // Convert the condition to a boolean value. |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4977 | ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), |
| 4978 | Cond.get()); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4979 | if (CondE.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4980 | return StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4981 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4982 | Cond = CondE.get(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 4983 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 4984 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4985 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4986 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); |
| 4987 | if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4988 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4989 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4990 | // Transform the increment |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4991 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4992 | if (Inc.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4993 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4994 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4995 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); |
| 4996 | if (S->getInc() && !FullInc.get()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 4997 | return StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 4998 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4999 | // Transform the body |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5000 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5001 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5002 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5003 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5004 | if (!getDerived().AlwaysRebuild() && |
| 5005 | Init.get() == S->getInit() && |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5006 | FullCond.get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5007 | Inc.get() == S->getInc() && |
| 5008 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5009 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5011 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5012 | Init.get(), FullCond, ConditionVar, |
| 5013 | FullInc, S->getRParenLoc(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5017 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5018 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5019 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 5020 | S->getLabel()); |
| 5021 | if (!LD) |
| 5022 | return StmtError(); |
| 5023 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5024 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5025 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 5026 | cast<LabelDecl>(LD)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5030 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5032 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5033 | if (Target.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5034 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5036 | if (!getDerived().AlwaysRebuild() && |
| 5037 | Target.get() == S->getTarget()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5038 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5039 | |
| 5040 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5041 | Target.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5045 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5047 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5050 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5051 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5052 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5053 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5056 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5057 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5058 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5059 | ExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5060 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5061 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5062 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5063 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5064 | // to tell whether the return type of the function has changed. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5065 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5067 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5068 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5069 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5070 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5071 | bool DeclChanged = false; |
| 5072 | llvm::SmallVector<Decl *, 4> Decls; |
| 5073 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 5074 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 5075 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 5076 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5077 | if (!Transformed) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5078 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5080 | if (Transformed != *D) |
| 5081 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5083 | Decls.push_back(Transformed); |
| 5084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5086 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5087 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
| 5089 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5090 | S->getStartLoc(), S->getEndLoc()); |
| 5091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5092 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5093 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5094 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5095 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5096 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5097 | ASTOwningVector<Expr*> Constraints(getSema()); |
| 5098 | ASTOwningVector<Expr*> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5099 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5100 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5101 | ExprResult AsmString; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5102 | ASTOwningVector<Expr*> Clobbers(getSema()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5103 | |
| 5104 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5105 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5106 | // Go through the outputs. |
| 5107 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5108 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5109 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5110 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5111 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5112 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5113 | // Transform the output expr. |
| 5114 | Expr *OutputExpr = S->getOutputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5115 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5116 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5117 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5118 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5119 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5120 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5121 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5122 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5123 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5124 | // Go through the inputs. |
| 5125 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 5126 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5127 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5128 | // No need to transform the constraint literal. |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5129 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5130 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5131 | // Transform the input expr. |
| 5132 | Expr *InputExpr = S->getInputExpr(I); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5133 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5134 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5135 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5136 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5137 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5138 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5139 | Exprs.push_back(Result.get()); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5140 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5141 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5142 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5143 | return SemaRef.Owned(S); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5144 | |
| 5145 | // Go through the clobbers. |
| 5146 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5147 | Clobbers.push_back(S->getClobber(I)); |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5148 | |
| 5149 | // No need to transform the asm string literal. |
| 5150 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 5151 | |
| 5152 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 5153 | S->isSimple(), |
| 5154 | S->isVolatile(), |
| 5155 | S->getNumOutputs(), |
| 5156 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 5157 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5158 | move_arg(Constraints), |
| 5159 | move_arg(Exprs), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5160 | AsmString.get(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 5161 | move_arg(Clobbers), |
| 5162 | S->getRParenLoc(), |
| 5163 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | |
| 5167 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5168 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5170 | // Transform the body of the @try. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5171 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5172 | if (TryBody.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5173 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5174 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5175 | // Transform the @catch statements (if present). |
| 5176 | bool AnyCatchChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5177 | ASTOwningVector<Stmt*> CatchStmts(SemaRef); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5178 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5179 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5180 | if (Catch.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5181 | return StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5182 | if (Catch.get() != S->getCatchStmt(I)) |
| 5183 | AnyCatchChanged = true; |
| 5184 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5185 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5187 | // Transform the @finally statement (if present). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5188 | StmtResult Finally; |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5189 | if (S->getFinallyStmt()) { |
| 5190 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 5191 | if (Finally.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5192 | return StmtError(); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | // If nothing changed, just retain this statement. |
| 5196 | if (!getDerived().AlwaysRebuild() && |
| 5197 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 5198 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5199 | Finally.get() == S->getFinallyStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5200 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5201 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5202 | // Build a new statement. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5203 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 5204 | move_arg(CatchStmts), Finally.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5205 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5206 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5207 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5208 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5210 | // Transform the @catch parameter, if there is one. |
| 5211 | VarDecl *Var = 0; |
| 5212 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 5213 | TypeSourceInfo *TSInfo = 0; |
| 5214 | if (FromVar->getTypeSourceInfo()) { |
| 5215 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 5216 | if (!TSInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5217 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5218 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5219 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5220 | QualType T; |
| 5221 | if (TSInfo) |
| 5222 | T = TSInfo->getType(); |
| 5223 | else { |
| 5224 | T = getDerived().TransformType(FromVar->getType()); |
| 5225 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5226 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5227 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5229 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 5230 | if (!Var) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5231 | return StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5232 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5233 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5234 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5235 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5236 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5237 | |
| 5238 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 5239 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5240 | Var, Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5241 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5242 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5243 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5244 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5245 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5246 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5247 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5248 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5249 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5250 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5251 | // If nothing changed, just retain this statement. |
| 5252 | if (!getDerived().AlwaysRebuild() && |
| 5253 | Body.get() == S->getFinallyBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5254 | return SemaRef.Owned(S); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 5255 | |
| 5256 | // Build a new statement. |
| 5257 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5258 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5261 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5262 | StmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5263 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5264 | ExprResult Operand; |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5265 | if (S->getThrowExpr()) { |
| 5266 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 5267 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5268 | return StmtError(); |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5269 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5270 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 5271 | if (!getDerived().AlwaysRebuild() && |
| 5272 | Operand.get() == S->getThrowExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5273 | return getSema().Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5274 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5275 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5278 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5279 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5280 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5281 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5282 | // Transform the object we are locking. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5283 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5284 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5285 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5286 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5287 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5288 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5289 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5290 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5291 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5292 | // If nothing change, just retain the current statement. |
| 5293 | if (!getDerived().AlwaysRebuild() && |
| 5294 | Object.get() == S->getSynchExpr() && |
| 5295 | Body.get() == S->getSynchBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5296 | return SemaRef.Owned(S); |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 5297 | |
| 5298 | // Build a new statement. |
| 5299 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5300 | Object.get(), Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5304 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5305 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5306 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5307 | // Transform the element statement. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5308 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5309 | if (Element.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5310 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5311 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5312 | // Transform the collection expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5313 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5314 | if (Collection.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5315 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5316 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5317 | // Transform the body. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5318 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5319 | if (Body.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5320 | return StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5321 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5322 | // If nothing changed, just retain this statement. |
| 5323 | if (!getDerived().AlwaysRebuild() && |
| 5324 | Element.get() == S->getElement() && |
| 5325 | Collection.get() == S->getCollection() && |
| 5326 | Body.get() == S->getBody()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5327 | return SemaRef.Owned(S); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5328 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5329 | // Build a new statement. |
| 5330 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 5331 | /*FIXME:*/S->getForLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5332 | Element.get(), |
| 5333 | Collection.get(), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 5334 | S->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5335 | Body.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | |
| 5339 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5340 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5341 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 5342 | // Transform the exception declaration, if any. |
| 5343 | VarDecl *Var = 0; |
| 5344 | if (S->getExceptionDecl()) { |
| 5345 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5346 | TypeSourceInfo *T = getDerived().TransformType( |
| 5347 | ExceptionDecl->getTypeSourceInfo()); |
| 5348 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5349 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5351 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5352 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 5353 | ExceptionDecl->getLocation()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5354 | if (!Var || Var->isInvalidDecl()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5355 | return StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5356 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5358 | // Transform the actual exception handler. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5359 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 5360 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5361 | return StmtError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 5364 | !Var && |
| 5365 | Handler.get() == S->getHandlerBlock()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5366 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5367 | |
| 5368 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 5369 | Var, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5370 | Handler.get()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5371 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5373 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5374 | StmtResult |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5375 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 5376 | // Transform the try block itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5377 | StmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5378 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 5379 | if (TryBlock.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5380 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5382 | // Transform the handlers. |
| 5383 | bool HandlerChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5384 | ASTOwningVector<Stmt*> Handlers(SemaRef); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5385 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5386 | StmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5387 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 5388 | if (Handler.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5389 | return StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5391 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 5392 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 5393 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5394 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5395 | if (!getDerived().AlwaysRebuild() && |
| 5396 | TryBlock.get() == S->getTryBlock() && |
| 5397 | !HandlerChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5398 | return SemaRef.Owned(S); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5399 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5400 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5403 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5404 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5405 | // Expression transformation |
| 5406 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5407 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5408 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5409 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5410 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | |
| 5413 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5414 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5415 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5416 | NestedNameSpecifierLoc QualifierLoc; |
| 5417 | if (E->getQualifierLoc()) { |
| 5418 | QualifierLoc |
| 5419 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5420 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5421 | return ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5422 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5423 | |
| 5424 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5425 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 5426 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5427 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5428 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5429 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5430 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 5431 | if (NameInfo.getName()) { |
| 5432 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 5433 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5434 | return ExprError(); |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 5435 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5436 | |
| 5437 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5438 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5439 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5440 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5441 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5442 | |
| 5443 | // Mark it referenced in the new context regardless. |
| 5444 | // FIXME: this is a bit instantiation-specific. |
| 5445 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 5446 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5447 | return SemaRef.Owned(E); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 5448 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5449 | |
| 5450 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5451 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5452 | TemplateArgs = &TransArgs; |
| 5453 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5454 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5455 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5456 | E->getNumTemplateArgs(), |
| 5457 | TransArgs)) |
| 5458 | return ExprError(); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 5459 | } |
| 5460 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5461 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 5462 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5463 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5464 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5465 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5466 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5467 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5468 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5469 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5471 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5472 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5473 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5474 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5475 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5477 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5478 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5479 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5480 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5482 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5483 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5484 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5485 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5486 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5489 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5490 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5491 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5492 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5496 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5498 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5500 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5503 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5505 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5506 | E->getRParen()); |
| 5507 | } |
| 5508 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5509 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5510 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5511 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5512 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5513 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5514 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5515 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5516 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5517 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5519 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 5520 | E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5521 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5524 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5525 | ExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5526 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 5527 | // Transform the type. |
| 5528 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 5529 | if (!Type) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5530 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5531 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5532 | // Transform all of the components into components similar to what the |
| 5533 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5534 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 5535 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 5536 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5537 | // template code that we don't care. |
| 5538 | bool ExprChanged = false; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5539 | typedef Sema::OffsetOfComponent Component; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5540 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 5541 | llvm::SmallVector<Component, 4> Components; |
| 5542 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 5543 | const Node &ON = E->getComponent(I); |
| 5544 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 5545 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5546 | Comp.LocStart = ON.getRange().getBegin(); |
| 5547 | Comp.LocEnd = ON.getRange().getEnd(); |
| 5548 | switch (ON.getKind()) { |
| 5549 | case Node::Array: { |
| 5550 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5551 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5552 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5553 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5554 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5555 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 5556 | Comp.isBrackets = true; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5557 | Comp.U.E = Index.get(); |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5558 | break; |
| 5559 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5560 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5561 | case Node::Field: |
| 5562 | case Node::Identifier: |
| 5563 | Comp.isBrackets = false; |
| 5564 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 5565 | if (!Comp.U.IdentInfo) |
| 5566 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5568 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5569 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 5570 | case Node::Base: |
| 5571 | // Will be recomputed during the rebuild. |
| 5572 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5573 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5574 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5575 | Components.push_back(Comp); |
| 5576 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5577 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5578 | // If nothing changed, retain the existing expression. |
| 5579 | if (!getDerived().AlwaysRebuild() && |
| 5580 | Type == E->getTypeSourceInfo() && |
| 5581 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5582 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5583 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 5584 | // Build a new offsetof expression. |
| 5585 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 5586 | Components.data(), Components.size(), |
| 5587 | E->getRParenLoc()); |
| 5588 | } |
| 5589 | |
| 5590 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5591 | ExprResult |
John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 5592 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5593 | assert(getDerived().AlreadyTransformed(E->getType()) && |
| 5594 | "opaque value expression requires transformation"); |
| 5595 | return SemaRef.Owned(E); |
| 5596 | } |
| 5597 | |
| 5598 | template<typename Derived> |
| 5599 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5600 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5601 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5602 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 5603 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 5604 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5605 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5606 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5608 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5609 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5610 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 5611 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5612 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5613 | E->getSourceRange()); |
| 5614 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5616 | ExprResult SubExpr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5617 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5618 | // C++0x [expr.sizeof]p1: |
| 5619 | // The operand is either an expression, which is an unevaluated operand |
| 5620 | // [...] |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5621 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 5624 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5625 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5626 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5627 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5628 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5630 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5631 | return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5632 | E->isSizeOf(), |
| 5633 | E->getSourceRange()); |
| 5634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5636 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5637 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5638 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5639 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5640 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5641 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5642 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5643 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5645 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5646 | |
| 5647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5648 | if (!getDerived().AlwaysRebuild() && |
| 5649 | LHS.get() == E->getLHS() && |
| 5650 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5651 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5653 | return getDerived().RebuildArraySubscriptExpr(LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | /*FIXME:*/E->getLHS()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5655 | RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | E->getRBracketLoc()); |
| 5657 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
| 5659 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5660 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5661 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5662 | // Transform the callee. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5663 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5664 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5665 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5666 | |
| 5667 | // Transform arguments. |
| 5668 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5669 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5670 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 5671 | &ArgChanged)) |
| 5672 | return ExprError(); |
| 5673 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5674 | if (!getDerived().AlwaysRebuild() && |
| 5675 | Callee.get() == E->getCallee() && |
| 5676 | !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5677 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5679 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5681 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5682 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5683 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | E->getRParenLoc()); |
| 5685 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | |
| 5687 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5688 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5689 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5690 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5691 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5692 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5694 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5695 | if (E->hasQualifier()) { |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5696 | QualifierLoc |
| 5697 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 5698 | |
| 5699 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5700 | return ExprError(); |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 5701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 5703 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5704 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 5705 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5706 | if (!Member) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5707 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5708 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5709 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 5710 | if (FoundDecl == E->getMemberDecl()) { |
| 5711 | FoundDecl = Member; |
| 5712 | } else { |
| 5713 | FoundDecl = cast_or_null<NamedDecl>( |
| 5714 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 5715 | if (!FoundDecl) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5716 | return ExprError(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5717 | } |
| 5718 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5719 | if (!getDerived().AlwaysRebuild() && |
| 5720 | Base.get() == E->getBase() && |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5721 | QualifierLoc == E->getQualifierLoc() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5722 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5723 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5724 | !E->hasExplicitTemplateArgs()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5725 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5726 | // Mark it referenced in the new context regardless. |
| 5727 | // FIXME: this is a bit instantiation-specific. |
| 5728 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5729 | return SemaRef.Owned(E); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 5730 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5731 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5732 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5733 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5734 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 5735 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 5736 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 5737 | E->getNumTemplateArgs(), |
| 5738 | TransArgs)) |
| 5739 | return ExprError(); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5740 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5742 | // FIXME: Bogus source location for the operator |
| 5743 | SourceLocation FakeOperatorLoc |
| 5744 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 5745 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5746 | // FIXME: to do this check properly, we will need to preserve the |
| 5747 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5748 | // base (and therefore couldn't do the check) and a |
| 5749 | // nested-name-qualifier (and therefore could do the lookup). |
| 5750 | NamedDecl *FirstQualifierInScope = 0; |
| 5751 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5752 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5753 | E->isArrow(), |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 5754 | QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5755 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 5756 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 5757 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 5758 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5759 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5760 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5762 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5763 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5764 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5765 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5766 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5767 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5768 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5769 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5770 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5771 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5772 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5773 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5774 | if (!getDerived().AlwaysRebuild() && |
| 5775 | LHS.get() == E->getLHS() && |
| 5776 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5777 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5778 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5779 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5780 | LHS.get(), RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5781 | } |
| 5782 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5783 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5784 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5785 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5786 | CompoundAssignOperator *E) { |
| 5787 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5789 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5790 | template<typename Derived> |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 5791 | ExprResult TreeTransform<Derived>:: |
| 5792 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 5793 | // Just rebuild the common and RHS expressions and see whether we |
| 5794 | // get any changes. |
| 5795 | |
| 5796 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 5797 | if (commonExpr.isInvalid()) |
| 5798 | return ExprError(); |
| 5799 | |
| 5800 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 5801 | if (rhs.isInvalid()) |
| 5802 | return ExprError(); |
| 5803 | |
| 5804 | if (!getDerived().AlwaysRebuild() && |
| 5805 | commonExpr.get() == e->getCommon() && |
| 5806 | rhs.get() == e->getFalseExpr()) |
| 5807 | return SemaRef.Owned(e); |
| 5808 | |
| 5809 | return getDerived().RebuildConditionalOperator(commonExpr.take(), |
| 5810 | e->getQuestionLoc(), |
| 5811 | 0, |
| 5812 | e->getColonLoc(), |
| 5813 | rhs.get()); |
| 5814 | } |
| 5815 | |
| 5816 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5817 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5818 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5819 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5820 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5821 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5822 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5823 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5824 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5825 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5826 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5827 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5828 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5829 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5830 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5831 | if (!getDerived().AlwaysRebuild() && |
| 5832 | Cond.get() == E->getCond() && |
| 5833 | LHS.get() == E->getLHS() && |
| 5834 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5835 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5836 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5837 | return getDerived().RebuildConditionalOperator(Cond.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5838 | E->getQuestionLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5839 | LHS.get(), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 5840 | E->getColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5841 | RHS.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5843 | |
| 5844 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5845 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5846 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5847 | // Implicit casts are eliminated during transformation, since they |
| 5848 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5849 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5852 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5853 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5854 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5855 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 5856 | if (!Type) |
| 5857 | return ExprError(); |
| 5858 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5859 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5860 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5861 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5862 | return ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5865 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5866 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5867 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5868 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5869 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 5870 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5871 | E->getRParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5872 | SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5873 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5875 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5876 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5877 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5878 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 5879 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 5880 | if (!NewT) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5881 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5882 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5883 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5884 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5885 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5886 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5887 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5888 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5889 | Init.get() == E->getInitializer()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5890 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5891 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 5892 | // Note: the expression type doesn't necessarily match the |
| 5893 | // type-as-written, but that's okay, because it should always be |
| 5894 | // derivable from the initializer. |
| 5895 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 5896 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5897 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5898 | Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5901 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5902 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5903 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5904 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5905 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5906 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5907 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5908 | if (!getDerived().AlwaysRebuild() && |
| 5909 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5910 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5912 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5913 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5914 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 5915 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5916 | E->getAccessorLoc(), |
| 5917 | E->getAccessor()); |
| 5918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5920 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5921 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5922 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5923 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5924 | |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5925 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 5926 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 5927 | Inits, &InitChanged)) |
| 5928 | return ExprError(); |
| 5929 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5930 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5931 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5932 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5933 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 5934 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5936 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5937 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5938 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5939 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5940 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5941 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5942 | // transform the initializer value |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5943 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5944 | if (Init.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5945 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5946 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5947 | // transform the designators. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 5948 | ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5949 | bool ExprChanged = false; |
| 5950 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 5951 | DEnd = E->designators_end(); |
| 5952 | D != DEnd; ++D) { |
| 5953 | if (D->isFieldDesignator()) { |
| 5954 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 5955 | D->getDotLoc(), |
| 5956 | D->getFieldLoc())); |
| 5957 | continue; |
| 5958 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5959 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5960 | if (D->isArrayDesignator()) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5961 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5962 | if (Index.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5963 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5964 | |
| 5965 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5966 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5967 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5968 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 5969 | ArrayExprs.push_back(Index.release()); |
| 5970 | continue; |
| 5971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5973 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5974 | ExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5975 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 5976 | if (Start.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5977 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5978 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5979 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5980 | if (End.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 5981 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5982 | |
| 5983 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5984 | End.get(), |
| 5985 | D->getLBracketLoc(), |
| 5986 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5988 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 5989 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5990 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5991 | ArrayExprs.push_back(Start.release()); |
| 5992 | ArrayExprs.push_back(End.release()); |
| 5993 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5994 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5995 | if (!getDerived().AlwaysRebuild() && |
| 5996 | Init.get() == E->getInit() && |
| 5997 | !ExprChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 5998 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5999 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6000 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 6001 | E->getEqualOrColonLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6002 | E->usesGNUSyntax(), Init.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6003 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6004 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6005 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6006 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6007 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6008 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6009 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6010 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 6011 | // FIXME: Will we ever have proper type location here? Will we actually |
| 6012 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6013 | QualType T = getDerived().TransformType(E->getType()); |
| 6014 | if (T.isNull()) |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6017 | if (!getDerived().AlwaysRebuild() && |
| 6018 | T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6019 | return SemaRef.Owned(E); |
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 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 6022 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6024 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6025 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6026 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 6027 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 6028 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6029 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6030 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6031 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6032 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6033 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6034 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6035 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6036 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6037 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6038 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6039 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6040 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 6041 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6042 | } |
| 6043 | |
| 6044 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6045 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6046 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6047 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6048 | ASTOwningVector<Expr*, 4> Inits(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6049 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 6050 | &ArgumentChanged)) |
| 6051 | return ExprError(); |
| 6052 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6053 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 6054 | move_arg(Inits), |
| 6055 | E->getRParenLoc()); |
| 6056 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6057 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6058 | /// \brief Transform an address-of-label expression. |
| 6059 | /// |
| 6060 | /// By default, the transformation of an address-of-label expression always |
| 6061 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 6062 | /// the corresponding label statement by semantic analysis. |
| 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>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6066 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 6067 | E->getLabel()); |
| 6068 | if (!LD) |
| 6069 | return ExprError(); |
| 6070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6071 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6072 | cast<LabelDecl>(LD)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6074 | |
| 6075 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6076 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6077 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6078 | StmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6079 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 6080 | if (SubStmt.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6081 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6083 | if (!getDerived().AlwaysRebuild() && |
| 6084 | SubStmt.get() == E->getSubStmt()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6085 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6086 | |
| 6087 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6088 | SubStmt.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6089 | E->getRParenLoc()); |
| 6090 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6091 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6092 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6093 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6094 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6095 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6096 | if (Cond.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6097 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6098 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6099 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6100 | if (LHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6101 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6102 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6103 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6104 | if (RHS.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6105 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6106 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6107 | if (!getDerived().AlwaysRebuild() && |
| 6108 | Cond.get() == E->getCond() && |
| 6109 | LHS.get() == E->getLHS() && |
| 6110 | RHS.get() == E->getRHS()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6111 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6112 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6113 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6114 | Cond.get(), LHS.get(), RHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6115 | E->getRParenLoc()); |
| 6116 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6117 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6118 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6119 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6120 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6121 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6125 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6126 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6127 | switch (E->getOperator()) { |
| 6128 | case OO_New: |
| 6129 | case OO_Delete: |
| 6130 | case OO_Array_New: |
| 6131 | case OO_Array_Delete: |
| 6132 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6133 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6134 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6135 | case OO_Call: { |
| 6136 | // This is a call to an object's operator(). |
| 6137 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 6138 | |
| 6139 | // Transform the object itself. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6140 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6141 | if (Object.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6142 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6143 | |
| 6144 | // FIXME: Poor location information |
| 6145 | SourceLocation FakeLParenLoc |
| 6146 | = SemaRef.PP.getLocForEndOfToken( |
| 6147 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 6148 | |
| 6149 | // Transform the call arguments. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6150 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6151 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 6152 | Args)) |
| 6153 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6154 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6155 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6156 | move_arg(Args), |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6157 | E->getLocEnd()); |
| 6158 | } |
| 6159 | |
| 6160 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 6161 | case OO_##Name: |
| 6162 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 6163 | #include "clang/Basic/OperatorKinds.def" |
| 6164 | case OO_Subscript: |
| 6165 | // Handled below. |
| 6166 | break; |
| 6167 | |
| 6168 | case OO_Conditional: |
| 6169 | llvm_unreachable("conditional operator is not actually overloadable"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6170 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6171 | |
| 6172 | case OO_None: |
| 6173 | case NUM_OVERLOADED_OPERATORS: |
| 6174 | llvm_unreachable("not an overloaded operator?"); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6175 | return ExprError(); |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6178 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6179 | if (Callee.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6180 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6181 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6182 | ExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6183 | if (First.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6184 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6185 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6186 | ExprResult Second; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6187 | if (E->getNumArgs() == 2) { |
| 6188 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 6189 | if (Second.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6190 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6191 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6192 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6193 | if (!getDerived().AlwaysRebuild() && |
| 6194 | Callee.get() == E->getCallee() && |
| 6195 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6196 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6197 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6198 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6199 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 6200 | E->getOperatorLoc(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6201 | Callee.get(), |
| 6202 | First.get(), |
| 6203 | Second.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6204 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6206 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6207 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6208 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6209 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6210 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6211 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6212 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6213 | ExprResult |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 6214 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 6215 | // Transform the callee. |
| 6216 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 6217 | if (Callee.isInvalid()) |
| 6218 | return ExprError(); |
| 6219 | |
| 6220 | // Transform exec config. |
| 6221 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 6222 | if (EC.isInvalid()) |
| 6223 | return ExprError(); |
| 6224 | |
| 6225 | // Transform arguments. |
| 6226 | bool ArgChanged = false; |
| 6227 | ASTOwningVector<Expr*> Args(SemaRef); |
| 6228 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6229 | &ArgChanged)) |
| 6230 | return ExprError(); |
| 6231 | |
| 6232 | if (!getDerived().AlwaysRebuild() && |
| 6233 | Callee.get() == E->getCallee() && |
| 6234 | !ArgChanged) |
| 6235 | return SemaRef.Owned(E); |
| 6236 | |
| 6237 | // FIXME: Wrong source location information for the '('. |
| 6238 | SourceLocation FakeLParenLoc |
| 6239 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 6240 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 6241 | move_arg(Args), |
| 6242 | E->getRParenLoc(), EC.get()); |
| 6243 | } |
| 6244 | |
| 6245 | template<typename Derived> |
| 6246 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6247 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6248 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6249 | if (!Type) |
| 6250 | return ExprError(); |
| 6251 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6252 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6253 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6254 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6255 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6257 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6258 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6259 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6260 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6261 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6262 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6263 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6264 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 6265 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 6266 | SourceLocation FakeRParenLoc |
| 6267 | = SemaRef.PP.getLocForEndOfToken( |
| 6268 | E->getSubExpr()->getSourceRange().getEnd()); |
| 6269 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6270 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6271 | FakeLAngleLoc, |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6272 | Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6273 | FakeRAngleLoc, |
| 6274 | FakeRAngleLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6275 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6276 | FakeRParenLoc); |
| 6277 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6278 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6279 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6280 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6281 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 6282 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6284 | |
| 6285 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6286 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6287 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 6288 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6291 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6292 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6293 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6294 | CXXReinterpretCastExpr *E) { |
| 6295 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6298 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6299 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6300 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 6301 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6304 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6305 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6306 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6307 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6308 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 6309 | if (!Type) |
| 6310 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6311 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6312 | ExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 6313 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6314 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6315 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6317 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6318 | Type == E->getTypeInfoAsWritten() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6319 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6320 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6321 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6322 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6323 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6324 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6325 | E->getRParenLoc()); |
| 6326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6328 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6329 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6330 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6331 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6332 | TypeSourceInfo *TInfo |
| 6333 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6334 | if (!TInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6335 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6336 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6337 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6338 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6339 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6340 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6341 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6342 | E->getLocStart(), |
| 6343 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6344 | E->getLocEnd()); |
| 6345 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6346 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6347 | // We don't know whether the expression is potentially evaluated until |
| 6348 | // after we perform semantic analysis, so the expression is potentially |
| 6349 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6350 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6351 | Sema::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6352 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6353 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6354 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6355 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6357 | if (!getDerived().AlwaysRebuild() && |
| 6358 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6359 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6360 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 6361 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6362 | E->getLocStart(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6363 | SubExpr.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6364 | E->getLocEnd()); |
| 6365 | } |
| 6366 | |
| 6367 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6368 | ExprResult |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6369 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 6370 | if (E->isTypeOperand()) { |
| 6371 | TypeSourceInfo *TInfo |
| 6372 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 6373 | if (!TInfo) |
| 6374 | return ExprError(); |
| 6375 | |
| 6376 | if (!getDerived().AlwaysRebuild() && |
| 6377 | TInfo == E->getTypeOperandSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6378 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6379 | |
| 6380 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 6381 | E->getLocStart(), |
| 6382 | TInfo, |
| 6383 | E->getLocEnd()); |
| 6384 | } |
| 6385 | |
| 6386 | // We don't know whether the expression is potentially evaluated until |
| 6387 | // after we perform semantic analysis, so the expression is potentially |
| 6388 | // potentially evaluated. |
| 6389 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); |
| 6390 | |
| 6391 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 6392 | if (SubExpr.isInvalid()) |
| 6393 | return ExprError(); |
| 6394 | |
| 6395 | if (!getDerived().AlwaysRebuild() && |
| 6396 | SubExpr.get() == E->getExprOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6397 | return SemaRef.Owned(E); |
Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 6398 | |
| 6399 | return getDerived().RebuildCXXUuidofExpr(E->getType(), |
| 6400 | E->getLocStart(), |
| 6401 | SubExpr.get(), |
| 6402 | E->getLocEnd()); |
| 6403 | } |
| 6404 | |
| 6405 | template<typename Derived> |
| 6406 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6407 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6408 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6409 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6411 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6412 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6413 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6414 | CXXNullPtrLiteralExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6415 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6417 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6418 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6419 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6420 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6421 | DeclContext *DC = getSema().getFunctionLevelDeclContext(); |
| 6422 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); |
| 6423 | QualType T = MD->getThisType(getSema().Context); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6424 | |
Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 6425 | if (!getDerived().AlwaysRebuild() && T == E->getType()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6426 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6427 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 6428 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6430 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6431 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6432 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6433 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6434 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6435 | if (SubExpr.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6436 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6438 | if (!getDerived().AlwaysRebuild() && |
| 6439 | SubExpr.get() == E->getSubExpr()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6440 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6441 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6442 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6443 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6444 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6445 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6446 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6447 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6448 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6449 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 6450 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6451 | if (!Param) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6452 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6453 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 6454 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6455 | Param == E->getParam()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6456 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6457 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 6458 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6459 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6460 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6461 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6462 | ExprResult |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6463 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 6464 | CXXScalarValueInitExpr *E) { |
| 6465 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6466 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6467 | return ExprError(); |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6468 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6470 | T == E->getTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6471 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6472 | |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6473 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 6474 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 6475 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6476 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6477 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6478 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6479 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6480 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6481 | // Transform the type that we're allocating |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6482 | TypeSourceInfo *AllocTypeInfo |
| 6483 | = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); |
| 6484 | if (!AllocTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6485 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6486 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6487 | // Transform the size of the array we're allocating (if any). |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6488 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6489 | if (ArraySize.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6490 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6491 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6492 | // Transform the placement arguments (if any). |
| 6493 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6494 | ASTOwningVector<Expr*> PlacementArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6495 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 6496 | E->getNumPlacementArgs(), true, |
| 6497 | PlacementArgs, &ArgumentChanged)) |
| 6498 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6499 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6500 | // transform the constructor arguments (if any). |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6501 | ASTOwningVector<Expr*> ConstructorArgs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6502 | if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, |
| 6503 | ConstructorArgs, &ArgumentChanged)) |
| 6504 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6505 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6506 | // Transform constructor, new operator, and delete operator. |
| 6507 | CXXConstructorDecl *Constructor = 0; |
| 6508 | if (E->getConstructor()) { |
| 6509 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6510 | getDerived().TransformDecl(E->getLocStart(), |
| 6511 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6512 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6513 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6514 | } |
| 6515 | |
| 6516 | FunctionDecl *OperatorNew = 0; |
| 6517 | if (E->getOperatorNew()) { |
| 6518 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6519 | getDerived().TransformDecl(E->getLocStart(), |
| 6520 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6521 | if (!OperatorNew) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6522 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6523 | } |
| 6524 | |
| 6525 | FunctionDecl *OperatorDelete = 0; |
| 6526 | if (E->getOperatorDelete()) { |
| 6527 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6528 | getDerived().TransformDecl(E->getLocStart(), |
| 6529 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6530 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6531 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6532 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6534 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6535 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6536 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6537 | Constructor == E->getConstructor() && |
| 6538 | OperatorNew == E->getOperatorNew() && |
| 6539 | OperatorDelete == E->getOperatorDelete() && |
| 6540 | !ArgumentChanged) { |
| 6541 | // Mark any declarations we need as referenced. |
| 6542 | // FIXME: instantiation-specific. |
| 6543 | if (Constructor) |
| 6544 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 6545 | if (OperatorNew) |
| 6546 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 6547 | if (OperatorDelete) |
| 6548 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6549 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6550 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6551 | |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6552 | QualType AllocType = AllocTypeInfo->getType(); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6553 | if (!ArraySize.get()) { |
| 6554 | // If no array size was specified, but the new expression was |
| 6555 | // instantiated with an array type (e.g., "new T" where T is |
| 6556 | // instantiated with "int[4]"), extract the outer bound from the |
| 6557 | // array type as our array size. We do this with constant and |
| 6558 | // dependently-sized array types. |
| 6559 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 6560 | if (!ArrayT) { |
| 6561 | // Do nothing |
| 6562 | } else if (const ConstantArrayType *ConsArrayT |
| 6563 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6564 | ArraySize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 6565 | = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, |
| 6566 | ConsArrayT->getSize(), |
| 6567 | SemaRef.Context.getSizeType(), |
| 6568 | /*FIXME:*/E->getLocStart())); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6569 | AllocType = ConsArrayT->getElementType(); |
| 6570 | } else if (const DependentSizedArrayType *DepArrayT |
| 6571 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 6572 | if (DepArrayT->getSizeExpr()) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6573 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 6574 | AllocType = DepArrayT->getElementType(); |
| 6575 | } |
| 6576 | } |
| 6577 | } |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6579 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 6580 | E->isGlobalNew(), |
| 6581 | /*FIXME:*/E->getLocStart(), |
| 6582 | move_arg(PlacementArgs), |
| 6583 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 6584 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6585 | AllocType, |
Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 6586 | AllocTypeInfo, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6587 | ArraySize.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6588 | /*FIXME:*/E->getLocStart(), |
| 6589 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6590 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6592 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6593 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6594 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6595 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6596 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6597 | if (Operand.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6598 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6599 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6600 | // Transform the delete operator, if known. |
| 6601 | FunctionDecl *OperatorDelete = 0; |
| 6602 | if (E->getOperatorDelete()) { |
| 6603 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6604 | getDerived().TransformDecl(E->getLocStart(), |
| 6605 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6606 | if (!OperatorDelete) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6607 | return ExprError(); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6608 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6609 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6610 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6611 | Operand.get() == E->getArgument() && |
| 6612 | OperatorDelete == E->getOperatorDelete()) { |
| 6613 | // Mark any declarations we need as referenced. |
| 6614 | // FIXME: instantiation-specific. |
| 6615 | if (OperatorDelete) |
| 6616 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 6617 | |
| 6618 | if (!E->getArgument()->isTypeDependent()) { |
| 6619 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 6620 | E->getDestroyedType()); |
| 6621 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 6622 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 6623 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), |
| 6624 | SemaRef.LookupDestructor(Record)); |
| 6625 | } |
| 6626 | } |
| 6627 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6628 | return SemaRef.Owned(E); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6630 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6631 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 6632 | E->isGlobalDelete(), |
| 6633 | E->isArrayForm(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6634 | Operand.get()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6636 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6637 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6638 | ExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6639 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6640 | CXXPseudoDestructorExpr *E) { |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6641 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6642 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6643 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6644 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6645 | ParsedType ObjectTypePtr; |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6646 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6647 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6648 | E->getOperatorLoc(), |
| 6649 | E->isArrow()? tok::arrow : tok::period, |
| 6650 | ObjectTypePtr, |
| 6651 | MayBePseudoDestructor); |
| 6652 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6653 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6654 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6655 | QualType ObjectType = ObjectTypePtr.get(); |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6656 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 6657 | if (QualifierLoc) { |
| 6658 | QualifierLoc |
| 6659 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 6660 | if (!QualifierLoc) |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6661 | return ExprError(); |
| 6662 | } |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6663 | CXXScopeSpec SS; |
| 6664 | SS.Adopt(QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6665 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6666 | PseudoDestructorTypeStorage Destroyed; |
| 6667 | if (E->getDestroyedTypeInfo()) { |
| 6668 | TypeSourceInfo *DestroyedTypeInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6669 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 6670 | ObjectType, 0, SS); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6671 | if (!DestroyedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6672 | return ExprError(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6673 | Destroyed = DestroyedTypeInfo; |
| 6674 | } else if (ObjectType->isDependentType()) { |
| 6675 | // We aren't likely to be able to resolve the identifier down to a type |
| 6676 | // now anyway, so just retain the identifier. |
| 6677 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 6678 | E->getDestroyedTypeLoc()); |
| 6679 | } else { |
| 6680 | // Look for a destructor known with the given name. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 6681 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6682 | *E->getDestroyedTypeIdentifier(), |
| 6683 | E->getDestroyedTypeLoc(), |
| 6684 | /*Scope=*/0, |
| 6685 | SS, ObjectTypePtr, |
| 6686 | false); |
| 6687 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6688 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6689 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6690 | Destroyed |
| 6691 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 6692 | E->getDestroyedTypeLoc()); |
| 6693 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6694 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6695 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 6696 | if (E->getScopeTypeInfo()) { |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6697 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6698 | if (!ScopeTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6699 | return ExprError(); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6700 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6701 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6702 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6703 | E->getOperatorLoc(), |
| 6704 | E->isArrow(), |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 6705 | SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6706 | ScopeTypeInfo, |
| 6707 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6708 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6709 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6711 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 6712 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6713 | ExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6714 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6715 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6716 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 6717 | |
| 6718 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 6719 | Sema::LookupOrdinaryName); |
| 6720 | |
| 6721 | // Transform all the decls. |
| 6722 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 6723 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6724 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 6725 | getDerived().TransformDecl(Old->getNameLoc(), |
| 6726 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6727 | if (!InstD) { |
| 6728 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 6729 | // This can happen because of dependent hiding. |
| 6730 | if (isa<UsingShadowDecl>(*I)) |
| 6731 | continue; |
| 6732 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6733 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 6734 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6735 | |
| 6736 | // Expand using declarations. |
| 6737 | if (isa<UsingDecl>(InstD)) { |
| 6738 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 6739 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 6740 | E = UD->shadow_end(); I != E; ++I) |
| 6741 | R.addDecl(*I); |
| 6742 | continue; |
| 6743 | } |
| 6744 | |
| 6745 | R.addDecl(InstD); |
| 6746 | } |
| 6747 | |
| 6748 | // Resolve a kind, but don't do any further analysis. If it's |
| 6749 | // ambiguous, the callee needs to deal with it. |
| 6750 | R.resolveKind(); |
| 6751 | |
| 6752 | // Rebuild the nested-name qualifier, if present. |
| 6753 | CXXScopeSpec SS; |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6754 | if (Old->getQualifierLoc()) { |
| 6755 | NestedNameSpecifierLoc QualifierLoc |
| 6756 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 6757 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6758 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6759 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 6760 | SS.Adopt(QualifierLoc); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 6763 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6764 | CXXRecordDecl *NamingClass |
| 6765 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 6766 | Old->getNameLoc(), |
| 6767 | Old->getNamingClass())); |
| 6768 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6769 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6770 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 6771 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | // If we have no template arguments, it's a normal declaration name. |
| 6775 | if (!Old->hasExplicitTemplateArgs()) |
| 6776 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 6777 | |
| 6778 | // If we have template arguments, rebuild them, then rebuild the |
| 6779 | // templateid expression. |
| 6780 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6781 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 6782 | Old->getNumTemplateArgs(), |
| 6783 | TransArgs)) |
| 6784 | return ExprError(); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6785 | |
| 6786 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 6787 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6789 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6790 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6791 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6792 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6793 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 6794 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6795 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6797 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 54e5b13 | 2010-09-09 16:14:44 +0000 | [diff] [blame] | 6798 | T == E->getQueriedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6799 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6800 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6801 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6802 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6803 | T, |
| 6804 | E->getLocEnd()); |
| 6805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6806 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6807 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6808 | ExprResult |
Francois Pichet | 9dfa3ce | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 6809 | TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { |
| 6810 | TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); |
| 6811 | if (!LhsT) |
| 6812 | return ExprError(); |
| 6813 | |
| 6814 | TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); |
| 6815 | if (!RhsT) |
| 6816 | return ExprError(); |
| 6817 | |
| 6818 | if (!getDerived().AlwaysRebuild() && |
| 6819 | LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) |
| 6820 | return SemaRef.Owned(E); |
| 6821 | |
| 6822 | return getDerived().RebuildBinaryTypeTrait(E->getTrait(), |
| 6823 | E->getLocStart(), |
| 6824 | LhsT, RhsT, |
| 6825 | E->getLocEnd()); |
| 6826 | } |
| 6827 | |
| 6828 | template<typename Derived> |
| 6829 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 6830 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6831 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6832 | NestedNameSpecifierLoc QualifierLoc |
| 6833 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 6834 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6835 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6836 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6837 | // TODO: If this is a conversion-function-id, verify that the |
| 6838 | // destination type name (if present) resolves the same way after |
| 6839 | // instantiation as it did in the local scope. |
| 6840 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6841 | DeclarationNameInfo NameInfo |
| 6842 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 6843 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6844 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6845 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6846 | if (!E->hasExplicitTemplateArgs()) { |
| 6847 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6848 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6849 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 6850 | // if name has not changed, DNLoc has not changed either. |
| 6851 | NameInfo.getName() == E->getDeclName()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6852 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6853 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6854 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6855 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6856 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 6857 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6858 | |
| 6859 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 6860 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 6861 | E->getNumTemplateArgs(), |
| 6862 | TransArgs)) |
| 6863 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6864 | |
Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 6865 | return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6866 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 6867 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6868 | } |
| 6869 | |
| 6870 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6871 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6872 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 6873 | // CXXConstructExprs are always implicit, so when we have a |
| 6874 | // 1-argument construction we just transform that argument. |
| 6875 | if (E->getNumArgs() == 1 || |
| 6876 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 6877 | return getDerived().TransformExpr(E->getArg(0)); |
| 6878 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6879 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 6880 | |
| 6881 | QualType T = getDerived().TransformType(E->getType()); |
| 6882 | if (T.isNull()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6883 | return ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6884 | |
| 6885 | CXXConstructorDecl *Constructor |
| 6886 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6887 | getDerived().TransformDecl(E->getLocStart(), |
| 6888 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6889 | if (!Constructor) |
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 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6892 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6893 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6894 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6895 | &ArgumentChanged)) |
| 6896 | return ExprError(); |
| 6897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6898 | if (!getDerived().AlwaysRebuild() && |
| 6899 | T == E->getType() && |
| 6900 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6901 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 6902 | // Mark the constructor as referenced. |
| 6903 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6904 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6905 | return SemaRef.Owned(E); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 6906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6907 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 6908 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 6909 | Constructor, E->isElidable(), |
Douglas Gregor | b0a04ff | 2010-08-22 17:20:18 +0000 | [diff] [blame] | 6910 | move_arg(Args), |
| 6911 | E->requiresZeroInitialization(), |
Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 6912 | E->getConstructionKind(), |
| 6913 | E->getParenRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6914 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6916 | /// \brief Transform a C++ temporary-binding expression. |
| 6917 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6918 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 6919 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6920 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6921 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6922 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6923 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6924 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6925 | |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6926 | /// \brief Transform a C++ expression that contains cleanups that should |
| 6927 | /// be run after the expression is evaluated. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6928 | /// |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6929 | /// Since ExprWithCleanups nodes are implicitly generated, we |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6930 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6931 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6932 | ExprResult |
John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 6933 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 6934 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6936 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6937 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6938 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6939 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6940 | CXXTemporaryObjectExpr *E) { |
| 6941 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6942 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6943 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6944 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6945 | CXXConstructorDecl *Constructor |
| 6946 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6947 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 6948 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6949 | if (!Constructor) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6950 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6951 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6952 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6953 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6954 | Args.reserve(E->getNumArgs()); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6955 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 6956 | &ArgumentChanged)) |
| 6957 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6958 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6959 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6960 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6961 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6962 | !ArgumentChanged) { |
| 6963 | // FIXME: Instantiation-specific |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6964 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6965 | return SemaRef.MaybeBindToTemporary(E); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 6966 | } |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6967 | |
| 6968 | return getDerived().RebuildCXXTemporaryObjectExpr(T, |
| 6969 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6970 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6971 | E->getLocEnd()); |
| 6972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6973 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6974 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6975 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6976 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6977 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6978 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 6979 | if (!T) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6980 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6982 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 6983 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 6984 | Args.reserve(E->arg_size()); |
| 6985 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 6986 | &ArgumentChanged)) |
| 6987 | return ExprError(); |
| 6988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6989 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6990 | T == E->getTypeSourceInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6991 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6992 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6993 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6994 | // FIXME: we're faking the locations of the commas |
Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 6995 | return getDerived().RebuildCXXUnresolvedConstructExpr(T, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6996 | E->getLParenLoc(), |
| 6997 | move_arg(Args), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6998 | E->getRParenLoc()); |
| 6999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7000 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7001 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7002 | ExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 7003 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7004 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7005 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7006 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7007 | Expr *OldBase; |
| 7008 | QualType BaseType; |
| 7009 | QualType ObjectType; |
| 7010 | if (!E->isImplicitAccess()) { |
| 7011 | OldBase = E->getBase(); |
| 7012 | Base = getDerived().TransformExpr(OldBase); |
| 7013 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7014 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7015 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7016 | // Start the member reference and compute the object's type. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7017 | ParsedType ObjectTy; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7018 | bool MayBePseudoDestructor = false; |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7019 | Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7020 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7021 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 7022 | ObjectTy, |
| 7023 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7024 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7025 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7026 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7027 | ObjectType = ObjectTy.get(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7028 | BaseType = ((Expr*) Base.get())->getType(); |
| 7029 | } else { |
| 7030 | OldBase = 0; |
| 7031 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 7032 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 7033 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7034 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7035 | // Transform the first part of the nested-name-specifier that qualifies |
| 7036 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7037 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 7038 | = getDerived().TransformFirstQualifierInScope( |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7039 | E->getFirstQualifierFoundInScope(), |
| 7040 | E->getQualifierLoc().getBeginLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7041 | |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7042 | NestedNameSpecifierLoc QualifierLoc; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7043 | if (E->getQualifier()) { |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7044 | QualifierLoc |
| 7045 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 7046 | ObjectType, |
| 7047 | FirstQualifierInScope); |
| 7048 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7049 | return ExprError(); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7051 | |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7052 | // TODO: If this is a conversion-function-id, verify that the |
| 7053 | // destination type name (if present) resolves the same way after |
| 7054 | // instantiation as it did in the local scope. |
| 7055 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7056 | DeclarationNameInfo NameInfo |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7057 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7058 | if (!NameInfo.getName()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7059 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7060 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7061 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7062 | // This is a reference to a member without an explicitly-specified |
| 7063 | // template argument list. Optimize for this common case. |
| 7064 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7065 | Base.get() == OldBase && |
| 7066 | BaseType == E->getBaseType() && |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7067 | QualifierLoc == E->getQualifierLoc() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7068 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7069 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7070 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7071 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7072 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7073 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7074 | E->isArrow(), |
| 7075 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7076 | QualifierLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7077 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7078 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7079 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7080 | } |
| 7081 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7082 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7083 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 7084 | E->getNumTemplateArgs(), |
| 7085 | TransArgs)) |
| 7086 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7087 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7088 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7089 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7090 | E->isArrow(), |
| 7091 | E->getOperatorLoc(), |
Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 7092 | QualifierLoc, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 7093 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7094 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7095 | &TransArgs); |
| 7096 | } |
| 7097 | |
| 7098 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7099 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7100 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7101 | // Transform the base of the expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7102 | ExprResult Base((Expr*) 0); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7103 | QualType BaseType; |
| 7104 | if (!Old->isImplicitAccess()) { |
| 7105 | Base = getDerived().TransformExpr(Old->getBase()); |
| 7106 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7107 | return ExprError(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7108 | BaseType = ((Expr*) Base.get())->getType(); |
| 7109 | } else { |
| 7110 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 7111 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7112 | |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7113 | NestedNameSpecifierLoc QualifierLoc; |
| 7114 | if (Old->getQualifierLoc()) { |
| 7115 | QualifierLoc |
| 7116 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 7117 | if (!QualifierLoc) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7118 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7119 | } |
| 7120 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7121 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7122 | Sema::LookupOrdinaryName); |
| 7123 | |
| 7124 | // Transform all the decls. |
| 7125 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 7126 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 7127 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 7128 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 7129 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7130 | if (!InstD) { |
| 7131 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 7132 | // This can happen because of dependent hiding. |
| 7133 | if (isa<UsingShadowDecl>(*I)) |
| 7134 | continue; |
| 7135 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7136 | return ExprError(); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 7137 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7138 | |
| 7139 | // Expand using declarations. |
| 7140 | if (isa<UsingDecl>(InstD)) { |
| 7141 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 7142 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 7143 | E = UD->shadow_end(); I != E; ++I) |
| 7144 | R.addDecl(*I); |
| 7145 | continue; |
| 7146 | } |
| 7147 | |
| 7148 | R.addDecl(InstD); |
| 7149 | } |
| 7150 | |
| 7151 | R.resolveKind(); |
| 7152 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7153 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 7154 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7155 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7156 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7157 | Old->getMemberLoc(), |
| 7158 | Old->getNamingClass())); |
| 7159 | if (!NamingClass) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7160 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7161 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 7162 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 7163 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7164 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7165 | TemplateArgumentListInfo TransArgs; |
| 7166 | if (Old->hasExplicitTemplateArgs()) { |
| 7167 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 7168 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 7169 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 7170 | Old->getNumTemplateArgs(), |
| 7171 | TransArgs)) |
| 7172 | return ExprError(); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7173 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7174 | |
| 7175 | // FIXME: to do this check properly, we will need to preserve the |
| 7176 | // first-qualifier-in-scope here, just in case we had a dependent |
| 7177 | // base (and therefore couldn't do the check) and a |
| 7178 | // nested-name-qualifier (and therefore could do the lookup). |
| 7179 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7180 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7181 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 7182 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7183 | Old->getOperatorLoc(), |
| 7184 | Old->isArrow(), |
Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 7185 | QualifierLoc, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 7186 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 7187 | R, |
| 7188 | (Old->hasExplicitTemplateArgs() |
| 7189 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7190 | } |
| 7191 | |
| 7192 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7193 | ExprResult |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7194 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 7195 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 7196 | if (SubExpr.isInvalid()) |
| 7197 | return ExprError(); |
| 7198 | |
| 7199 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7200 | return SemaRef.Owned(E); |
Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 7201 | |
| 7202 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 7203 | } |
| 7204 | |
| 7205 | template<typename Derived> |
| 7206 | ExprResult |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7207 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 7208 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 7209 | if (Pattern.isInvalid()) |
| 7210 | return ExprError(); |
| 7211 | |
| 7212 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 7213 | return SemaRef.Owned(E); |
| 7214 | |
Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 7215 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 7216 | E->getNumExpansions()); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7217 | } |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7218 | |
| 7219 | template<typename Derived> |
| 7220 | ExprResult |
| 7221 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7222 | // If E is not value-dependent, then nothing will change when we transform it. |
| 7223 | // Note: This is an instantiation-centric view. |
| 7224 | if (!E->isValueDependent()) |
| 7225 | return SemaRef.Owned(E); |
| 7226 | |
| 7227 | // Note: None of the implementations of TryExpandParameterPacks can ever |
| 7228 | // produce a diagnostic when given only a single unexpanded parameter pack, |
| 7229 | // so |
| 7230 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 7231 | bool ShouldExpand = false; |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7232 | bool RetainExpansion = false; |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7233 | llvm::Optional<unsigned> NumExpansions; |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7234 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 7235 | &Unexpanded, 1, |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7236 | ShouldExpand, RetainExpansion, |
| 7237 | NumExpansions)) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7238 | return ExprError(); |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7239 | |
Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 7240 | if (!ShouldExpand || RetainExpansion) |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7241 | return SemaRef.Owned(E); |
| 7242 | |
| 7243 | // We now know the length of the parameter pack, so build a new expression |
| 7244 | // that stores that length. |
| 7245 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 7246 | E->getPackLoc(), E->getRParenLoc(), |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 7247 | *NumExpansions); |
Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 7248 | } |
| 7249 | |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 7250 | template<typename Derived> |
| 7251 | ExprResult |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 7252 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 7253 | SubstNonTypeTemplateParmPackExpr *E) { |
| 7254 | // Default behavior is to do nothing with this transformation. |
| 7255 | return SemaRef.Owned(E); |
| 7256 | } |
| 7257 | |
| 7258 | template<typename Derived> |
| 7259 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7260 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7261 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7262 | } |
| 7263 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7264 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7265 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7266 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7267 | TypeSourceInfo *EncodedTypeInfo |
| 7268 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 7269 | if (!EncodedTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7270 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7272 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7273 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7274 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7275 | |
| 7276 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 7277 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7278 | E->getRParenLoc()); |
| 7279 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7281 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7282 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7283 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7284 | // Transform arguments. |
| 7285 | bool ArgChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7286 | ASTOwningVector<Expr*> Args(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7287 | Args.reserve(E->getNumArgs()); |
| 7288 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 7289 | &ArgChanged)) |
| 7290 | return ExprError(); |
| 7291 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7292 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 7293 | // Class message: transform the receiver type. |
| 7294 | TypeSourceInfo *ReceiverTypeInfo |
| 7295 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 7296 | if (!ReceiverTypeInfo) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7297 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7298 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7299 | // If nothing changed, just retain the existing message send. |
| 7300 | if (!getDerived().AlwaysRebuild() && |
| 7301 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7302 | return SemaRef.Owned(E); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7303 | |
| 7304 | // Build a new class message send. |
| 7305 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 7306 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7307 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7308 | E->getMethodDecl(), |
| 7309 | E->getLeftLoc(), |
| 7310 | move_arg(Args), |
| 7311 | E->getRightLoc()); |
| 7312 | } |
| 7313 | |
| 7314 | // Instance message: transform the receiver |
| 7315 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 7316 | "Only class and instance messages may be instantiated"); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7317 | ExprResult Receiver |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7318 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 7319 | if (Receiver.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7320 | return ExprError(); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7321 | |
| 7322 | // If nothing changed, just retain the existing message send. |
| 7323 | if (!getDerived().AlwaysRebuild() && |
| 7324 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7325 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7326 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7327 | // Build a new instance message send. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7328 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7329 | E->getSelector(), |
Argyrios Kyrtzidis | d0039e5 | 2010-12-10 20:08:27 +0000 | [diff] [blame] | 7330 | E->getSelectorLoc(), |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7331 | E->getMethodDecl(), |
| 7332 | E->getLeftLoc(), |
| 7333 | move_arg(Args), |
| 7334 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7335 | } |
| 7336 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7337 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7338 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7339 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7340 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7343 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7344 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7345 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7346 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7347 | } |
| 7348 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7349 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7350 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7351 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7352 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7353 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7354 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7355 | return ExprError(); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7356 | |
| 7357 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7358 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7359 | // If nothing changed, just retain the existing expression. |
| 7360 | if (!getDerived().AlwaysRebuild() && |
| 7361 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7362 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7363 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7364 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7365 | E->getLocation(), |
| 7366 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7367 | } |
| 7368 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7369 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7370 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7371 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7372 | // 'super' and types never change. Property never changes. Just |
| 7373 | // retain the existing expression. |
| 7374 | if (!E->isObjectReceiver()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7375 | return SemaRef.Owned(E); |
Fariborz Jahanian | 681c075 | 2010-10-14 16:04:05 +0000 | [diff] [blame] | 7376 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7377 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7378 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7379 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7380 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7381 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7382 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7383 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 7384 | // If nothing changed, just retain the existing expression. |
| 7385 | if (!getDerived().AlwaysRebuild() && |
| 7386 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7387 | return SemaRef.Owned(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7388 | |
John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 7389 | if (E->isExplicitProperty()) |
| 7390 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7391 | E->getExplicitProperty(), |
| 7392 | E->getLocation()); |
| 7393 | |
| 7394 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 7395 | E->getType(), |
| 7396 | E->getImplicitPropertyGetter(), |
| 7397 | E->getImplicitPropertySetter(), |
| 7398 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7399 | } |
| 7400 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7401 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7402 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7403 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7404 | // Transform the base expression. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7405 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7406 | if (Base.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7407 | return ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7408 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7409 | // If nothing changed, just retain the existing expression. |
| 7410 | if (!getDerived().AlwaysRebuild() && |
| 7411 | Base.get() == E->getBase()) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7412 | return SemaRef.Owned(E); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7413 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7414 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 7415 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7416 | } |
| 7417 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7418 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7419 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7420 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7421 | bool ArgumentChanged = false; |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 7422 | ASTOwningVector<Expr*> SubExprs(SemaRef); |
Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 7423 | SubExprs.reserve(E->getNumSubExprs()); |
| 7424 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 7425 | SubExprs, &ArgumentChanged)) |
| 7426 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7428 | if (!getDerived().AlwaysRebuild() && |
| 7429 | !ArgumentChanged) |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7430 | return SemaRef.Owned(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7431 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7432 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 7433 | move_arg(SubExprs), |
| 7434 | E->getRParenLoc()); |
| 7435 | } |
| 7436 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7437 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7438 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7439 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7440 | BlockDecl *oldBlock = E->getBlockDecl(); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7441 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7442 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); |
| 7443 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 7444 | |
| 7445 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 7446 | llvm::SmallVector<ParmVarDecl*, 4> params; |
| 7447 | llvm::SmallVector<QualType, 4> paramTypes; |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7448 | |
| 7449 | // Parameter substitution. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7450 | if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), |
| 7451 | oldBlock->param_begin(), |
| 7452 | oldBlock->param_size(), |
| 7453 | 0, paramTypes, ¶ms)) |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7454 | return true; |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7455 | |
| 7456 | const FunctionType *exprFunctionType = E->getFunctionType(); |
| 7457 | QualType exprResultType = exprFunctionType->getResultType(); |
| 7458 | if (!exprResultType.isNull()) { |
| 7459 | if (!exprResultType->isDependentType()) |
| 7460 | blockScope->ReturnType = exprResultType; |
| 7461 | else if (exprResultType != getSema().Context.DependentTy) |
| 7462 | blockScope->ReturnType = getDerived().TransformType(exprResultType); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7463 | } |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7464 | |
| 7465 | // If the return type has not been determined yet, leave it as a dependent |
| 7466 | // type; it'll get set when we process the body. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7467 | if (blockScope->ReturnType.isNull()) |
| 7468 | blockScope->ReturnType = getSema().Context.DependentTy; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7469 | |
| 7470 | // Don't allow returning a objc interface by value. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7471 | if (blockScope->ReturnType->isObjCObjectType()) { |
| 7472 | getSema().Diag(E->getCaretLocation(), |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7473 | diag::err_object_cannot_be_passed_returned_by_value) |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7474 | << 0 << blockScope->ReturnType; |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7475 | return ExprError(); |
| 7476 | } |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7477 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7478 | QualType functionType = getDerived().RebuildFunctionProtoType( |
| 7479 | blockScope->ReturnType, |
| 7480 | paramTypes.data(), |
| 7481 | paramTypes.size(), |
| 7482 | oldBlock->isVariadic(), |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7483 | 0, RQ_None, |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7484 | exprFunctionType->getExtInfo()); |
| 7485 | blockScope->FunctionType = functionType; |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7486 | |
| 7487 | // Set the parameters on the block decl. |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7488 | if (!params.empty()) |
| 7489 | blockScope->TheDecl->setParams(params.data(), params.size()); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7490 | |
| 7491 | // If the return type wasn't explicitly set, it will have been marked as a |
| 7492 | // dependent type (DependentTy); clear out the return type setting so |
| 7493 | // 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] | 7494 | if (blockScope->ReturnType == getSema().Context.DependentTy) |
| 7495 | blockScope->ReturnType = QualType(); |
Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 7496 | |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7497 | // Transform the body |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7498 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 7499 | if (body.isInvalid()) |
John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 7500 | return ExprError(); |
| 7501 | |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7502 | #ifndef NDEBUG |
| 7503 | // In builds with assertions, make sure that we captured everything we |
| 7504 | // captured before. |
| 7505 | |
| 7506 | if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); |
| 7507 | |
| 7508 | for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), |
| 7509 | e = oldBlock->capture_end(); i != e; ++i) { |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7510 | VarDecl *oldCapture = i->getVariable(); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7511 | |
| 7512 | // Ignore parameter packs. |
| 7513 | if (isa<ParmVarDecl>(oldCapture) && |
| 7514 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 7515 | continue; |
| 7516 | |
| 7517 | VarDecl *newCapture = |
| 7518 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 7519 | oldCapture)); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 7520 | assert(blockScope->CaptureMap.count(newCapture)); |
John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 7521 | } |
| 7522 | #endif |
| 7523 | |
| 7524 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 7525 | /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7526 | } |
| 7527 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7528 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7529 | ExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 7530 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7531 | ValueDecl *ND |
| 7532 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 7533 | E->getDecl())); |
| 7534 | if (!ND) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7535 | return ExprError(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7536 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7537 | if (!getDerived().AlwaysRebuild() && |
| 7538 | ND == E->getDecl()) { |
| 7539 | // Mark it referenced in the new context regardless. |
| 7540 | // FIXME: this is a bit instantiation-specific. |
| 7541 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 7542 | |
John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7543 | return SemaRef.Owned(E); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 7544 | } |
| 7545 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7546 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 7547 | return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7548 | ND, NameInfo, 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7549 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7550 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7551 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7552 | // Type reconstruction |
| 7553 | //===----------------------------------------------------------------------===// |
| 7554 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7555 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7556 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 7557 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7558 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7559 | getDerived().getBaseEntity()); |
| 7560 | } |
| 7561 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7562 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7563 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 7564 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7565 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7566 | getDerived().getBaseEntity()); |
| 7567 | } |
| 7568 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7569 | template<typename Derived> |
| 7570 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7571 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 7572 | bool WrittenAsLValue, |
| 7573 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7574 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7575 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7576 | } |
| 7577 | |
| 7578 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7579 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7580 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 7581 | QualType ClassType, |
| 7582 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 7583 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7584 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7585 | } |
| 7586 | |
| 7587 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7588 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7589 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 7590 | ArrayType::ArraySizeModifier SizeMod, |
| 7591 | const llvm::APInt *Size, |
| 7592 | Expr *SizeExpr, |
| 7593 | unsigned IndexTypeQuals, |
| 7594 | SourceRange BracketsRange) { |
| 7595 | if (SizeExpr || !Size) |
| 7596 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 7597 | IndexTypeQuals, BracketsRange, |
| 7598 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7599 | |
| 7600 | QualType Types[] = { |
| 7601 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 7602 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 7603 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7604 | }; |
| 7605 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 7606 | QualType SizeType; |
| 7607 | for (unsigned I = 0; I != NumTypes; ++I) |
| 7608 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 7609 | SizeType = Types[I]; |
| 7610 | break; |
| 7611 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7612 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7613 | IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, |
| 7614 | /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7615 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7616 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7617 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7618 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7619 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7620 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7621 | QualType |
| 7622 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7623 | ArrayType::ArraySizeModifier SizeMod, |
| 7624 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7625 | unsigned IndexTypeQuals, |
| 7626 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7627 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7628 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7629 | } |
| 7630 | |
| 7631 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7632 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7633 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7634 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7635 | unsigned IndexTypeQuals, |
| 7636 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7637 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 7638 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7639 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7640 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7641 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7642 | QualType |
| 7643 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7644 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7645 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7646 | unsigned IndexTypeQuals, |
| 7647 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7648 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7649 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7650 | IndexTypeQuals, BracketsRange); |
| 7651 | } |
| 7652 | |
| 7653 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7654 | QualType |
| 7655 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7656 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7657 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7658 | unsigned IndexTypeQuals, |
| 7659 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7660 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7661 | SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7662 | IndexTypeQuals, BracketsRange); |
| 7663 | } |
| 7664 | |
| 7665 | template<typename Derived> |
| 7666 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7667 | unsigned NumElements, |
| 7668 | VectorType::VectorKind VecKind) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7669 | // FIXME: semantic checking! |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 7670 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7672 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7673 | template<typename Derived> |
| 7674 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 7675 | unsigned NumElements, |
| 7676 | SourceLocation AttributeLoc) { |
| 7677 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 7678 | NumElements, true); |
| 7679 | IntegerLiteral *VectorSize |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 7680 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 7681 | AttributeLoc); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7682 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7683 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7684 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7685 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7686 | QualType |
| 7687 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7688 | Expr *SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7689 | SourceLocation AttributeLoc) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7690 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7692 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7693 | template<typename Derived> |
| 7694 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7695 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7696 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7697 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7698 | unsigned Quals, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7699 | RefQualifierKind RefQualifier, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7700 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7701 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 7702 | Quals, RefQualifier, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7703 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 7704 | getDerived().getBaseEntity(), |
| 7705 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7706 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7707 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7708 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 7709 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 7710 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 7711 | } |
| 7712 | |
| 7713 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7714 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 7715 | assert(D && "no decl found"); |
| 7716 | if (D->isInvalidDecl()) return QualType(); |
| 7717 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 7718 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7719 | TypeDecl *Ty; |
| 7720 | if (isa<UsingDecl>(D)) { |
| 7721 | UsingDecl *Using = cast<UsingDecl>(D); |
| 7722 | assert(Using->isTypeName() && |
| 7723 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 7724 | |
| 7725 | // A valid resolved using typename decl points to exactly one type decl. |
| 7726 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 7727 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7728 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 7729 | } else { |
| 7730 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 7731 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 7732 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 7733 | } |
| 7734 | |
| 7735 | return SemaRef.Context.getTypeDeclType(Ty); |
| 7736 | } |
| 7737 | |
| 7738 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7739 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 7740 | SourceLocation Loc) { |
| 7741 | return SemaRef.BuildTypeofExprType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7742 | } |
| 7743 | |
| 7744 | template<typename Derived> |
| 7745 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 7746 | return SemaRef.Context.getTypeOfType(Underlying); |
| 7747 | } |
| 7748 | |
| 7749 | template<typename Derived> |
John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 7750 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 7751 | SourceLocation Loc) { |
| 7752 | return SemaRef.BuildDecltypeType(E, Loc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7753 | } |
| 7754 | |
| 7755 | template<typename Derived> |
| 7756 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 7757 | TemplateName Template, |
| 7758 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7759 | const TemplateArgumentListInfo &TemplateArgs) { |
| 7760 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7762 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7763 | template<typename Derived> |
| 7764 | NestedNameSpecifier * |
| 7765 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7766 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 7767 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 7768 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 7769 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7770 | CXXScopeSpec SS; |
| 7771 | // FIXME: The source location information is all wrong. |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 7772 | SS.MakeTrivial(SemaRef.Context, Prefix, Range); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 7773 | if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(), |
| 7774 | /*FIXME:*/Range.getEnd(), |
| 7775 | ObjectType, false, |
| 7776 | SS, FirstQualifierInScope, |
| 7777 | false)) |
| 7778 | return 0; |
| 7779 | |
| 7780 | return SS.getScopeRep(); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7781 | } |
| 7782 | |
| 7783 | template<typename Derived> |
| 7784 | NestedNameSpecifier * |
| 7785 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7786 | SourceRange Range, |
| 7787 | NamespaceDecl *NS) { |
| 7788 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 7789 | } |
| 7790 | |
| 7791 | template<typename Derived> |
| 7792 | NestedNameSpecifier * |
| 7793 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7794 | SourceRange Range, |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 7795 | NamespaceAliasDecl *Alias) { |
| 7796 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias); |
| 7797 | } |
| 7798 | |
| 7799 | template<typename Derived> |
| 7800 | NestedNameSpecifier * |
| 7801 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 7802 | SourceRange Range, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7803 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 7804 | QualType T) { |
| 7805 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7806 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 7807 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7808 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 7809 | T.getTypePtr()); |
| 7810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7811 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 7812 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 7813 | return 0; |
| 7814 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7815 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7816 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7817 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7818 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7819 | bool TemplateKW, |
| 7820 | TemplateDecl *Template) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7821 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7822 | Template); |
| 7823 | } |
| 7824 | |
| 7825 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7826 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7827 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 7828 | const IdentifierInfo &Name, |
| 7829 | SourceLocation NameLoc, |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7830 | QualType ObjectType, |
| 7831 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7832 | UnqualifiedId TemplateName; |
| 7833 | TemplateName.setIdentifier(&Name, NameLoc); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7834 | Sema::TemplateTy Template; |
| 7835 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7836 | /*FIXME:*/SourceLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7837 | SS, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7838 | TemplateName, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7839 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7840 | /*EnteringContext=*/false, |
| 7841 | Template); |
John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 7842 | return Template.get(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 7843 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7844 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7845 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7846 | TemplateName |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7847 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7848 | OverloadedOperatorKind Operator, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7849 | SourceLocation NameLoc, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7850 | QualType ObjectType) { |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7851 | UnqualifiedId Name; |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7852 | // FIXME: Bogus location information. |
| 7853 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| 7854 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7855 | Sema::TemplateTy Template; |
| 7856 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 7857 | /*FIXME:*/SourceLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7858 | SS, |
| 7859 | Name, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 7860 | ParsedType::make(ObjectType), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 7861 | /*EnteringContext=*/false, |
| 7862 | Template); |
| 7863 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7864 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7865 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 7866 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7867 | ExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7868 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 7869 | SourceLocation OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7870 | Expr *OrigCallee, |
| 7871 | Expr *First, |
| 7872 | Expr *Second) { |
| 7873 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 7874 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7875 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7876 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7877 | if (Op == OO_Subscript) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7878 | if (!First->getType()->isOverloadableType() && |
| 7879 | !Second->getType()->isOverloadableType()) |
| 7880 | return getSema().CreateBuiltinArraySubscriptExpr(First, |
| 7881 | Callee->getLocStart(), |
| 7882 | Second, OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 7883 | } else if (Op == OO_Arrow) { |
| 7884 | // -> is never a builtin operation. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7885 | return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); |
| 7886 | } else if (Second == 0 || isPostIncDec) { |
| 7887 | if (!First->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7888 | // The argument is not of overloadable type, so try to create a |
| 7889 | // built-in unary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7890 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7891 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7892 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7893 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7894 | } |
| 7895 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7896 | if (!First->getType()->isOverloadableType() && |
| 7897 | !Second->getType()->isOverloadableType()) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7898 | // Neither of the arguments is an overloadable type, so try to |
| 7899 | // create a built-in binary operation. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7900 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7901 | ExprResult Result |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7902 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7903 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7904 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7905 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7906 | return move(Result); |
| 7907 | } |
| 7908 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7909 | |
| 7910 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7911 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7912 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7913 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7914 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7915 | assert(ULE->requiresADL()); |
| 7916 | |
| 7917 | // FIXME: Do we have to check |
| 7918 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 7919 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7920 | } else { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7921 | Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7922 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7923 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7924 | // Add any functions found via argument-dependent lookup. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7925 | Expr *Args[2] = { First, Second }; |
| 7926 | unsigned NumArgs = 1 + (Second != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7928 | // Create the overloaded operator invocation for unary operators. |
| 7929 | if (NumArgs == 1 || isPostIncDec) { |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7930 | UnaryOperatorKind Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7931 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7932 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7933 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7934 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7935 | if (Op == OO_Subscript) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7936 | return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 7937 | OpLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7938 | First, |
| 7939 | Second); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 7940 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7941 | // Create the overloaded operator invocation for binary operators. |
John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 7942 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7943 | ExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7944 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 7945 | if (Result.isInvalid()) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7946 | return ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7947 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7948 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 7949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7950 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7951 | template<typename Derived> |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7952 | ExprResult |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7953 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7954 | SourceLocation OperatorLoc, |
| 7955 | bool isArrow, |
Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 7956 | CXXScopeSpec &SS, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7957 | TypeSourceInfo *ScopeType, |
| 7958 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7959 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7960 | PseudoDestructorTypeStorage Destroyed) { |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7961 | QualType BaseType = Base->getType(); |
| 7962 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7963 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 7964 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 7965 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 7966 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7967 | // This pseudo-destructor expression is still a pseudo-destructor. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7968 | return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7969 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 7970 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7971 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7972 | /*FIXME?*/true); |
| 7973 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7974 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 7975 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7976 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 7977 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 7978 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 7979 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 7980 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7981 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7982 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7983 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7984 | OperatorLoc, isArrow, |
| 7985 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 7986 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 7987 | /*TemplateArgs*/ 0); |
| 7988 | } |
| 7989 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7990 | } // end namespace clang |
| 7991 | |
| 7992 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |