John McCall | 550e0c2 | 2009-10-21 00:40:46 +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. |
| 7 | //===----------------------------------------------------------------------===/ |
| 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 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "Sema.h" |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 23 | #include "clang/AST/Stmt.h" |
| 24 | #include "clang/AST/StmtCXX.h" |
| 25 | #include "clang/AST/StmtObjC.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 27 | #include "clang/Parse/Ownership.h" |
| 28 | #include "clang/Parse/Designator.h" |
| 29 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | /// \brief A semantic tree transformation that allows one to transform one |
| 36 | /// abstract syntax tree into another. |
| 37 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 39 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 40 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 41 | /// instantiation is implemented as a tree transformation where the |
| 42 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 43 | /// template arguments for their corresponding template parameters; a similar |
| 44 | /// transformation is performed for non-type template parameters and |
| 45 | /// template template parameters. |
| 46 | /// |
| 47 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// override any of the transformation or rebuild operators by providing an |
| 50 | /// operation with the same signature as the default implementation. The |
| 51 | /// overridding function should not be virtual. |
| 52 | /// |
| 53 | /// Semantic tree transformations are split into two stages, either of which |
| 54 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 55 | /// or the parts of an AST node using the various transformation functions, |
| 56 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 57 | /// node of the appropriate kind from the pieces. The default transformation |
| 58 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 59 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 60 | /// were changed by the transformation, invokes the rebuild operation to create |
| 61 | /// a new AST node. |
| 62 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 65 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 66 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 67 | /// new implementations. |
| 68 | /// |
| 69 | /// For more fine-grained transformations, subclasses can replace any of the |
| 70 | /// \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] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 75 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 76 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 77 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 78 | /// be able to use more efficient rebuild steps. |
| 79 | /// |
| 80 | /// 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] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 83 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 84 | /// default locations and entity names used for type-checking |
| 85 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 92 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 93 | typedef Sema::OwningExprResult OwningExprResult; |
| 94 | typedef Sema::StmtArg StmtArg; |
| 95 | typedef Sema::ExprArg ExprArg; |
| 96 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 103 | /// \brief Retrieves a reference to the derived class. |
| 104 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 105 | |
| 106 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 112 | /// this tree transform. |
| 113 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 115 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 116 | /// if none of the children have changed. |
| 117 | /// |
| 118 | /// Subclasses may override this function to specify when the transformation |
| 119 | /// should rebuild all AST nodes. |
| 120 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Returns the location of the entity being transformed, if that |
| 123 | /// information was not available elsewhere in the AST. |
| 124 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 126 | /// provide an alternative implementation that provides better location |
| 127 | /// information. |
| 128 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | /// \brief Returns the name of the entity being transformed, if that |
| 131 | /// information was not available elsewhere in the AST. |
| 132 | /// |
| 133 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 134 | /// implementation with a more precise name. |
| 135 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 137 | /// \brief Sets the "base" location and entity when that |
| 138 | /// information is known based on another transformation. |
| 139 | /// |
| 140 | /// By default, the source location and entity are ignored. Subclasses can |
| 141 | /// override this function to provide a customized implementation. |
| 142 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 144 | /// \brief RAII object that temporarily sets the base location and entity |
| 145 | /// used for reporting diagnostics in types. |
| 146 | class TemporaryBase { |
| 147 | TreeTransform &Self; |
| 148 | SourceLocation OldLocation; |
| 149 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | OldLocation = Self.getDerived().getBaseLocation(); |
| 155 | OldEntity = Self.getDerived().getBaseEntity(); |
| 156 | Self.getDerived().setBase(Location, Entity); |
| 157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | /// 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] | 169 | /// not change. For example, template instantiation need not traverse |
| 170 | /// non-dependent types. |
| 171 | bool AlreadyTransformed(QualType T) { |
| 172 | return T.isNull(); |
| 173 | } |
| 174 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 175 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 176 | /// because it is a default argument. |
| 177 | /// |
| 178 | /// Subclasses can provide an alternative implementation of this routine to |
| 179 | /// determine which kinds of call arguments get dropped. By default, |
| 180 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 181 | bool DropCallArgument(Expr *E) { |
| 182 | return E->isDefaultArgument(); |
| 183 | } |
| 184 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 189 | /// function. This is expensive, but we don't mind, because |
| 190 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 194 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 196 | /// \brief Transforms the given type-with-location into a new |
| 197 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 199 | /// By default, this routine transforms a type by delegating to the |
| 200 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 201 | /// may override this function (to take over all type |
| 202 | /// transformations) or some set of the TransformXXXType functions |
| 203 | /// to alter the transformation. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
| 205 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 206 | |
| 207 | /// \brief Transform the given type-with-location into a new |
| 208 | /// type, collecting location information in the given builder |
| 209 | /// as necessary. |
| 210 | /// |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
| 212 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 217 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 218 | /// statement or the TransformExpr() function to transform an expression. |
| 219 | /// Subclasses may override this function to transform statements using some |
| 220 | /// other mechanism. |
| 221 | /// |
| 222 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 227 | /// By default, this routine transforms an expression by delegating to the |
| 228 | /// appropriate TransformXXXExpr function to build a new expression. |
| 229 | /// Subclasses may override this function to transform expressions using some |
| 230 | /// other mechanism. |
| 231 | /// |
| 232 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 235 | /// \brief Transform the given declaration, which is referenced from a type |
| 236 | /// or expression. |
| 237 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 238 | /// By default, acts as the identity function on declarations. Subclasses |
| 239 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 240 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 247 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 250 | /// \brief Transform the given declaration, which was the first part of a |
| 251 | /// nested-name-specifier in a member access expression. |
| 252 | /// |
| 253 | /// This specific declaration transformation only applies to the first |
| 254 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 255 | /// the \c T in \c x->T::member |
| 256 | /// |
| 257 | /// By default, invokes TransformDecl() to transform the declaration. |
| 258 | /// Subclasses may override this function to provide alternate behavior. |
| 259 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 266 | /// nested-name-specifier. Subclasses may override this function to provide |
| 267 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 273 | /// \brief Transform the given declaration name. |
| 274 | /// |
| 275 | /// By default, transforms the types of conversion function, constructor, |
| 276 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 277 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 278 | /// override this function to provide alternate behavior. |
| 279 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | /// By default, this operation transforms the type, expression, or |
| 294 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 295 | /// new template argument from the transformed result. Subclasses may |
| 296 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 297 | /// |
| 298 | /// Returns true if there was an error. |
| 299 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 300 | TemplateArgumentLoc &Output); |
| 301 | |
| 302 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 303 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 304 | TemplateArgumentLoc &ArgLoc); |
| 305 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 306 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 307 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 308 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 314 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 315 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 318 | /// \brief Transforms the parameters of a function type into the |
| 319 | /// given vectors. |
| 320 | /// |
| 321 | /// The result vectors should be kept in sync; null entries in the |
| 322 | /// variables vector are acceptable. |
| 323 | /// |
| 324 | /// Return true on error. |
| 325 | bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 326 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 327 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars); |
| 328 | |
| 329 | /// \brief Transforms a single function-type parameter. Return null |
| 330 | /// on error. |
| 331 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); |
| 332 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 334 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 336 | QualType |
| 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | 105dfb5 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 347 | #define ABSTRACT_EXPR(Node, Parent) |
| 348 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Build a new pointer type given its pointee type. |
| 351 | /// |
| 352 | /// By default, performs semantic analysis when building the pointer type. |
| 353 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | |
| 356 | /// \brief Build a new block pointer type given its pointee type. |
| 357 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | /// By default, performs semantic analysis when building the |
| 365 | /// reference type. Subclasses may override this routine to provide |
| 366 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | /// \param LValue whether the type was written with an lvalue sigil |
| 369 | /// or an rvalue sigil. |
| 370 | QualType RebuildReferenceType(QualType ReferentType, |
| 371 | bool LValue, |
| 372 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 374 | /// \brief Build a new member pointer type given the pointee type and the |
| 375 | /// class type it refers into. |
| 376 | /// |
| 377 | /// By default, performs semantic analysis when building the member pointer |
| 378 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | /// \brief Build a new array type given the element type, size |
| 383 | /// modifier, size of the array (if known), size expression, and index type |
| 384 | /// qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | QualType RebuildArrayType(QualType ElementType, |
| 390 | ArrayType::ArraySizeModifier SizeMod, |
| 391 | const llvm::APInt *Size, |
| 392 | Expr *SizeExpr, |
| 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new constant array type given the element type, size |
| 397 | /// modifier, (known) size of the array, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// \brief Build a new incomplete array type given the element type, size |
| 408 | /// modifier, and index type qualifiers. |
| 409 | /// |
| 410 | /// By default, performs semantic analysis when building the array type. |
| 411 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 429 | /// size modifier, size expression, and index type qualifiers. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the array type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | unsigned IndexTypeQuals, |
| 437 | SourceRange BracketsRange); |
| 438 | |
| 439 | /// \brief Build a new vector type given the element type and |
| 440 | /// number of elements. |
| 441 | /// |
| 442 | /// By default, performs semantic analysis when building the vector type. |
| 443 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Build a new extended vector type given the element type and |
| 448 | /// number of elements. |
| 449 | /// |
| 450 | /// By default, performs semantic analysis when building the vector type. |
| 451 | /// Subclasses may override this routine to provide different behavior. |
| 452 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 453 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// given the element type and number of elements. |
| 457 | /// |
| 458 | /// By default, performs semantic analysis when building the vector type. |
| 459 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new function type. |
| 465 | /// |
| 466 | /// By default, performs semantic analysis when building the function type. |
| 467 | /// Subclasses may override this routine to provide different behavior. |
| 468 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 473 | /// \brief Build a new unprototyped function type. |
| 474 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 475 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 476 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 477 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 478 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 479 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Build a new typedef type. |
| 481 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 482 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 483 | } |
| 484 | |
| 485 | /// \brief Build a new class/struct/union type. |
| 486 | QualType RebuildRecordType(RecordDecl *Record) { |
| 487 | return SemaRef.Context.getTypeDeclType(Record); |
| 488 | } |
| 489 | |
| 490 | /// \brief Build a new Enum type. |
| 491 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 492 | return SemaRef.Context.getTypeDeclType(Enum); |
| 493 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 494 | |
| 495 | /// \brief Build a new elaborated type. |
| 496 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 497 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
| 500 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | /// |
| 502 | /// By default, performs semantic analysis when building the typeof type. |
| 503 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 504 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, builds a new TypeOfType with the given underlying type. |
| 509 | QualType RebuildTypeOfType(QualType Underlying); |
| 510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// |
| 513 | /// By default, performs semantic analysis when building the decltype type. |
| 514 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 515 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// \brief Build a new template specialization type. |
| 518 | /// |
| 519 | /// By default, performs semantic analysis when building the template |
| 520 | /// specialization type. Subclasses may override this routine to provide |
| 521 | /// different behavior. |
| 522 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 524 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// \brief Build a new qualified name type. |
| 527 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | /// By default, builds a new QualifiedNameType type from the |
| 529 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | /// this routine to provide different behavior. |
| 531 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 532 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | |
| 535 | /// \brief Build a new typename type that refers to a template-id. |
| 536 | /// |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 537 | /// By default, builds a new DependentNameType type from the |
| 538 | /// nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 541 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 542 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 543 | if (NNS->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 544 | // If the name is still dependent, just build a new dependent name type. |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 548 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 552 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 555 | |
| 556 | /// \brief Build a new typename type that refers to an identifier. |
| 557 | /// |
| 558 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 561 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 562 | NestedNameSpecifier *NNS, |
| 563 | const IdentifierInfo *Id, |
| 564 | SourceRange SR) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 565 | CXXScopeSpec SS; |
| 566 | SS.setScopeRep(NNS); |
| 567 | |
| 568 | if (NNS->isDependent()) { |
| 569 | // If the name is still dependent, just build a new dependent name type. |
| 570 | if (!SemaRef.computeDeclContext(SS)) |
| 571 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 572 | } |
| 573 | |
| 574 | TagDecl::TagKind Kind = TagDecl::TK_enum; |
| 575 | switch (Keyword) { |
| 576 | case ETK_None: |
| 577 | // FIXME: Note the lack of the "typename" specifier! |
| 578 | // Fall through |
| 579 | case ETK_Typename: |
| 580 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
| 581 | |
| 582 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 583 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 584 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 585 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 586 | } |
| 587 | |
| 588 | // We had a dependent elaborated-type-specifier that as been transformed |
| 589 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 590 | // referring to. |
| 591 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 592 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 593 | if (!DC) |
| 594 | return QualType(); |
| 595 | |
| 596 | TagDecl *Tag = 0; |
| 597 | SemaRef.LookupQualifiedName(Result, DC); |
| 598 | switch (Result.getResultKind()) { |
| 599 | case LookupResult::NotFound: |
| 600 | case LookupResult::NotFoundInCurrentInstantiation: |
| 601 | break; |
| 602 | |
| 603 | case LookupResult::Found: |
| 604 | Tag = Result.getAsSingle<TagDecl>(); |
| 605 | break; |
| 606 | |
| 607 | case LookupResult::FoundOverloaded: |
| 608 | case LookupResult::FoundUnresolvedValue: |
| 609 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 610 | return QualType(); |
| 611 | |
| 612 | case LookupResult::Ambiguous: |
| 613 | // Let the LookupResult structure handle ambiguities. |
| 614 | return QualType(); |
| 615 | } |
| 616 | |
| 617 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 618 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 619 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 620 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 621 | return QualType(); |
| 622 | } |
| 623 | |
| 624 | // FIXME: Terrible location information |
| 625 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 626 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 627 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 628 | return QualType(); |
| 629 | } |
| 630 | |
| 631 | // Build the elaborated-type-specifier type. |
| 632 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 633 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 634 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 637 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 638 | /// identifier that names the next step in the nested-name-specifier. |
| 639 | /// |
| 640 | /// By default, performs semantic analysis when building the new |
| 641 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 642 | /// different behavior. |
| 643 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 644 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 645 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 646 | QualType ObjectType, |
| 647 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 648 | |
| 649 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 650 | /// namespace named in the next step in the nested-name-specifier. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the new |
| 653 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 654 | /// different behavior. |
| 655 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 656 | SourceRange Range, |
| 657 | NamespaceDecl *NS); |
| 658 | |
| 659 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 660 | /// type named in the next step in the nested-name-specifier. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis when building the new |
| 663 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 664 | /// different behavior. |
| 665 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 666 | SourceRange Range, |
| 667 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 668 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 669 | |
| 670 | /// \brief Build a new template name given a nested name specifier, a flag |
| 671 | /// indicating whether the "template" keyword was provided, and the template |
| 672 | /// that the template name refers to. |
| 673 | /// |
| 674 | /// By default, builds the new template name directly. Subclasses may override |
| 675 | /// this routine to provide different behavior. |
| 676 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 677 | bool TemplateKW, |
| 678 | TemplateDecl *Template); |
| 679 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 680 | /// \brief Build a new template name given a nested name specifier and the |
| 681 | /// name that is referred to as a template. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis to determine whether the name can |
| 684 | /// be resolved to a specific template, then builds the appropriate kind of |
| 685 | /// template name. Subclasses may override this routine to provide different |
| 686 | /// behavior. |
| 687 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 688 | const IdentifierInfo &II, |
| 689 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 691 | /// \brief Build a new template name given a nested name specifier and the |
| 692 | /// overloaded operator name that is referred to as a template. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis to determine whether the name can |
| 695 | /// be resolved to a specific template, then builds the appropriate kind of |
| 696 | /// template name. Subclasses may override this routine to provide different |
| 697 | /// behavior. |
| 698 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 699 | OverloadedOperatorKind Operator, |
| 700 | QualType ObjectType); |
| 701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 702 | /// \brief Build a new compound statement. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis to build the new statement. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 707 | MultiStmtArg Statements, |
| 708 | SourceLocation RBraceLoc, |
| 709 | bool IsStmtExpr) { |
| 710 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 711 | IsStmtExpr); |
| 712 | } |
| 713 | |
| 714 | /// \brief Build a new case statement. |
| 715 | /// |
| 716 | /// By default, performs semantic analysis to build the new statement. |
| 717 | /// Subclasses may override this routine to provide different behavior. |
| 718 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 719 | ExprArg LHS, |
| 720 | SourceLocation EllipsisLoc, |
| 721 | ExprArg RHS, |
| 722 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | ColonLoc); |
| 725 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | /// \brief Attach the body to a new case statement. |
| 728 | /// |
| 729 | /// By default, performs semantic analysis to build the new statement. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
| 731 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 732 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 733 | return move(S); |
| 734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | /// \brief Build a new default statement. |
| 737 | /// |
| 738 | /// By default, performs semantic analysis to build the new statement. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | SourceLocation ColonLoc, |
| 742 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 744 | /*CurScope=*/0); |
| 745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | /// \brief Build a new label statement. |
| 748 | /// |
| 749 | /// By default, performs semantic analysis to build the new statement. |
| 750 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | IdentifierInfo *Id, |
| 753 | SourceLocation ColonLoc, |
| 754 | StmtArg SubStmt) { |
| 755 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 756 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | /// \brief Build a new "if" statement. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis to build the new statement. |
| 761 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 763 | VarDecl *CondVar, StmtArg Then, |
| 764 | SourceLocation ElseLoc, StmtArg Else) { |
| 765 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 766 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 769 | /// \brief Start building a new switch statement. |
| 770 | /// |
| 771 | /// By default, performs semantic analysis to build the new statement. |
| 772 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 773 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 774 | VarDecl *CondVar) { |
| 775 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 778 | /// \brief Attach the body to the switch statement. |
| 779 | /// |
| 780 | /// By default, performs semantic analysis to build the new statement. |
| 781 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 783 | StmtArg Switch, StmtArg Body) { |
| 784 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 785 | move(Body)); |
| 786 | } |
| 787 | |
| 788 | /// \brief Build a new while statement. |
| 789 | /// |
| 790 | /// By default, performs semantic analysis to build the new statement. |
| 791 | /// Subclasses may override this routine to provide different behavior. |
| 792 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 793 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 794 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 795 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 796 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 797 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 800 | /// \brief Build a new do-while statement. |
| 801 | /// |
| 802 | /// By default, performs semantic analysis to build the new statement. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
| 804 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 805 | SourceLocation WhileLoc, |
| 806 | SourceLocation LParenLoc, |
| 807 | ExprArg Cond, |
| 808 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 810 | move(Cond), RParenLoc); |
| 811 | } |
| 812 | |
| 813 | /// \brief Build a new for statement. |
| 814 | /// |
| 815 | /// By default, performs semantic analysis to build the new statement. |
| 816 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 819 | StmtArg Init, Sema::FullExprArg Cond, |
| 820 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 821 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 822 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 823 | DeclPtrTy::make(CondVar), |
| 824 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | /// \brief Build a new goto statement. |
| 828 | /// |
| 829 | /// By default, performs semantic analysis to build the new statement. |
| 830 | /// Subclasses may override this routine to provide different behavior. |
| 831 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 832 | SourceLocation LabelLoc, |
| 833 | LabelStmt *Label) { |
| 834 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 835 | } |
| 836 | |
| 837 | /// \brief Build a new indirect goto statement. |
| 838 | /// |
| 839 | /// By default, performs semantic analysis to build the new statement. |
| 840 | /// Subclasses may override this routine to provide different behavior. |
| 841 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 842 | SourceLocation StarLoc, |
| 843 | ExprArg Target) { |
| 844 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 847 | /// \brief Build a new return statement. |
| 848 | /// |
| 849 | /// By default, performs semantic analysis to build the new statement. |
| 850 | /// Subclasses may override this routine to provide different behavior. |
| 851 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 852 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 854 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 857 | /// \brief Build a new declaration statement. |
| 858 | /// |
| 859 | /// By default, performs semantic analysis to build the new statement. |
| 860 | /// Subclasses may override this routine to provide different behavior. |
| 861 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 863 | SourceLocation EndLoc) { |
| 864 | return getSema().Owned( |
| 865 | new (getSema().Context) DeclStmt( |
| 866 | DeclGroupRef::Create(getSema().Context, |
| 867 | Decls, NumDecls), |
| 868 | StartLoc, EndLoc)); |
| 869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 871 | /// \brief Build a new inline asm statement. |
| 872 | /// |
| 873 | /// By default, performs semantic analysis to build the new statement. |
| 874 | /// Subclasses may override this routine to provide different behavior. |
| 875 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 876 | bool IsSimple, |
| 877 | bool IsVolatile, |
| 878 | unsigned NumOutputs, |
| 879 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 880 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 881 | MultiExprArg Constraints, |
| 882 | MultiExprArg Exprs, |
| 883 | ExprArg AsmString, |
| 884 | MultiExprArg Clobbers, |
| 885 | SourceLocation RParenLoc, |
| 886 | bool MSAsm) { |
| 887 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 888 | NumInputs, Names, move(Constraints), |
| 889 | move(Exprs), move(AsmString), move(Clobbers), |
| 890 | RParenLoc, MSAsm); |
| 891 | } |
| 892 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 893 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 894 | /// |
| 895 | /// By default, performs semantic analysis to build the new statement. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
| 897 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 898 | ExprArg Operand) { |
| 899 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 900 | } |
| 901 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 902 | /// \brief Build a new Objective-C @synchronized statement. |
| 903 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 904 | /// By default, performs semantic analysis to build the new statement. |
| 905 | /// Subclasses may override this routine to provide different behavior. |
| 906 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 907 | ExprArg Object, |
| 908 | StmtArg Body) { |
| 909 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 910 | move(Body)); |
| 911 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame^] | 912 | |
| 913 | /// \brief Build a new Objective-C fast enumeration statement. |
| 914 | /// |
| 915 | /// By default, performs semantic analysis to build the new statement. |
| 916 | /// Subclasses may override this routine to provide different behavior. |
| 917 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 918 | SourceLocation LParenLoc, |
| 919 | StmtArg Element, |
| 920 | ExprArg Collection, |
| 921 | SourceLocation RParenLoc, |
| 922 | StmtArg Body) { |
| 923 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
| 924 | move(Element), |
| 925 | move(Collection), |
| 926 | RParenLoc, |
| 927 | move(Body)); |
| 928 | } |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 930 | /// \brief Build a new C++ exception declaration. |
| 931 | /// |
| 932 | /// By default, performs semantic analysis to build the new decaration. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 935 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 936 | IdentifierInfo *Name, |
| 937 | SourceLocation Loc, |
| 938 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 940 | TypeRange); |
| 941 | } |
| 942 | |
| 943 | /// \brief Build a new C++ catch statement. |
| 944 | /// |
| 945 | /// By default, performs semantic analysis to build the new statement. |
| 946 | /// Subclasses may override this routine to provide different behavior. |
| 947 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 948 | VarDecl *ExceptionDecl, |
| 949 | StmtArg Handler) { |
| 950 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 952 | Handler.takeAs<Stmt>())); |
| 953 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 955 | /// \brief Build a new C++ try statement. |
| 956 | /// |
| 957 | /// By default, performs semantic analysis to build the new statement. |
| 958 | /// Subclasses may override this routine to provide different behavior. |
| 959 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 960 | StmtArg TryBlock, |
| 961 | MultiStmtArg Handlers) { |
| 962 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 963 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 965 | /// \brief Build a new expression that references a declaration. |
| 966 | /// |
| 967 | /// By default, performs semantic analysis to build the new expression. |
| 968 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 969 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 970 | LookupResult &R, |
| 971 | bool RequiresADL) { |
| 972 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | /// \brief Build a new expression that references a declaration. |
| 977 | /// |
| 978 | /// By default, performs semantic analysis to build the new expression. |
| 979 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 980 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 981 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 982 | ValueDecl *VD, SourceLocation Loc, |
| 983 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 984 | CXXScopeSpec SS; |
| 985 | SS.setScopeRep(Qualifier); |
| 986 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 987 | |
| 988 | // FIXME: loses template args. |
| 989 | |
| 990 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 993 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 995 | /// By default, performs semantic analysis to build the new expression. |
| 996 | /// Subclasses may override this routine to provide different behavior. |
| 997 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 998 | SourceLocation RParen) { |
| 999 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1000 | } |
| 1001 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1002 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1004 | /// By default, performs semantic analysis to build the new expression. |
| 1005 | /// Subclasses may override this routine to provide different behavior. |
| 1006 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1007 | SourceLocation OperatorLoc, |
| 1008 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1009 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1010 | SourceRange QualifierRange, |
| 1011 | TypeSourceInfo *ScopeType, |
| 1012 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1013 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1014 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1018 | /// By default, performs semantic analysis to build the new expression. |
| 1019 | /// Subclasses may override this routine to provide different behavior. |
| 1020 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1021 | UnaryOperator::Opcode Opc, |
| 1022 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1023 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1024 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1026 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1028 | /// By default, performs semantic analysis to build the new expression. |
| 1029 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1030 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1031 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1032 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1033 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
| 1041 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1042 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1044 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1045 | OpLoc, isSizeOf, R); |
| 1046 | if (Result.isInvalid()) |
| 1047 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | SubExpr.release(); |
| 1050 | return move(Result); |
| 1051 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1054 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1055 | /// By default, performs semantic analysis to build the new expression. |
| 1056 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | SourceLocation LBracketLoc, |
| 1059 | ExprArg RHS, |
| 1060 | SourceLocation RBracketLoc) { |
| 1061 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1063 | RBracketLoc); |
| 1064 | } |
| 1065 | |
| 1066 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | /// By default, performs semantic analysis to build the new expression. |
| 1069 | /// Subclasses may override this routine to provide different behavior. |
| 1070 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1071 | MultiExprArg Args, |
| 1072 | SourceLocation *CommaLocs, |
| 1073 | SourceLocation RParenLoc) { |
| 1074 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1075 | move(Args), CommaLocs, RParenLoc); |
| 1076 | } |
| 1077 | |
| 1078 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1080 | /// By default, performs semantic analysis to build the new expression. |
| 1081 | /// Subclasses may override this routine to provide different behavior. |
| 1082 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1084 | NestedNameSpecifier *Qualifier, |
| 1085 | SourceRange QualifierRange, |
| 1086 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1087 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1088 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1089 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1090 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1091 | if (!Member->getDeclName()) { |
| 1092 | // We have a reference to an unnamed field. |
| 1093 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1095 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1096 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1097 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1098 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1099 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1101 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1102 | Member, MemberLoc, |
| 1103 | cast<FieldDecl>(Member)->getType()); |
| 1104 | return getSema().Owned(ME); |
| 1105 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1107 | CXXScopeSpec SS; |
| 1108 | if (Qualifier) { |
| 1109 | SS.setRange(QualifierRange); |
| 1110 | SS.setScopeRep(Qualifier); |
| 1111 | } |
| 1112 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1113 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1114 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1115 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1116 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1117 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1118 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1119 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1120 | R.resolveKind(); |
| 1121 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1122 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1123 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1124 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1125 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1126 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// By default, performs semantic analysis to build the new expression. |
| 1131 | /// Subclasses may override this routine to provide different behavior. |
| 1132 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1133 | BinaryOperator::Opcode Opc, |
| 1134 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1135 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1136 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | /// By default, performs semantic analysis to build the new expression. |
| 1142 | /// Subclasses may override this routine to provide different behavior. |
| 1143 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1144 | SourceLocation QuestionLoc, |
| 1145 | ExprArg LHS, |
| 1146 | SourceLocation ColonLoc, |
| 1147 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1149 | move(LHS), move(RHS)); |
| 1150 | } |
| 1151 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1152 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1154 | /// By default, performs semantic analysis to build the new expression. |
| 1155 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1156 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1157 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | SourceLocation RParenLoc, |
| 1159 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1160 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1161 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1164 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1165 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1166 | /// By default, performs semantic analysis to build the new expression. |
| 1167 | /// Subclasses may override this routine to provide different behavior. |
| 1168 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1169 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1170 | SourceLocation RParenLoc, |
| 1171 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1172 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1173 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1174 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1176 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1178 | /// By default, performs semantic analysis to build the new expression. |
| 1179 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1181 | SourceLocation OpLoc, |
| 1182 | SourceLocation AccessorLoc, |
| 1183 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1184 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1185 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1186 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1187 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1188 | OpLoc, /*IsArrow*/ false, |
| 1189 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1190 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1191 | AccessorLoc, |
| 1192 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1194 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1195 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1197 | /// By default, performs semantic analysis to build the new expression. |
| 1198 | /// Subclasses may override this routine to provide different behavior. |
| 1199 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1200 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1201 | SourceLocation RBraceLoc, |
| 1202 | QualType ResultTy) { |
| 1203 | OwningExprResult Result |
| 1204 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1205 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1206 | return move(Result); |
| 1207 | |
| 1208 | // Patch in the result type we were given, which may have been computed |
| 1209 | // when the initial InitListExpr was built. |
| 1210 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1211 | ILE->setType(ResultTy); |
| 1212 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | /// By default, performs semantic analysis to build the new expression. |
| 1218 | /// Subclasses may override this routine to provide different behavior. |
| 1219 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1220 | MultiExprArg ArrayExprs, |
| 1221 | SourceLocation EqualOrColonLoc, |
| 1222 | bool GNUSyntax, |
| 1223 | ExprArg Init) { |
| 1224 | OwningExprResult Result |
| 1225 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1226 | move(Init)); |
| 1227 | if (Result.isInvalid()) |
| 1228 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | ArrayExprs.release(); |
| 1231 | return move(Result); |
| 1232 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1233 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1234 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | /// By default, builds the implicit value initialization without performing |
| 1237 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1238 | /// different behavior. |
| 1239 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1240 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1241 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | /// By default, performs semantic analysis to build the new expression. |
| 1246 | /// Subclasses may override this routine to provide different behavior. |
| 1247 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1248 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1249 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1250 | RParenLoc); |
| 1251 | } |
| 1252 | |
| 1253 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1255 | /// By default, performs semantic analysis to build the new expression. |
| 1256 | /// Subclasses may override this routine to provide different behavior. |
| 1257 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1258 | MultiExprArg SubExprs, |
| 1259 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1260 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1261 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1262 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1264 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1265 | /// |
| 1266 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1267 | /// rather than attempting to map the label statement itself. |
| 1268 | /// Subclasses may override this routine to provide different behavior. |
| 1269 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1270 | SourceLocation LabelLoc, |
| 1271 | LabelStmt *Label) { |
| 1272 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 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 GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1276 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1277 | /// By default, performs semantic analysis to build the new expression. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
| 1279 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1280 | StmtArg SubStmt, |
| 1281 | SourceLocation RParenLoc) { |
| 1282 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1285 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1286 | /// |
| 1287 | /// By default, performs semantic analysis to build the new expression. |
| 1288 | /// Subclasses may override this routine to provide different behavior. |
| 1289 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1290 | QualType T1, QualType T2, |
| 1291 | SourceLocation RParenLoc) { |
| 1292 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1293 | T1.getAsOpaquePtr(), |
| 1294 | T2.getAsOpaquePtr(), |
| 1295 | RParenLoc); |
| 1296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1298 | /// \brief Build a new __builtin_choose_expr expression. |
| 1299 | /// |
| 1300 | /// By default, performs semantic analysis to build the new expression. |
| 1301 | /// Subclasses may override this routine to provide different behavior. |
| 1302 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1303 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1304 | SourceLocation RParenLoc) { |
| 1305 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1306 | move(Cond), move(LHS), move(RHS), |
| 1307 | RParenLoc); |
| 1308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | /// \brief Build a new overloaded operator call expression. |
| 1311 | /// |
| 1312 | /// By default, performs semantic analysis to build the new expression. |
| 1313 | /// The semantic analysis provides the behavior of template instantiation, |
| 1314 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1317 | /// provide different behavior. |
| 1318 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1319 | SourceLocation OpLoc, |
| 1320 | ExprArg Callee, |
| 1321 | ExprArg First, |
| 1322 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
| 1324 | /// \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] | 1325 | /// reinterpret_cast. |
| 1326 | /// |
| 1327 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1331 | Stmt::StmtClass Class, |
| 1332 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1333 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | SourceLocation RAngleLoc, |
| 1335 | SourceLocation LParenLoc, |
| 1336 | ExprArg SubExpr, |
| 1337 | SourceLocation RParenLoc) { |
| 1338 | switch (Class) { |
| 1339 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1340 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | move(SubExpr), RParenLoc); |
| 1343 | |
| 1344 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1345 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | move(SubExpr), RParenLoc); |
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 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1350 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1351 | RAngleLoc, LParenLoc, |
| 1352 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1356 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | move(SubExpr), RParenLoc); |
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 | default: |
| 1361 | assert(false && "Invalid C++ named cast"); |
| 1362 | break; |
| 1363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | return getSema().ExprError(); |
| 1366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | /// \brief Build a new C++ static_cast expression. |
| 1369 | /// |
| 1370 | /// By default, performs semantic analysis to build the new expression. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
| 1372 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1373 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1374 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | SourceLocation RAngleLoc, |
| 1376 | SourceLocation LParenLoc, |
| 1377 | ExprArg SubExpr, |
| 1378 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1379 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1380 | TInfo, move(SubExpr), |
| 1381 | SourceRange(LAngleLoc, RAngleLoc), |
| 1382 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /// \brief Build a new C++ dynamic_cast expression. |
| 1386 | /// |
| 1387 | /// By default, performs semantic analysis to build the new expression. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
| 1389 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1390 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1391 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | SourceLocation RAngleLoc, |
| 1393 | SourceLocation LParenLoc, |
| 1394 | ExprArg SubExpr, |
| 1395 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1396 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1397 | TInfo, move(SubExpr), |
| 1398 | SourceRange(LAngleLoc, RAngleLoc), |
| 1399 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1403 | /// |
| 1404 | /// By default, performs semantic analysis to build the new expression. |
| 1405 | /// Subclasses may override this routine to provide different behavior. |
| 1406 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1407 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1408 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | SourceLocation RAngleLoc, |
| 1410 | SourceLocation LParenLoc, |
| 1411 | ExprArg SubExpr, |
| 1412 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1413 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1414 | TInfo, move(SubExpr), |
| 1415 | SourceRange(LAngleLoc, RAngleLoc), |
| 1416 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /// \brief Build a new C++ const_cast expression. |
| 1420 | /// |
| 1421 | /// By default, performs semantic analysis to build the new expression. |
| 1422 | /// Subclasses may override this routine to provide different behavior. |
| 1423 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1424 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1425 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | SourceLocation RAngleLoc, |
| 1427 | SourceLocation LParenLoc, |
| 1428 | ExprArg SubExpr, |
| 1429 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1430 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1431 | TInfo, move(SubExpr), |
| 1432 | SourceRange(LAngleLoc, RAngleLoc), |
| 1433 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | /// \brief Build a new C++ functional-style cast expression. |
| 1437 | /// |
| 1438 | /// By default, performs semantic analysis to build the new expression. |
| 1439 | /// Subclasses may override this routine to provide different behavior. |
| 1440 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1441 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1442 | SourceLocation LParenLoc, |
| 1443 | ExprArg SubExpr, |
| 1444 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1445 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1446 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1447 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1449 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | RParenLoc); |
| 1452 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1454 | /// \brief Build a new C++ typeid(type) expression. |
| 1455 | /// |
| 1456 | /// By default, performs semantic analysis to build the new expression. |
| 1457 | /// Subclasses may override this routine to provide different behavior. |
| 1458 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1459 | SourceLocation LParenLoc, |
| 1460 | QualType T, |
| 1461 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1462 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1463 | T.getAsOpaquePtr(), RParenLoc); |
| 1464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1465 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | /// \brief Build a new C++ typeid(expr) expression. |
| 1467 | /// |
| 1468 | /// By default, performs semantic analysis to build the new expression. |
| 1469 | /// Subclasses may override this routine to provide different behavior. |
| 1470 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1471 | SourceLocation LParenLoc, |
| 1472 | ExprArg Operand, |
| 1473 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1476 | RParenLoc); |
| 1477 | if (Result.isInvalid()) |
| 1478 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1479 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1481 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | /// \brief Build a new C++ "this" expression. |
| 1485 | /// |
| 1486 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1487 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1488 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1490 | QualType ThisType, |
| 1491 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1493 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1494 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /// \brief Build a new C++ throw expression. |
| 1498 | /// |
| 1499 | /// By default, performs semantic analysis to build the new expression. |
| 1500 | /// Subclasses may override this routine to provide different behavior. |
| 1501 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1502 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1503 | } |
| 1504 | |
| 1505 | /// \brief Build a new C++ default-argument expression. |
| 1506 | /// |
| 1507 | /// By default, builds a new default-argument expression, which does not |
| 1508 | /// require any semantic analysis. Subclasses may override this routine to |
| 1509 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1510 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1511 | ParmVarDecl *Param) { |
| 1512 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1513 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | /// \brief Build a new C++ zero-initialization expression. |
| 1517 | /// |
| 1518 | /// By default, performs semantic analysis to build the new expression. |
| 1519 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1520 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | SourceLocation LParenLoc, |
| 1522 | QualType T, |
| 1523 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1525 | T.getAsOpaquePtr(), LParenLoc, |
| 1526 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | 0, RParenLoc); |
| 1528 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1529 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | /// \brief Build a new C++ "new" expression. |
| 1531 | /// |
| 1532 | /// By default, performs semantic analysis to build the new expression. |
| 1533 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1534 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1535 | bool UseGlobal, |
| 1536 | SourceLocation PlacementLParen, |
| 1537 | MultiExprArg PlacementArgs, |
| 1538 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1539 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1540 | QualType AllocType, |
| 1541 | SourceLocation TypeLoc, |
| 1542 | SourceRange TypeRange, |
| 1543 | ExprArg ArraySize, |
| 1544 | SourceLocation ConstructorLParen, |
| 1545 | MultiExprArg ConstructorArgs, |
| 1546 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1547 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | PlacementLParen, |
| 1549 | move(PlacementArgs), |
| 1550 | PlacementRParen, |
| 1551 | ParenTypeId, |
| 1552 | AllocType, |
| 1553 | TypeLoc, |
| 1554 | TypeRange, |
| 1555 | move(ArraySize), |
| 1556 | ConstructorLParen, |
| 1557 | move(ConstructorArgs), |
| 1558 | ConstructorRParen); |
| 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++ "delete" expression. |
| 1562 | /// |
| 1563 | /// By default, performs semantic analysis to build the new expression. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
| 1565 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1566 | bool IsGlobalDelete, |
| 1567 | bool IsArrayForm, |
| 1568 | ExprArg Operand) { |
| 1569 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1570 | move(Operand)); |
| 1571 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1573 | /// \brief Build a new unary type trait expression. |
| 1574 | /// |
| 1575 | /// By default, performs semantic analysis to build the new expression. |
| 1576 | /// Subclasses may override this routine to provide different behavior. |
| 1577 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1578 | SourceLocation StartLoc, |
| 1579 | SourceLocation LParenLoc, |
| 1580 | QualType T, |
| 1581 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | T.getAsOpaquePtr(), RParenLoc); |
| 1584 | } |
| 1585 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | /// expression. |
| 1588 | /// |
| 1589 | /// By default, performs semantic analysis to build the new expression. |
| 1590 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1591 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1592 | SourceRange QualifierRange, |
| 1593 | DeclarationName Name, |
| 1594 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1595 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1596 | CXXScopeSpec SS; |
| 1597 | SS.setRange(QualifierRange); |
| 1598 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1599 | |
| 1600 | if (TemplateArgs) |
| 1601 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1602 | *TemplateArgs); |
| 1603 | |
| 1604 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | /// \brief Build a new template-id expression. |
| 1608 | /// |
| 1609 | /// By default, performs semantic analysis to build the new expression. |
| 1610 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1611 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1612 | LookupResult &R, |
| 1613 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1614 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1615 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /// \brief Build a new object-construction expression. |
| 1619 | /// |
| 1620 | /// By default, performs semantic analysis to build the new expression. |
| 1621 | /// Subclasses may override this routine to provide different behavior. |
| 1622 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1623 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1624 | CXXConstructorDecl *Constructor, |
| 1625 | bool IsElidable, |
| 1626 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1627 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1628 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1629 | ConvertedArgs)) |
| 1630 | return getSema().ExprError(); |
| 1631 | |
| 1632 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1633 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /// \brief Build a new object-construction expression. |
| 1637 | /// |
| 1638 | /// By default, performs semantic analysis to build the new expression. |
| 1639 | /// Subclasses may override this routine to provide different behavior. |
| 1640 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1641 | QualType T, |
| 1642 | SourceLocation LParenLoc, |
| 1643 | MultiExprArg Args, |
| 1644 | SourceLocation *Commas, |
| 1645 | SourceLocation RParenLoc) { |
| 1646 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1647 | T.getAsOpaquePtr(), |
| 1648 | LParenLoc, |
| 1649 | move(Args), |
| 1650 | Commas, |
| 1651 | RParenLoc); |
| 1652 | } |
| 1653 | |
| 1654 | /// \brief Build a new object-construction expression. |
| 1655 | /// |
| 1656 | /// By default, performs semantic analysis to build the new expression. |
| 1657 | /// Subclasses may override this routine to provide different behavior. |
| 1658 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1659 | QualType T, |
| 1660 | SourceLocation LParenLoc, |
| 1661 | MultiExprArg Args, |
| 1662 | SourceLocation *Commas, |
| 1663 | SourceLocation RParenLoc) { |
| 1664 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1665 | /*FIXME*/LParenLoc), |
| 1666 | T.getAsOpaquePtr(), |
| 1667 | LParenLoc, |
| 1668 | move(Args), |
| 1669 | Commas, |
| 1670 | RParenLoc); |
| 1671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1672 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | /// \brief Build a new member reference expression. |
| 1674 | /// |
| 1675 | /// By default, performs semantic analysis to build the new expression. |
| 1676 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1677 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1678 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | bool IsArrow, |
| 1680 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1681 | NestedNameSpecifier *Qualifier, |
| 1682 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1683 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1684 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1685 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1686 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1688 | SS.setRange(QualifierRange); |
| 1689 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1691 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1692 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1693 | SS, FirstQualifierInScope, |
| 1694 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1697 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1698 | /// |
| 1699 | /// By default, performs semantic analysis to build the new expression. |
| 1700 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1701 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1702 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1703 | SourceLocation OperatorLoc, |
| 1704 | bool IsArrow, |
| 1705 | NestedNameSpecifier *Qualifier, |
| 1706 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1707 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1708 | LookupResult &R, |
| 1709 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1710 | CXXScopeSpec SS; |
| 1711 | SS.setRange(QualifierRange); |
| 1712 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1714 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1715 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1716 | SS, FirstQualifierInScope, |
| 1717 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1718 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1720 | /// \brief Build a new Objective-C @encode expression. |
| 1721 | /// |
| 1722 | /// By default, performs semantic analysis to build the new expression. |
| 1723 | /// Subclasses may override this routine to provide different behavior. |
| 1724 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1725 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1727 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1728 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1731 | /// \brief Build a new Objective-C class message. |
| 1732 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1733 | Selector Sel, |
| 1734 | ObjCMethodDecl *Method, |
| 1735 | SourceLocation LBracLoc, |
| 1736 | MultiExprArg Args, |
| 1737 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1738 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1739 | ReceiverTypeInfo->getType(), |
| 1740 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1741 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1742 | move(Args)); |
| 1743 | } |
| 1744 | |
| 1745 | /// \brief Build a new Objective-C instance message. |
| 1746 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1747 | Selector Sel, |
| 1748 | ObjCMethodDecl *Method, |
| 1749 | SourceLocation LBracLoc, |
| 1750 | MultiExprArg Args, |
| 1751 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1752 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1753 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1754 | ReceiverType, |
| 1755 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1756 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1757 | move(Args)); |
| 1758 | } |
| 1759 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1760 | /// \brief Build a new shuffle vector expression. |
| 1761 | /// |
| 1762 | /// By default, performs semantic analysis to build the new expression. |
| 1763 | /// Subclasses may override this routine to provide different behavior. |
| 1764 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1765 | MultiExprArg SubExprs, |
| 1766 | SourceLocation RParenLoc) { |
| 1767 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1770 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1771 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1772 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1774 | // Build a reference to the __builtin_shufflevector builtin |
| 1775 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1777 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1778 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1780 | |
| 1781 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1782 | unsigned NumSubExprs = SubExprs.size(); |
| 1783 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1784 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1785 | Subs, NumSubExprs, |
| 1786 | Builtin->getResultType(), |
| 1787 | RParenLoc); |
| 1788 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | // Type-check the __builtin_shufflevector expression. |
| 1791 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1792 | if (Result.isInvalid()) |
| 1793 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1795 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1798 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1799 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1800 | template<typename Derived> |
| 1801 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1802 | if (!S) |
| 1803 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1805 | switch (S->getStmtClass()) { |
| 1806 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1808 | // Transform individual statement nodes |
| 1809 | #define STMT(Node, Parent) \ |
| 1810 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1811 | #define EXPR(Node, Parent) |
| 1812 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1813 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1814 | // Transform expressions by calling TransformExpr. |
| 1815 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1816 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1817 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1818 | #include "clang/AST/StmtNodes.def" |
| 1819 | { |
| 1820 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1821 | if (E.isInvalid()) |
| 1822 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1824 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1828 | return SemaRef.Owned(S->Retain()); |
| 1829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1830 | |
| 1831 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1832 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1833 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1834 | if (!E) |
| 1835 | return SemaRef.Owned(E); |
| 1836 | |
| 1837 | switch (E->getStmtClass()) { |
| 1838 | case Stmt::NoStmtClass: break; |
| 1839 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1840 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1841 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1842 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1843 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1846 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1850 | NestedNameSpecifier * |
| 1851 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1852 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1853 | QualType ObjectType, |
| 1854 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1855 | if (!NNS) |
| 1856 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1858 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1859 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1860 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1862 | ObjectType, |
| 1863 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1864 | if (!Prefix) |
| 1865 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | |
| 1867 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1868 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1869 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1870 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1871 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1873 | switch (NNS->getKind()) { |
| 1874 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1876 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1877 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1878 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1879 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
| 1881 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1882 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1883 | ObjectType, |
| 1884 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1885 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1886 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1888 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1889 | getDerived().TransformDecl(Range.getBegin(), |
| 1890 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1892 | Prefix == NNS->getPrefix() && |
| 1893 | NS == NNS->getAsNamespace()) |
| 1894 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1895 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1896 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1897 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1899 | case NestedNameSpecifier::Global: |
| 1900 | // There is no meaningful transformation that one could perform on the |
| 1901 | // global scope. |
| 1902 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1903 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1904 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1905 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1906 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1907 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1908 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1909 | if (T.isNull()) |
| 1910 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1911 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1912 | if (!getDerived().AlwaysRebuild() && |
| 1913 | Prefix == NNS->getPrefix() && |
| 1914 | T == QualType(NNS->getAsType(), 0)) |
| 1915 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
| 1917 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1918 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1919 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1920 | } |
| 1921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1922 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1923 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1928 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1929 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1930 | SourceLocation Loc, |
| 1931 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1932 | if (!Name) |
| 1933 | return Name; |
| 1934 | |
| 1935 | switch (Name.getNameKind()) { |
| 1936 | case DeclarationName::Identifier: |
| 1937 | case DeclarationName::ObjCZeroArgSelector: |
| 1938 | case DeclarationName::ObjCOneArgSelector: |
| 1939 | case DeclarationName::ObjCMultiArgSelector: |
| 1940 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1941 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1942 | case DeclarationName::CXXUsingDirective: |
| 1943 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1944 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1945 | case DeclarationName::CXXConstructorName: |
| 1946 | case DeclarationName::CXXDestructorName: |
| 1947 | case DeclarationName::CXXConversionFunctionName: { |
| 1948 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1949 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1950 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1951 | if (T.isNull()) |
| 1952 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1954 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1955 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1956 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1957 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1960 | return DeclarationName(); |
| 1961 | } |
| 1962 | |
| 1963 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1964 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1965 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1966 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1967 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1968 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1969 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1970 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1971 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1972 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1973 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1974 | if (!NNS) |
| 1975 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1977 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1978 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1979 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1980 | if (!TransTemplate) |
| 1981 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1982 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1983 | if (!getDerived().AlwaysRebuild() && |
| 1984 | NNS == QTN->getQualifier() && |
| 1985 | TransTemplate == Template) |
| 1986 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1988 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1989 | TransTemplate); |
| 1990 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1991 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1992 | // These should be getting filtered out before they make it into the AST. |
| 1993 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1994 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1996 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1998 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1999 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2000 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2001 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2002 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2004 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2005 | NNS == DTN->getQualifier() && |
| 2006 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2007 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2008 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2009 | if (DTN->isIdentifier()) |
| 2010 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 2011 | ObjectType); |
| 2012 | |
| 2013 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 2014 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2015 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2017 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2019 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2020 | if (!TransTemplate) |
| 2021 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2023 | if (!getDerived().AlwaysRebuild() && |
| 2024 | TransTemplate == Template) |
| 2025 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2027 | return TemplateName(TransTemplate); |
| 2028 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2030 | // These should be getting filtered out before they reach the AST. |
| 2031 | assert(false && "overloaded function decl survived to here"); |
| 2032 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2036 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2037 | const TemplateArgument &Arg, |
| 2038 | TemplateArgumentLoc &Output) { |
| 2039 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2040 | switch (Arg.getKind()) { |
| 2041 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2042 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | |
| 2045 | case TemplateArgument::Type: |
| 2046 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2047 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2048 | |
| 2049 | break; |
| 2050 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2051 | case TemplateArgument::Template: |
| 2052 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2053 | break; |
| 2054 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2055 | case TemplateArgument::Expression: |
| 2056 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2057 | break; |
| 2058 | |
| 2059 | case TemplateArgument::Declaration: |
| 2060 | case TemplateArgument::Integral: |
| 2061 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2062 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | template<typename Derived> |
| 2068 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2069 | const TemplateArgumentLoc &Input, |
| 2070 | TemplateArgumentLoc &Output) { |
| 2071 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2072 | switch (Arg.getKind()) { |
| 2073 | case TemplateArgument::Null: |
| 2074 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2075 | Output = Input; |
| 2076 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2077 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2078 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2079 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2080 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2081 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2082 | |
| 2083 | DI = getDerived().TransformType(DI); |
| 2084 | if (!DI) return true; |
| 2085 | |
| 2086 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2087 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2088 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2090 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2091 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2092 | DeclarationName Name; |
| 2093 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2094 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2095 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2096 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2097 | if (!D) return true; |
| 2098 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2099 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2100 | if (SourceExpr) { |
| 2101 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2102 | Action::Unevaluated); |
| 2103 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2104 | if (E.isInvalid()) |
| 2105 | SourceExpr = NULL; |
| 2106 | else { |
| 2107 | SourceExpr = E.takeAs<Expr>(); |
| 2108 | SourceExpr->Retain(); |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2113 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2115 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2116 | case TemplateArgument::Template: { |
| 2117 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2118 | TemplateName Template |
| 2119 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2120 | if (Template.isNull()) |
| 2121 | return true; |
| 2122 | |
| 2123 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2124 | Input.getTemplateQualifierRange(), |
| 2125 | Input.getTemplateNameLoc()); |
| 2126 | return false; |
| 2127 | } |
| 2128 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2129 | case TemplateArgument::Expression: { |
| 2130 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2131 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2132 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2133 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2134 | Expr *InputExpr = Input.getSourceExpression(); |
| 2135 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2136 | |
| 2137 | Sema::OwningExprResult E |
| 2138 | = getDerived().TransformExpr(InputExpr); |
| 2139 | if (E.isInvalid()) return true; |
| 2140 | |
| 2141 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2142 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2143 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2144 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2146 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2147 | case TemplateArgument::Pack: { |
| 2148 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2149 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2150 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2151 | AEnd = Arg.pack_end(); |
| 2152 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2153 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2154 | // FIXME: preserve source information here when we start |
| 2155 | // caring about parameter packs. |
| 2156 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2157 | TemplateArgumentLoc InputArg; |
| 2158 | TemplateArgumentLoc OutputArg; |
| 2159 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2160 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2161 | return true; |
| 2162 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2163 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2164 | } |
| 2165 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2167 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2168 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2169 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2170 | } |
| 2171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2172 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2173 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2174 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2177 | //===----------------------------------------------------------------------===// |
| 2178 | // Type transformation |
| 2179 | //===----------------------------------------------------------------------===// |
| 2180 | |
| 2181 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2182 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2183 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2184 | if (getDerived().AlreadyTransformed(T)) |
| 2185 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2186 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2187 | // Temporary workaround. All of these transformations should |
| 2188 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2189 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2190 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2192 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2193 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2194 | if (!NewDI) |
| 2195 | return QualType(); |
| 2196 | |
| 2197 | return NewDI->getType(); |
| 2198 | } |
| 2199 | |
| 2200 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2201 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2202 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2203 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2204 | return DI; |
| 2205 | |
| 2206 | TypeLocBuilder TLB; |
| 2207 | |
| 2208 | TypeLoc TL = DI->getTypeLoc(); |
| 2209 | TLB.reserve(TL.getFullDataSize()); |
| 2210 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2211 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2212 | if (Result.isNull()) |
| 2213 | return 0; |
| 2214 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2215 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | template<typename Derived> |
| 2219 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2220 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2221 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2222 | switch (T.getTypeLocClass()) { |
| 2223 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2224 | #define TYPELOC(CLASS, PARENT) \ |
| 2225 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2226 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2227 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2228 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2230 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2231 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2232 | return QualType(); |
| 2233 | } |
| 2234 | |
| 2235 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2236 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2237 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2238 | /// types). This is the right thing for template instantiation, but |
| 2239 | /// probably not for other clients. |
| 2240 | template<typename Derived> |
| 2241 | QualType |
| 2242 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2243 | QualifiedTypeLoc T, |
| 2244 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2245 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2246 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2247 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2248 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2249 | if (Result.isNull()) |
| 2250 | return QualType(); |
| 2251 | |
| 2252 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2253 | // FIXME: this is the right thing for template instantiation, but |
| 2254 | // probably not for other clients. |
| 2255 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2256 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2257 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2258 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2259 | |
| 2260 | TLB.push<QualifiedTypeLoc>(Result); |
| 2261 | |
| 2262 | // No location information to preserve. |
| 2263 | |
| 2264 | return Result; |
| 2265 | } |
| 2266 | |
| 2267 | template <class TyLoc> static inline |
| 2268 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2269 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2270 | NewT.setNameLoc(T.getNameLoc()); |
| 2271 | return T.getType(); |
| 2272 | } |
| 2273 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2274 | template<typename Derived> |
| 2275 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2276 | BuiltinTypeLoc T, |
| 2277 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2278 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2279 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2280 | if (T.needsExtraLocalData()) |
| 2281 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2282 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2285 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2286 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2287 | ComplexTypeLoc T, |
| 2288 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2289 | // FIXME: recurse? |
| 2290 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2291 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2292 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2293 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2294 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2295 | PointerTypeLoc TL, |
| 2296 | QualType ObjectType) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2297 | QualType PointeeType |
| 2298 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2299 | if (PointeeType.isNull()) |
| 2300 | return QualType(); |
| 2301 | |
| 2302 | QualType Result = TL.getType(); |
| 2303 | if (PointeeType->isObjCInterfaceType()) { |
| 2304 | // A dependent pointer type 'T *' has is being transformed such |
| 2305 | // that an Objective-C class type is being replaced for 'T'. The |
| 2306 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2307 | // PointerType. |
| 2308 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2309 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2310 | const_cast<ObjCProtocolDecl **>( |
| 2311 | IFace->qual_begin()), |
| 2312 | IFace->getNumProtocols()); |
| 2313 | |
| 2314 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2315 | NewT.setStarLoc(TL.getSigilLoc()); |
| 2316 | NewT.setHasProtocolsAsWritten(false); |
| 2317 | NewT.setLAngleLoc(SourceLocation()); |
| 2318 | NewT.setRAngleLoc(SourceLocation()); |
| 2319 | NewT.setHasBaseTypeAsWritten(true); |
| 2320 | return Result; |
| 2321 | } |
| 2322 | |
| 2323 | if (getDerived().AlwaysRebuild() || |
| 2324 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2325 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2326 | if (Result.isNull()) |
| 2327 | return QualType(); |
| 2328 | } |
| 2329 | |
| 2330 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2331 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2332 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2333 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2334 | |
| 2335 | template<typename Derived> |
| 2336 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2337 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2338 | BlockPointerTypeLoc TL, |
| 2339 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2340 | QualType PointeeType |
| 2341 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2342 | if (PointeeType.isNull()) |
| 2343 | return QualType(); |
| 2344 | |
| 2345 | QualType Result = TL.getType(); |
| 2346 | if (getDerived().AlwaysRebuild() || |
| 2347 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2348 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 2349 | TL.getSigilLoc()); |
| 2350 | if (Result.isNull()) |
| 2351 | return QualType(); |
| 2352 | } |
| 2353 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2354 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2355 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2356 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2359 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2360 | /// don't care whether the type itself is an l-value type or an r-value |
| 2361 | /// type; we only care if the type was *written* as an l-value type |
| 2362 | /// or an r-value type. |
| 2363 | template<typename Derived> |
| 2364 | QualType |
| 2365 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2366 | ReferenceTypeLoc TL, |
| 2367 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2368 | const ReferenceType *T = TL.getTypePtr(); |
| 2369 | |
| 2370 | // Note that this works with the pointee-as-written. |
| 2371 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2372 | if (PointeeType.isNull()) |
| 2373 | return QualType(); |
| 2374 | |
| 2375 | QualType Result = TL.getType(); |
| 2376 | if (getDerived().AlwaysRebuild() || |
| 2377 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2378 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2379 | T->isSpelledAsLValue(), |
| 2380 | TL.getSigilLoc()); |
| 2381 | if (Result.isNull()) |
| 2382 | return QualType(); |
| 2383 | } |
| 2384 | |
| 2385 | // r-value references can be rebuilt as l-value references. |
| 2386 | ReferenceTypeLoc NewTL; |
| 2387 | if (isa<LValueReferenceType>(Result)) |
| 2388 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2389 | else |
| 2390 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2391 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2392 | |
| 2393 | return Result; |
| 2394 | } |
| 2395 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2396 | template<typename Derived> |
| 2397 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2398 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2399 | LValueReferenceTypeLoc TL, |
| 2400 | QualType ObjectType) { |
| 2401 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2402 | } |
| 2403 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2404 | template<typename Derived> |
| 2405 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2406 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2407 | RValueReferenceTypeLoc TL, |
| 2408 | QualType ObjectType) { |
| 2409 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2410 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2411 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2412 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2413 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2414 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2415 | MemberPointerTypeLoc TL, |
| 2416 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2417 | MemberPointerType *T = TL.getTypePtr(); |
| 2418 | |
| 2419 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2420 | if (PointeeType.isNull()) |
| 2421 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2422 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2423 | // TODO: preserve source information for this. |
| 2424 | QualType ClassType |
| 2425 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2426 | if (ClassType.isNull()) |
| 2427 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2428 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2429 | QualType Result = TL.getType(); |
| 2430 | if (getDerived().AlwaysRebuild() || |
| 2431 | PointeeType != T->getPointeeType() || |
| 2432 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2433 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2434 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2435 | if (Result.isNull()) |
| 2436 | return QualType(); |
| 2437 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2438 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2439 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2440 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2441 | |
| 2442 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2445 | template<typename Derived> |
| 2446 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2447 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2448 | ConstantArrayTypeLoc TL, |
| 2449 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2450 | ConstantArrayType *T = TL.getTypePtr(); |
| 2451 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2452 | if (ElementType.isNull()) |
| 2453 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2454 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2455 | QualType Result = TL.getType(); |
| 2456 | if (getDerived().AlwaysRebuild() || |
| 2457 | ElementType != T->getElementType()) { |
| 2458 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2459 | T->getSizeModifier(), |
| 2460 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2461 | T->getIndexTypeCVRQualifiers(), |
| 2462 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | if (Result.isNull()) |
| 2464 | return QualType(); |
| 2465 | } |
| 2466 | |
| 2467 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2468 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2469 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2470 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2471 | Expr *Size = TL.getSizeExpr(); |
| 2472 | if (Size) { |
| 2473 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2474 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2475 | } |
| 2476 | NewTL.setSizeExpr(Size); |
| 2477 | |
| 2478 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2480 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2481 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2482 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2483 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2484 | IncompleteArrayTypeLoc TL, |
| 2485 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2486 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2487 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2488 | if (ElementType.isNull()) |
| 2489 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2490 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2491 | QualType Result = TL.getType(); |
| 2492 | if (getDerived().AlwaysRebuild() || |
| 2493 | ElementType != T->getElementType()) { |
| 2494 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2495 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2496 | T->getIndexTypeCVRQualifiers(), |
| 2497 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2498 | if (Result.isNull()) |
| 2499 | return QualType(); |
| 2500 | } |
| 2501 | |
| 2502 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2503 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2504 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2505 | NewTL.setSizeExpr(0); |
| 2506 | |
| 2507 | return Result; |
| 2508 | } |
| 2509 | |
| 2510 | template<typename Derived> |
| 2511 | QualType |
| 2512 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2513 | VariableArrayTypeLoc TL, |
| 2514 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2515 | VariableArrayType *T = TL.getTypePtr(); |
| 2516 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2517 | if (ElementType.isNull()) |
| 2518 | return QualType(); |
| 2519 | |
| 2520 | // Array bounds are not potentially evaluated contexts |
| 2521 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2522 | |
| 2523 | Sema::OwningExprResult SizeResult |
| 2524 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2525 | if (SizeResult.isInvalid()) |
| 2526 | return QualType(); |
| 2527 | |
| 2528 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2529 | |
| 2530 | QualType Result = TL.getType(); |
| 2531 | if (getDerived().AlwaysRebuild() || |
| 2532 | ElementType != T->getElementType() || |
| 2533 | Size != T->getSizeExpr()) { |
| 2534 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2535 | T->getSizeModifier(), |
| 2536 | move(SizeResult), |
| 2537 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2538 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2539 | if (Result.isNull()) |
| 2540 | return QualType(); |
| 2541 | } |
| 2542 | else SizeResult.take(); |
| 2543 | |
| 2544 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2545 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2546 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2547 | NewTL.setSizeExpr(Size); |
| 2548 | |
| 2549 | return Result; |
| 2550 | } |
| 2551 | |
| 2552 | template<typename Derived> |
| 2553 | QualType |
| 2554 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2555 | DependentSizedArrayTypeLoc TL, |
| 2556 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2557 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2558 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2559 | if (ElementType.isNull()) |
| 2560 | return QualType(); |
| 2561 | |
| 2562 | // Array bounds are not potentially evaluated contexts |
| 2563 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2564 | |
| 2565 | Sema::OwningExprResult SizeResult |
| 2566 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2567 | if (SizeResult.isInvalid()) |
| 2568 | return QualType(); |
| 2569 | |
| 2570 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2571 | |
| 2572 | QualType Result = TL.getType(); |
| 2573 | if (getDerived().AlwaysRebuild() || |
| 2574 | ElementType != T->getElementType() || |
| 2575 | Size != T->getSizeExpr()) { |
| 2576 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2577 | T->getSizeModifier(), |
| 2578 | move(SizeResult), |
| 2579 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2580 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2581 | if (Result.isNull()) |
| 2582 | return QualType(); |
| 2583 | } |
| 2584 | else SizeResult.take(); |
| 2585 | |
| 2586 | // We might have any sort of array type now, but fortunately they |
| 2587 | // all have the same location layout. |
| 2588 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2589 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2590 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2591 | NewTL.setSizeExpr(Size); |
| 2592 | |
| 2593 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2595 | |
| 2596 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2597 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2598 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2599 | DependentSizedExtVectorTypeLoc TL, |
| 2600 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2601 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2602 | |
| 2603 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2604 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2605 | if (ElementType.isNull()) |
| 2606 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2607 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2608 | // Vector sizes are not potentially evaluated contexts |
| 2609 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2610 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2611 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2612 | if (Size.isInvalid()) |
| 2613 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2614 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2615 | QualType Result = TL.getType(); |
| 2616 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2617 | ElementType != T->getElementType() || |
| 2618 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2619 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2620 | move(Size), |
| 2621 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2622 | if (Result.isNull()) |
| 2623 | return QualType(); |
| 2624 | } |
| 2625 | else Size.take(); |
| 2626 | |
| 2627 | // Result might be dependent or not. |
| 2628 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2629 | DependentSizedExtVectorTypeLoc NewTL |
| 2630 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2631 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2632 | } else { |
| 2633 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2634 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2635 | } |
| 2636 | |
| 2637 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2638 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2639 | |
| 2640 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2641 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2642 | VectorTypeLoc TL, |
| 2643 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2645 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2646 | if (ElementType.isNull()) |
| 2647 | return QualType(); |
| 2648 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | QualType Result = TL.getType(); |
| 2650 | if (getDerived().AlwaysRebuild() || |
| 2651 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2652 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2653 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2654 | if (Result.isNull()) |
| 2655 | return QualType(); |
| 2656 | } |
| 2657 | |
| 2658 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2659 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2660 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2661 | return Result; |
| 2662 | } |
| 2663 | |
| 2664 | template<typename Derived> |
| 2665 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2666 | ExtVectorTypeLoc TL, |
| 2667 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | VectorType *T = TL.getTypePtr(); |
| 2669 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2670 | if (ElementType.isNull()) |
| 2671 | return QualType(); |
| 2672 | |
| 2673 | QualType Result = TL.getType(); |
| 2674 | if (getDerived().AlwaysRebuild() || |
| 2675 | ElementType != T->getElementType()) { |
| 2676 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2677 | T->getNumElements(), |
| 2678 | /*FIXME*/ SourceLocation()); |
| 2679 | if (Result.isNull()) |
| 2680 | return QualType(); |
| 2681 | } |
| 2682 | |
| 2683 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2684 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2685 | |
| 2686 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2687 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2688 | |
| 2689 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2690 | ParmVarDecl * |
| 2691 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2692 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2693 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2694 | if (!NewDI) |
| 2695 | return 0; |
| 2696 | |
| 2697 | if (NewDI == OldDI) |
| 2698 | return OldParm; |
| 2699 | else |
| 2700 | return ParmVarDecl::Create(SemaRef.Context, |
| 2701 | OldParm->getDeclContext(), |
| 2702 | OldParm->getLocation(), |
| 2703 | OldParm->getIdentifier(), |
| 2704 | NewDI->getType(), |
| 2705 | NewDI, |
| 2706 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2707 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2708 | /* DefArg */ NULL); |
| 2709 | } |
| 2710 | |
| 2711 | template<typename Derived> |
| 2712 | bool TreeTransform<Derived>:: |
| 2713 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2714 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2715 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2716 | FunctionProtoType *T = TL.getTypePtr(); |
| 2717 | |
| 2718 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2719 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2720 | |
| 2721 | QualType NewType; |
| 2722 | ParmVarDecl *NewParm; |
| 2723 | |
| 2724 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2725 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2726 | if (!NewParm) |
| 2727 | return true; |
| 2728 | NewType = NewParm->getType(); |
| 2729 | |
| 2730 | // Deal with the possibility that we don't have a parameter |
| 2731 | // declaration for this parameter. |
| 2732 | } else { |
| 2733 | NewParm = 0; |
| 2734 | |
| 2735 | QualType OldType = T->getArgType(i); |
| 2736 | NewType = getDerived().TransformType(OldType); |
| 2737 | if (NewType.isNull()) |
| 2738 | return true; |
| 2739 | } |
| 2740 | |
| 2741 | PTypes.push_back(NewType); |
| 2742 | PVars.push_back(NewParm); |
| 2743 | } |
| 2744 | |
| 2745 | return false; |
| 2746 | } |
| 2747 | |
| 2748 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2749 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2751 | FunctionProtoTypeLoc TL, |
| 2752 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2753 | FunctionProtoType *T = TL.getTypePtr(); |
| 2754 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2755 | if (ResultType.isNull()) |
| 2756 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2757 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2758 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2759 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2760 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2761 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2762 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2763 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2764 | QualType Result = TL.getType(); |
| 2765 | if (getDerived().AlwaysRebuild() || |
| 2766 | ResultType != T->getResultType() || |
| 2767 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2768 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2769 | ParamTypes.data(), |
| 2770 | ParamTypes.size(), |
| 2771 | T->isVariadic(), |
| 2772 | T->getTypeQuals()); |
| 2773 | if (Result.isNull()) |
| 2774 | return QualType(); |
| 2775 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2777 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2778 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2779 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2780 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2781 | NewTL.setArg(i, ParamDecls[i]); |
| 2782 | |
| 2783 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2784 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2785 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2786 | template<typename Derived> |
| 2787 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2788 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2789 | FunctionNoProtoTypeLoc TL, |
| 2790 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2791 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2792 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2793 | if (ResultType.isNull()) |
| 2794 | return QualType(); |
| 2795 | |
| 2796 | QualType Result = TL.getType(); |
| 2797 | if (getDerived().AlwaysRebuild() || |
| 2798 | ResultType != T->getResultType()) |
| 2799 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2800 | |
| 2801 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2802 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2803 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2804 | |
| 2805 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2806 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2807 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2808 | template<typename Derived> QualType |
| 2809 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2810 | UnresolvedUsingTypeLoc TL, |
| 2811 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2812 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2813 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2814 | if (!D) |
| 2815 | return QualType(); |
| 2816 | |
| 2817 | QualType Result = TL.getType(); |
| 2818 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2819 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2820 | if (Result.isNull()) |
| 2821 | return QualType(); |
| 2822 | } |
| 2823 | |
| 2824 | // We might get an arbitrary type spec type back. We should at |
| 2825 | // least always get a type spec type, though. |
| 2826 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2827 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2828 | |
| 2829 | return Result; |
| 2830 | } |
| 2831 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2832 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2833 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2834 | TypedefTypeLoc TL, |
| 2835 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2836 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2837 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2838 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2839 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2840 | if (!Typedef) |
| 2841 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2842 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2843 | QualType Result = TL.getType(); |
| 2844 | if (getDerived().AlwaysRebuild() || |
| 2845 | Typedef != T->getDecl()) { |
| 2846 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2847 | if (Result.isNull()) |
| 2848 | return QualType(); |
| 2849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2850 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2851 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2852 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2853 | |
| 2854 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2857 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2858 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2859 | TypeOfExprTypeLoc TL, |
| 2860 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2861 | // typeof expressions are not potentially evaluated contexts |
| 2862 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2864 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2865 | if (E.isInvalid()) |
| 2866 | return QualType(); |
| 2867 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2868 | QualType Result = TL.getType(); |
| 2869 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2870 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2871 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2872 | if (Result.isNull()) |
| 2873 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2874 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2875 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2876 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2877 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2878 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2879 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2880 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2881 | |
| 2882 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2884 | |
| 2885 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2886 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2887 | TypeOfTypeLoc TL, |
| 2888 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2889 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2890 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2891 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2892 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2894 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2895 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2896 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2897 | if (Result.isNull()) |
| 2898 | return QualType(); |
| 2899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2900 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2901 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2902 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2903 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2904 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2905 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2906 | |
| 2907 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2908 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2909 | |
| 2910 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2911 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2912 | DecltypeTypeLoc TL, |
| 2913 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2914 | DecltypeType *T = TL.getTypePtr(); |
| 2915 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2916 | // decltype expressions are not potentially evaluated contexts |
| 2917 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2918 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2919 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2920 | if (E.isInvalid()) |
| 2921 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2923 | QualType Result = TL.getType(); |
| 2924 | if (getDerived().AlwaysRebuild() || |
| 2925 | E.get() != T->getUnderlyingExpr()) { |
| 2926 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2927 | if (Result.isNull()) |
| 2928 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2930 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2933 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2934 | |
| 2935 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2939 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2940 | RecordTypeLoc TL, |
| 2941 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2942 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2943 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2944 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2945 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2946 | if (!Record) |
| 2947 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2948 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2949 | QualType Result = TL.getType(); |
| 2950 | if (getDerived().AlwaysRebuild() || |
| 2951 | Record != T->getDecl()) { |
| 2952 | Result = getDerived().RebuildRecordType(Record); |
| 2953 | if (Result.isNull()) |
| 2954 | return QualType(); |
| 2955 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2956 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2957 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2958 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2959 | |
| 2960 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2962 | |
| 2963 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2964 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2965 | EnumTypeLoc TL, |
| 2966 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2967 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2968 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2969 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2970 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2971 | if (!Enum) |
| 2972 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2973 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2974 | QualType Result = TL.getType(); |
| 2975 | if (getDerived().AlwaysRebuild() || |
| 2976 | Enum != T->getDecl()) { |
| 2977 | Result = getDerived().RebuildEnumType(Enum); |
| 2978 | if (Result.isNull()) |
| 2979 | return QualType(); |
| 2980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2981 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2982 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2983 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2984 | |
| 2985 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2986 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2987 | |
| 2988 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2989 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2990 | ElaboratedTypeLoc TL, |
| 2991 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2992 | ElaboratedType *T = TL.getTypePtr(); |
| 2993 | |
| 2994 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2995 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2996 | if (Underlying.isNull()) |
| 2997 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2998 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2999 | QualType Result = TL.getType(); |
| 3000 | if (getDerived().AlwaysRebuild() || |
| 3001 | Underlying != T->getUnderlyingType()) { |
| 3002 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 3003 | if (Result.isNull()) |
| 3004 | return QualType(); |
| 3005 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3006 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3007 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3008 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3009 | |
| 3010 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3011 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3012 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3013 | template<typename Derived> |
| 3014 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3015 | TypeLocBuilder &TLB, |
| 3016 | InjectedClassNameTypeLoc TL, |
| 3017 | QualType ObjectType) { |
| 3018 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3019 | TL.getTypePtr()->getDecl()); |
| 3020 | if (!D) return QualType(); |
| 3021 | |
| 3022 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3023 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3024 | return T; |
| 3025 | } |
| 3026 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3028 | template<typename Derived> |
| 3029 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3030 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3031 | TemplateTypeParmTypeLoc TL, |
| 3032 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3033 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3037 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3039 | SubstTemplateTypeParmTypeLoc TL, |
| 3040 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3041 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3045 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3046 | const TemplateSpecializationType *TST, |
| 3047 | QualType ObjectType) { |
| 3048 | // FIXME: this entire method is a temporary workaround; callers |
| 3049 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3050 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3051 | // Fake up a TemplateSpecializationTypeLoc. |
| 3052 | TypeLocBuilder TLB; |
| 3053 | TemplateSpecializationTypeLoc TL |
| 3054 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3055 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3056 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3057 | |
| 3058 | TL.setTemplateNameLoc(BaseLoc); |
| 3059 | TL.setLAngleLoc(BaseLoc); |
| 3060 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3061 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3062 | const TemplateArgument &TA = TST->getArg(i); |
| 3063 | TemplateArgumentLoc TAL; |
| 3064 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3065 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3066 | } |
| 3067 | |
| 3068 | TypeLocBuilder IgnoredTLB; |
| 3069 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3073 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3074 | TypeLocBuilder &TLB, |
| 3075 | TemplateSpecializationTypeLoc TL, |
| 3076 | QualType ObjectType) { |
| 3077 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3078 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3079 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3080 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3081 | if (Template.isNull()) |
| 3082 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3084 | TemplateArgumentListInfo NewTemplateArgs; |
| 3085 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3086 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3087 | |
| 3088 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3089 | TemplateArgumentLoc Loc; |
| 3090 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3091 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3092 | NewTemplateArgs.addArgument(Loc); |
| 3093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3095 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3096 | |
| 3097 | QualType Result = |
| 3098 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3099 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3100 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3101 | |
| 3102 | if (!Result.isNull()) { |
| 3103 | TemplateSpecializationTypeLoc NewTL |
| 3104 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3105 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3106 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3107 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3108 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3109 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3112 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
| 3115 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3116 | QualType |
| 3117 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3118 | QualifiedNameTypeLoc TL, |
| 3119 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3120 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3121 | NestedNameSpecifier *NNS |
| 3122 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3123 | SourceRange(), |
| 3124 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3125 | if (!NNS) |
| 3126 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3128 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3129 | if (Named.isNull()) |
| 3130 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3131 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3132 | QualType Result = TL.getType(); |
| 3133 | if (getDerived().AlwaysRebuild() || |
| 3134 | NNS != T->getQualifier() || |
| 3135 | Named != T->getNamedType()) { |
| 3136 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3137 | if (Result.isNull()) |
| 3138 | return QualType(); |
| 3139 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3140 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3141 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3142 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3143 | |
| 3144 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3146 | |
| 3147 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3148 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3149 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3150 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3151 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3152 | |
| 3153 | /* FIXME: preserve source information better than this */ |
| 3154 | SourceRange SR(TL.getNameLoc()); |
| 3155 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3156 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3157 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3158 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3159 | if (!NNS) |
| 3160 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3162 | QualType Result; |
| 3163 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3164 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3165 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3166 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3167 | if (NewTemplateId.isNull()) |
| 3168 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3170 | if (!getDerived().AlwaysRebuild() && |
| 3171 | NNS == T->getQualifier() && |
| 3172 | NewTemplateId == QualType(TemplateId, 0)) |
| 3173 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3175 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3176 | NewTemplateId); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3177 | } else { |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3178 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3179 | T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3180 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3181 | if (Result.isNull()) |
| 3182 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3183 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3184 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3185 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3186 | |
| 3187 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3190 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3191 | QualType |
| 3192 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3193 | ObjCInterfaceTypeLoc TL, |
| 3194 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3195 | // ObjCInterfaceType is never dependent. |
| 3196 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | |
| 3199 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3200 | QualType |
| 3201 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3202 | ObjCObjectPointerTypeLoc TL, |
| 3203 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3204 | // ObjCObjectPointerType is never dependent. |
| 3205 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3208 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3209 | // Statement transformation |
| 3210 | //===----------------------------------------------------------------------===// |
| 3211 | template<typename Derived> |
| 3212 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3213 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3214 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | template<typename Derived> |
| 3218 | Sema::OwningStmtResult |
| 3219 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3220 | return getDerived().TransformCompoundStmt(S, false); |
| 3221 | } |
| 3222 | |
| 3223 | template<typename Derived> |
| 3224 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | bool IsStmtExpr) { |
| 3227 | bool SubStmtChanged = false; |
| 3228 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3229 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3230 | B != BEnd; ++B) { |
| 3231 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3232 | if (Result.isInvalid()) |
| 3233 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3236 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3237 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3239 | if (!getDerived().AlwaysRebuild() && |
| 3240 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | |
| 3243 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3244 | move_arg(Statements), |
| 3245 | S->getRBracLoc(), |
| 3246 | IsStmtExpr); |
| 3247 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3248 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3249 | template<typename Derived> |
| 3250 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3251 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3252 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3253 | { |
| 3254 | // The case value expressions are not potentially evaluated. |
| 3255 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3256 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3257 | // Transform the left-hand case value. |
| 3258 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3259 | if (LHS.isInvalid()) |
| 3260 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3262 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3263 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3264 | if (RHS.isInvalid()) |
| 3265 | return SemaRef.StmtError(); |
| 3266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3268 | // Build the case statement. |
| 3269 | // Case statements are always rebuilt so that they will attached to their |
| 3270 | // transformed switch statement. |
| 3271 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3272 | move(LHS), |
| 3273 | S->getEllipsisLoc(), |
| 3274 | move(RHS), |
| 3275 | S->getColonLoc()); |
| 3276 | if (Case.isInvalid()) |
| 3277 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3279 | // Transform the statement following the case |
| 3280 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3281 | if (SubStmt.isInvalid()) |
| 3282 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3283 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | // Attach the body to the case statement |
| 3285 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3286 | } |
| 3287 | |
| 3288 | template<typename Derived> |
| 3289 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3291 | // Transform the statement following the default case |
| 3292 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3293 | if (SubStmt.isInvalid()) |
| 3294 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3296 | // Default statements are always rebuilt |
| 3297 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3298 | move(SubStmt)); |
| 3299 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3301 | template<typename Derived> |
| 3302 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3305 | if (SubStmt.isInvalid()) |
| 3306 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3308 | // FIXME: Pass the real colon location in. |
| 3309 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3310 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3311 | move(SubStmt)); |
| 3312 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | Sema::OwningStmtResult |
| 3316 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3318 | OwningExprResult Cond(SemaRef); |
| 3319 | VarDecl *ConditionVar = 0; |
| 3320 | if (S->getConditionVariable()) { |
| 3321 | ConditionVar |
| 3322 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3323 | getDerived().TransformDefinition( |
| 3324 | S->getConditionVariable()->getLocation(), |
| 3325 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3326 | if (!ConditionVar) |
| 3327 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3328 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3329 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3330 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3331 | if (Cond.isInvalid()) |
| 3332 | return SemaRef.StmtError(); |
| 3333 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3334 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3335 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | // Transform the "then" branch. |
| 3338 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3339 | if (Then.isInvalid()) |
| 3340 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | // Transform the "else" branch. |
| 3343 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3344 | if (Else.isInvalid()) |
| 3345 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3347 | if (!getDerived().AlwaysRebuild() && |
| 3348 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3349 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | Then.get() == S->getThen() && |
| 3351 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | return SemaRef.Owned(S->Retain()); |
| 3353 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3354 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3355 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | template<typename Derived> |
| 3360 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3361 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3363 | OwningExprResult Cond(SemaRef); |
| 3364 | VarDecl *ConditionVar = 0; |
| 3365 | if (S->getConditionVariable()) { |
| 3366 | ConditionVar |
| 3367 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3368 | getDerived().TransformDefinition( |
| 3369 | S->getConditionVariable()->getLocation(), |
| 3370 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3371 | if (!ConditionVar) |
| 3372 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3373 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3374 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3375 | |
| 3376 | if (Cond.isInvalid()) |
| 3377 | return SemaRef.StmtError(); |
| 3378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3380 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3381 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3382 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3383 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3384 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3385 | if (Switch.isInvalid()) |
| 3386 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3387 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3388 | // Transform the body of the switch statement. |
| 3389 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3390 | if (Body.isInvalid()) |
| 3391 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3393 | // Complete the switch statement. |
| 3394 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3395 | move(Body)); |
| 3396 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3397 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3398 | template<typename Derived> |
| 3399 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3401 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3402 | OwningExprResult Cond(SemaRef); |
| 3403 | VarDecl *ConditionVar = 0; |
| 3404 | if (S->getConditionVariable()) { |
| 3405 | ConditionVar |
| 3406 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3407 | getDerived().TransformDefinition( |
| 3408 | S->getConditionVariable()->getLocation(), |
| 3409 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3410 | if (!ConditionVar) |
| 3411 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3412 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3413 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3414 | |
| 3415 | if (Cond.isInvalid()) |
| 3416 | return SemaRef.StmtError(); |
| 3417 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3418 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3419 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3420 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3421 | // Transform the body |
| 3422 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3423 | if (Body.isInvalid()) |
| 3424 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3426 | if (!getDerived().AlwaysRebuild() && |
| 3427 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3428 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3430 | return SemaRef.Owned(S->Retain()); |
| 3431 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3432 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3433 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3436 | template<typename Derived> |
| 3437 | Sema::OwningStmtResult |
| 3438 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3439 | // Transform the condition |
| 3440 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3441 | if (Cond.isInvalid()) |
| 3442 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3443 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3444 | // Transform the body |
| 3445 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3446 | if (Body.isInvalid()) |
| 3447 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3449 | if (!getDerived().AlwaysRebuild() && |
| 3450 | Cond.get() == S->getCond() && |
| 3451 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | return SemaRef.Owned(S->Retain()); |
| 3453 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3454 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3455 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3456 | S->getRParenLoc()); |
| 3457 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3459 | template<typename Derived> |
| 3460 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | // Transform the initialization statement |
| 3463 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3464 | if (Init.isInvalid()) |
| 3465 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3466 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3467 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3468 | OwningExprResult Cond(SemaRef); |
| 3469 | VarDecl *ConditionVar = 0; |
| 3470 | if (S->getConditionVariable()) { |
| 3471 | ConditionVar |
| 3472 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3473 | getDerived().TransformDefinition( |
| 3474 | S->getConditionVariable()->getLocation(), |
| 3475 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3476 | if (!ConditionVar) |
| 3477 | return SemaRef.StmtError(); |
| 3478 | } else { |
| 3479 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3480 | |
| 3481 | if (Cond.isInvalid()) |
| 3482 | return SemaRef.StmtError(); |
| 3483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3484 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3485 | // Transform the increment |
| 3486 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3487 | if (Inc.isInvalid()) |
| 3488 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3490 | // Transform the body |
| 3491 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3492 | if (Body.isInvalid()) |
| 3493 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3494 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3495 | if (!getDerived().AlwaysRebuild() && |
| 3496 | Init.get() == S->getInit() && |
| 3497 | Cond.get() == S->getCond() && |
| 3498 | Inc.get() == S->getInc() && |
| 3499 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | return SemaRef.Owned(S->Retain()); |
| 3501 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3502 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3503 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3504 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3505 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3506 | S->getRParenLoc(), move(Body)); |
| 3507 | } |
| 3508 | |
| 3509 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3510 | Sema::OwningStmtResult |
| 3511 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3512 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3513 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3514 | S->getLabel()); |
| 3515 | } |
| 3516 | |
| 3517 | template<typename Derived> |
| 3518 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3520 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3521 | if (Target.isInvalid()) |
| 3522 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | if (!getDerived().AlwaysRebuild() && |
| 3525 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3527 | |
| 3528 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3529 | move(Target)); |
| 3530 | } |
| 3531 | |
| 3532 | template<typename Derived> |
| 3533 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3534 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3535 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3538 | template<typename Derived> |
| 3539 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3541 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3544 | template<typename Derived> |
| 3545 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3546 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3547 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3548 | if (Result.isInvalid()) |
| 3549 | return SemaRef.StmtError(); |
| 3550 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3551 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3552 | // to tell whether the return type of the function has changed. |
| 3553 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3554 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3556 | template<typename Derived> |
| 3557 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3559 | bool DeclChanged = false; |
| 3560 | llvm::SmallVector<Decl *, 4> Decls; |
| 3561 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3562 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3563 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3564 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3565 | if (!Transformed) |
| 3566 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3567 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3568 | if (Transformed != *D) |
| 3569 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3570 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3571 | Decls.push_back(Transformed); |
| 3572 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3574 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3575 | return SemaRef.Owned(S->Retain()); |
| 3576 | |
| 3577 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3578 | S->getStartLoc(), S->getEndLoc()); |
| 3579 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3581 | template<typename Derived> |
| 3582 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3584 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | template<typename Derived> |
| 3589 | Sema::OwningStmtResult |
| 3590 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3591 | |
| 3592 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3593 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3594 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3595 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3596 | OwningExprResult AsmString(SemaRef); |
| 3597 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3598 | |
| 3599 | bool ExprsChanged = false; |
| 3600 | |
| 3601 | // Go through the outputs. |
| 3602 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3603 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3604 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3605 | // No need to transform the constraint literal. |
| 3606 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3607 | |
| 3608 | // Transform the output expr. |
| 3609 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3610 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3611 | if (Result.isInvalid()) |
| 3612 | return SemaRef.StmtError(); |
| 3613 | |
| 3614 | ExprsChanged |= Result.get() != OutputExpr; |
| 3615 | |
| 3616 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3617 | } |
| 3618 | |
| 3619 | // Go through the inputs. |
| 3620 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3621 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3622 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3623 | // No need to transform the constraint literal. |
| 3624 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3625 | |
| 3626 | // Transform the input expr. |
| 3627 | Expr *InputExpr = S->getInputExpr(I); |
| 3628 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3629 | if (Result.isInvalid()) |
| 3630 | return SemaRef.StmtError(); |
| 3631 | |
| 3632 | ExprsChanged |= Result.get() != InputExpr; |
| 3633 | |
| 3634 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3635 | } |
| 3636 | |
| 3637 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3638 | return SemaRef.Owned(S->Retain()); |
| 3639 | |
| 3640 | // Go through the clobbers. |
| 3641 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3642 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3643 | |
| 3644 | // No need to transform the asm string literal. |
| 3645 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3646 | |
| 3647 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3648 | S->isSimple(), |
| 3649 | S->isVolatile(), |
| 3650 | S->getNumOutputs(), |
| 3651 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3652 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3653 | move_arg(Constraints), |
| 3654 | move_arg(Exprs), |
| 3655 | move(AsmString), |
| 3656 | move_arg(Clobbers), |
| 3657 | S->getRParenLoc(), |
| 3658 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | |
| 3662 | template<typename Derived> |
| 3663 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3664 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3665 | // FIXME: Implement this |
| 3666 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3670 | template<typename Derived> |
| 3671 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3673 | // FIXME: Implement this |
| 3674 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3675 | return SemaRef.Owned(S->Retain()); |
| 3676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3678 | template<typename Derived> |
| 3679 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3681 | // FIXME: Implement this |
| 3682 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3683 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3684 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3686 | template<typename Derived> |
| 3687 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3689 | OwningExprResult Operand(SemaRef); |
| 3690 | if (S->getThrowExpr()) { |
| 3691 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3692 | if (Operand.isInvalid()) |
| 3693 | return getSema().StmtError(); |
| 3694 | } |
| 3695 | |
| 3696 | if (!getDerived().AlwaysRebuild() && |
| 3697 | Operand.get() == S->getThrowExpr()) |
| 3698 | return getSema().Owned(S->Retain()); |
| 3699 | |
| 3700 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3703 | template<typename Derived> |
| 3704 | Sema::OwningStmtResult |
| 3705 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3706 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3707 | // Transform the object we are locking. |
| 3708 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3709 | if (Object.isInvalid()) |
| 3710 | return SemaRef.StmtError(); |
| 3711 | |
| 3712 | // Transform the body. |
| 3713 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3714 | if (Body.isInvalid()) |
| 3715 | return SemaRef.StmtError(); |
| 3716 | |
| 3717 | // If nothing change, just retain the current statement. |
| 3718 | if (!getDerived().AlwaysRebuild() && |
| 3719 | Object.get() == S->getSynchExpr() && |
| 3720 | Body.get() == S->getSynchBody()) |
| 3721 | return SemaRef.Owned(S->Retain()); |
| 3722 | |
| 3723 | // Build a new statement. |
| 3724 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 3725 | move(Object), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | template<typename Derived> |
| 3729 | Sema::OwningStmtResult |
| 3730 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3731 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame^] | 3732 | // Transform the element statement. |
| 3733 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 3734 | if (Element.isInvalid()) |
| 3735 | return SemaRef.StmtError(); |
| 3736 | |
| 3737 | // Transform the collection expression. |
| 3738 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 3739 | if (Collection.isInvalid()) |
| 3740 | return SemaRef.StmtError(); |
| 3741 | |
| 3742 | // Transform the body. |
| 3743 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3744 | if (Body.isInvalid()) |
| 3745 | return SemaRef.StmtError(); |
| 3746 | |
| 3747 | // If nothing changed, just retain this statement. |
| 3748 | if (!getDerived().AlwaysRebuild() && |
| 3749 | Element.get() == S->getElement() && |
| 3750 | Collection.get() == S->getCollection() && |
| 3751 | Body.get() == S->getBody()) |
| 3752 | return SemaRef.Owned(S->Retain()); |
| 3753 | |
| 3754 | // Build a new statement. |
| 3755 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 3756 | /*FIXME:*/S->getForLoc(), |
| 3757 | move(Element), |
| 3758 | move(Collection), |
| 3759 | S->getRParenLoc(), |
| 3760 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | |
| 3764 | template<typename Derived> |
| 3765 | Sema::OwningStmtResult |
| 3766 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3767 | // Transform the exception declaration, if any. |
| 3768 | VarDecl *Var = 0; |
| 3769 | if (S->getExceptionDecl()) { |
| 3770 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3771 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3772 | ExceptionDecl->getDeclName()); |
| 3773 | |
| 3774 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3775 | if (T.isNull()) |
| 3776 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3778 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3779 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3780 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3781 | ExceptionDecl->getIdentifier(), |
| 3782 | ExceptionDecl->getLocation(), |
| 3783 | /*FIXME: Inaccurate*/ |
| 3784 | SourceRange(ExceptionDecl->getLocation())); |
| 3785 | if (!Var || Var->isInvalidDecl()) { |
| 3786 | if (Var) |
| 3787 | Var->Destroy(SemaRef.Context); |
| 3788 | return SemaRef.StmtError(); |
| 3789 | } |
| 3790 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3792 | // Transform the actual exception handler. |
| 3793 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3794 | if (Handler.isInvalid()) { |
| 3795 | if (Var) |
| 3796 | Var->Destroy(SemaRef.Context); |
| 3797 | return SemaRef.StmtError(); |
| 3798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3800 | if (!getDerived().AlwaysRebuild() && |
| 3801 | !Var && |
| 3802 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3803 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3804 | |
| 3805 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3806 | Var, |
| 3807 | move(Handler)); |
| 3808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3810 | template<typename Derived> |
| 3811 | Sema::OwningStmtResult |
| 3812 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3813 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3815 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3816 | if (TryBlock.isInvalid()) |
| 3817 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3818 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3819 | // Transform the handlers. |
| 3820 | bool HandlerChanged = false; |
| 3821 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3822 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3823 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3824 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3825 | if (Handler.isInvalid()) |
| 3826 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3827 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3828 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3829 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3831 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3832 | if (!getDerived().AlwaysRebuild() && |
| 3833 | TryBlock.get() == S->getTryBlock() && |
| 3834 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3835 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3836 | |
| 3837 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3838 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3839 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3841 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | // Expression transformation |
| 3843 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | template<typename Derived> |
| 3845 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3846 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3847 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
| 3850 | template<typename Derived> |
| 3851 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3852 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3853 | NestedNameSpecifier *Qualifier = 0; |
| 3854 | if (E->getQualifier()) { |
| 3855 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3856 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3857 | if (!Qualifier) |
| 3858 | return SemaRef.ExprError(); |
| 3859 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3860 | |
| 3861 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3862 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3863 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | if (!ND) |
| 3865 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3867 | if (!getDerived().AlwaysRebuild() && |
| 3868 | Qualifier == E->getQualifier() && |
| 3869 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3870 | !E->hasExplicitTemplateArgumentList()) { |
| 3871 | |
| 3872 | // Mark it referenced in the new context regardless. |
| 3873 | // FIXME: this is a bit instantiation-specific. |
| 3874 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3875 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3877 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3878 | |
| 3879 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3880 | if (E->hasExplicitTemplateArgumentList()) { |
| 3881 | TemplateArgs = &TransArgs; |
| 3882 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3883 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3884 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3885 | TemplateArgumentLoc Loc; |
| 3886 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3887 | return SemaRef.ExprError(); |
| 3888 | TransArgs.addArgument(Loc); |
| 3889 | } |
| 3890 | } |
| 3891 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3892 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3893 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3896 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3898 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3904 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3905 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3908 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3909 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3910 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3913 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3914 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3916 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3921 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3922 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3923 | return SemaRef.Owned(E->Retain()); |
| 3924 | } |
| 3925 | |
| 3926 | template<typename Derived> |
| 3927 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3928 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3930 | if (SubExpr.isInvalid()) |
| 3931 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3932 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3933 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3934 | return SemaRef.Owned(E->Retain()); |
| 3935 | |
| 3936 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3937 | E->getRParen()); |
| 3938 | } |
| 3939 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3940 | template<typename Derived> |
| 3941 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3942 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3943 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | if (SubExpr.isInvalid()) |
| 3945 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3947 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3948 | return SemaRef.Owned(E->Retain()); |
| 3949 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3951 | E->getOpcode(), |
| 3952 | move(SubExpr)); |
| 3953 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3954 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3955 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3957 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3958 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3959 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3960 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3961 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3962 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3964 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3965 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3966 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3967 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3968 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3969 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | E->getSourceRange()); |
| 3971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | // C++0x [expr.sizeof]p1: |
| 3976 | // The operand is either an expression, which is an unevaluated operand |
| 3977 | // [...] |
| 3978 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3981 | if (SubExpr.isInvalid()) |
| 3982 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3984 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3985 | return SemaRef.Owned(E->Retain()); |
| 3986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3988 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3989 | E->isSizeOf(), |
| 3990 | E->getSourceRange()); |
| 3991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3994 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3995 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3996 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3997 | if (LHS.isInvalid()) |
| 3998 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4000 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4001 | if (RHS.isInvalid()) |
| 4002 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4003 | |
| 4004 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4005 | if (!getDerived().AlwaysRebuild() && |
| 4006 | LHS.get() == E->getLHS() && |
| 4007 | RHS.get() == E->getRHS()) |
| 4008 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4010 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4011 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4012 | move(RHS), |
| 4013 | E->getRBracketLoc()); |
| 4014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | |
| 4016 | template<typename Derived> |
| 4017 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4018 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4019 | // Transform the callee. |
| 4020 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4021 | if (Callee.isInvalid()) |
| 4022 | return SemaRef.ExprError(); |
| 4023 | |
| 4024 | // Transform arguments. |
| 4025 | bool ArgChanged = false; |
| 4026 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4027 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4028 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4029 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4030 | if (Arg.isInvalid()) |
| 4031 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | // FIXME: Wrong source location information for the ','. |
| 4034 | FakeCommaLocs.push_back( |
| 4035 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
| 4037 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4038 | Args.push_back(Arg.takeAs<Expr>()); |
| 4039 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4041 | if (!getDerived().AlwaysRebuild() && |
| 4042 | Callee.get() == E->getCallee() && |
| 4043 | !ArgChanged) |
| 4044 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4049 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4050 | move_arg(Args), |
| 4051 | FakeCommaLocs.data(), |
| 4052 | E->getRParenLoc()); |
| 4053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
| 4055 | template<typename Derived> |
| 4056 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4057 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4058 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4059 | if (Base.isInvalid()) |
| 4060 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4061 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4062 | NestedNameSpecifier *Qualifier = 0; |
| 4063 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4064 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4065 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4066 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4067 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4068 | return SemaRef.ExprError(); |
| 4069 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4070 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4071 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4072 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4073 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4074 | if (!Member) |
| 4075 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4077 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4078 | if (FoundDecl == E->getMemberDecl()) { |
| 4079 | FoundDecl = Member; |
| 4080 | } else { |
| 4081 | FoundDecl = cast_or_null<NamedDecl>( |
| 4082 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4083 | if (!FoundDecl) |
| 4084 | return SemaRef.ExprError(); |
| 4085 | } |
| 4086 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4087 | if (!getDerived().AlwaysRebuild() && |
| 4088 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4089 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4090 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4091 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4092 | !E->hasExplicitTemplateArgumentList()) { |
| 4093 | |
| 4094 | // Mark it referenced in the new context regardless. |
| 4095 | // FIXME: this is a bit instantiation-specific. |
| 4096 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4097 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4098 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4099 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4100 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4101 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4102 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4103 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4104 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4105 | TemplateArgumentLoc Loc; |
| 4106 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4107 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4108 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4109 | } |
| 4110 | } |
| 4111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4112 | // FIXME: Bogus source location for the operator |
| 4113 | SourceLocation FakeOperatorLoc |
| 4114 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4115 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4116 | // FIXME: to do this check properly, we will need to preserve the |
| 4117 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4118 | // base (and therefore couldn't do the check) and a |
| 4119 | // nested-name-qualifier (and therefore could do the lookup). |
| 4120 | NamedDecl *FirstQualifierInScope = 0; |
| 4121 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4122 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4123 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4124 | Qualifier, |
| 4125 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4126 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4127 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4128 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4129 | (E->hasExplicitTemplateArgumentList() |
| 4130 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4131 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4134 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4135 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4136 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4137 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4138 | if (LHS.isInvalid()) |
| 4139 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4142 | if (RHS.isInvalid()) |
| 4143 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4144 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4145 | if (!getDerived().AlwaysRebuild() && |
| 4146 | LHS.get() == E->getLHS() && |
| 4147 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | return SemaRef.Owned(E->Retain()); |
| 4149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4151 | move(LHS), move(RHS)); |
| 4152 | } |
| 4153 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | Sema::OwningExprResult |
| 4156 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4157 | CompoundAssignOperator *E) { |
| 4158 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4161 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4162 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4163 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4165 | if (Cond.isInvalid()) |
| 4166 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4168 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4169 | if (LHS.isInvalid()) |
| 4170 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4173 | if (RHS.isInvalid()) |
| 4174 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4176 | if (!getDerived().AlwaysRebuild() && |
| 4177 | Cond.get() == E->getCond() && |
| 4178 | LHS.get() == E->getLHS() && |
| 4179 | RHS.get() == E->getRHS()) |
| 4180 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | |
| 4182 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4183 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4185 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4186 | move(RHS)); |
| 4187 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | |
| 4189 | template<typename Derived> |
| 4190 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4191 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4192 | // Implicit casts are eliminated during transformation, since they |
| 4193 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4194 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4197 | template<typename Derived> |
| 4198 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4199 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4200 | TypeSourceInfo *OldT; |
| 4201 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | { |
| 4203 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4204 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4206 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4207 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4208 | OldT = E->getTypeInfoAsWritten(); |
| 4209 | NewT = getDerived().TransformType(OldT); |
| 4210 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | return SemaRef.ExprError(); |
| 4212 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4214 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4215 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4216 | if (SubExpr.isInvalid()) |
| 4217 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4220 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4221 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4222 | return SemaRef.Owned(E->Retain()); |
| 4223 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4224 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4225 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | E->getRParenLoc(), |
| 4227 | move(SubExpr)); |
| 4228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4230 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4231 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4232 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4233 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4234 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4235 | if (!NewT) |
| 4236 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4237 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4238 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4239 | if (Init.isInvalid()) |
| 4240 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4242 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4243 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4244 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4245 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4247 | // Note: the expression type doesn't necessarily match the |
| 4248 | // type-as-written, but that's okay, because it should always be |
| 4249 | // derivable from the initializer. |
| 4250 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4251 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4252 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4253 | move(Init)); |
| 4254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4256 | template<typename Derived> |
| 4257 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4258 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4259 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4260 | if (Base.isInvalid()) |
| 4261 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | if (!getDerived().AlwaysRebuild() && |
| 4264 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4265 | return SemaRef.Owned(E->Retain()); |
| 4266 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4267 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4268 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4269 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4270 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4271 | E->getAccessorLoc(), |
| 4272 | E->getAccessor()); |
| 4273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4274 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4275 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4276 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4277 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4280 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4281 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4282 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4283 | if (Init.isInvalid()) |
| 4284 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4286 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4287 | Inits.push_back(Init.takeAs<Expr>()); |
| 4288 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4289 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4290 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | return SemaRef.Owned(E->Retain()); |
| 4292 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4293 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4294 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4295 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4297 | template<typename Derived> |
| 4298 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4299 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4300 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4301 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4302 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4303 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4304 | if (Init.isInvalid()) |
| 4305 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4307 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4308 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4309 | bool ExprChanged = false; |
| 4310 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4311 | DEnd = E->designators_end(); |
| 4312 | D != DEnd; ++D) { |
| 4313 | if (D->isFieldDesignator()) { |
| 4314 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4315 | D->getDotLoc(), |
| 4316 | D->getFieldLoc())); |
| 4317 | continue; |
| 4318 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4319 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4320 | if (D->isArrayDesignator()) { |
| 4321 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4322 | if (Index.isInvalid()) |
| 4323 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | |
| 4325 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4329 | ArrayExprs.push_back(Index.release()); |
| 4330 | continue; |
| 4331 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4332 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4333 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4335 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4336 | if (Start.isInvalid()) |
| 4337 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4338 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4340 | if (End.isInvalid()) |
| 4341 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4342 | |
| 4343 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4344 | End.get(), |
| 4345 | D->getLBracketLoc(), |
| 4346 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4349 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4350 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | ArrayExprs.push_back(Start.release()); |
| 4352 | ArrayExprs.push_back(End.release()); |
| 4353 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4355 | if (!getDerived().AlwaysRebuild() && |
| 4356 | Init.get() == E->getInit() && |
| 4357 | !ExprChanged) |
| 4358 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4359 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4360 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4361 | E->getEqualOrColonLoc(), |
| 4362 | E->usesGNUSyntax(), move(Init)); |
| 4363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4364 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4365 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4368 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4369 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4370 | |
| 4371 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4372 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4373 | QualType T = getDerived().TransformType(E->getType()); |
| 4374 | if (T.isNull()) |
| 4375 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4376 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4377 | if (!getDerived().AlwaysRebuild() && |
| 4378 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4379 | return SemaRef.Owned(E->Retain()); |
| 4380 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4381 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4386 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4387 | // FIXME: Do we want the type as written? |
| 4388 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | { |
| 4391 | // FIXME: Source location isn't quite accurate. |
| 4392 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4393 | T = getDerived().TransformType(E->getType()); |
| 4394 | if (T.isNull()) |
| 4395 | return SemaRef.ExprError(); |
| 4396 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4399 | if (SubExpr.isInvalid()) |
| 4400 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | if (!getDerived().AlwaysRebuild() && |
| 4403 | T == E->getType() && |
| 4404 | SubExpr.get() == E->getSubExpr()) |
| 4405 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4406 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4407 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4408 | T, E->getRParenLoc()); |
| 4409 | } |
| 4410 | |
| 4411 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4413 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | bool ArgumentChanged = false; |
| 4415 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4416 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4417 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4418 | if (Init.isInvalid()) |
| 4419 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4422 | Inits.push_back(Init.takeAs<Expr>()); |
| 4423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4426 | move_arg(Inits), |
| 4427 | E->getRParenLoc()); |
| 4428 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4429 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4430 | /// \brief Transform an address-of-label expression. |
| 4431 | /// |
| 4432 | /// By default, the transformation of an address-of-label expression always |
| 4433 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4434 | /// the corresponding label statement by semantic analysis. |
| 4435 | template<typename Derived> |
| 4436 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4437 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4438 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4439 | E->getLabel()); |
| 4440 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
| 4442 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4443 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4444 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4447 | if (SubStmt.isInvalid()) |
| 4448 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4449 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4450 | if (!getDerived().AlwaysRebuild() && |
| 4451 | SubStmt.get() == E->getSubStmt()) |
| 4452 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4453 | |
| 4454 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4455 | move(SubStmt), |
| 4456 | E->getRParenLoc()); |
| 4457 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | template<typename Derived> |
| 4460 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4461 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4462 | QualType T1, T2; |
| 4463 | { |
| 4464 | // FIXME: Source location isn't quite accurate. |
| 4465 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4466 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4467 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4468 | if (T1.isNull()) |
| 4469 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4471 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4472 | if (T2.isNull()) |
| 4473 | return SemaRef.ExprError(); |
| 4474 | } |
| 4475 | |
| 4476 | if (!getDerived().AlwaysRebuild() && |
| 4477 | T1 == E->getArgType1() && |
| 4478 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | return SemaRef.Owned(E->Retain()); |
| 4480 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4481 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4482 | T1, T2, E->getRParenLoc()); |
| 4483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4485 | template<typename Derived> |
| 4486 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4487 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4489 | if (Cond.isInvalid()) |
| 4490 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4491 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4493 | if (LHS.isInvalid()) |
| 4494 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4495 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4496 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4497 | if (RHS.isInvalid()) |
| 4498 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4499 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4500 | if (!getDerived().AlwaysRebuild() && |
| 4501 | Cond.get() == E->getCond() && |
| 4502 | LHS.get() == E->getLHS() && |
| 4503 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | return SemaRef.Owned(E->Retain()); |
| 4505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4507 | move(Cond), move(LHS), move(RHS), |
| 4508 | E->getRParenLoc()); |
| 4509 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4513 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4514 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | template<typename Derived> |
| 4518 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4519 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4520 | switch (E->getOperator()) { |
| 4521 | case OO_New: |
| 4522 | case OO_Delete: |
| 4523 | case OO_Array_New: |
| 4524 | case OO_Array_Delete: |
| 4525 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4526 | return SemaRef.ExprError(); |
| 4527 | |
| 4528 | case OO_Call: { |
| 4529 | // This is a call to an object's operator(). |
| 4530 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4531 | |
| 4532 | // Transform the object itself. |
| 4533 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4534 | if (Object.isInvalid()) |
| 4535 | return SemaRef.ExprError(); |
| 4536 | |
| 4537 | // FIXME: Poor location information |
| 4538 | SourceLocation FakeLParenLoc |
| 4539 | = SemaRef.PP.getLocForEndOfToken( |
| 4540 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4541 | |
| 4542 | // Transform the call arguments. |
| 4543 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4544 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4545 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4546 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4547 | break; |
| 4548 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4549 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4550 | if (Arg.isInvalid()) |
| 4551 | return SemaRef.ExprError(); |
| 4552 | |
| 4553 | // FIXME: Poor source location information. |
| 4554 | SourceLocation FakeCommaLoc |
| 4555 | = SemaRef.PP.getLocForEndOfToken( |
| 4556 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4557 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4558 | Args.push_back(Arg.release()); |
| 4559 | } |
| 4560 | |
| 4561 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4562 | move_arg(Args), |
| 4563 | FakeCommaLocs.data(), |
| 4564 | E->getLocEnd()); |
| 4565 | } |
| 4566 | |
| 4567 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4568 | case OO_##Name: |
| 4569 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4570 | #include "clang/Basic/OperatorKinds.def" |
| 4571 | case OO_Subscript: |
| 4572 | // Handled below. |
| 4573 | break; |
| 4574 | |
| 4575 | case OO_Conditional: |
| 4576 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4577 | return SemaRef.ExprError(); |
| 4578 | |
| 4579 | case OO_None: |
| 4580 | case NUM_OVERLOADED_OPERATORS: |
| 4581 | llvm_unreachable("not an overloaded operator?"); |
| 4582 | return SemaRef.ExprError(); |
| 4583 | } |
| 4584 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4585 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4586 | if (Callee.isInvalid()) |
| 4587 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4589 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4590 | if (First.isInvalid()) |
| 4591 | return SemaRef.ExprError(); |
| 4592 | |
| 4593 | OwningExprResult Second(SemaRef); |
| 4594 | if (E->getNumArgs() == 2) { |
| 4595 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4596 | if (Second.isInvalid()) |
| 4597 | return SemaRef.ExprError(); |
| 4598 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4600 | if (!getDerived().AlwaysRebuild() && |
| 4601 | Callee.get() == E->getCallee() && |
| 4602 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4604 | return SemaRef.Owned(E->Retain()); |
| 4605 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4606 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4607 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4608 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4609 | move(First), |
| 4610 | move(Second)); |
| 4611 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4613 | template<typename Derived> |
| 4614 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4615 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4616 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4620 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4621 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4622 | TypeSourceInfo *OldT; |
| 4623 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4624 | { |
| 4625 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4626 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4627 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4628 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4629 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4630 | OldT = E->getTypeInfoAsWritten(); |
| 4631 | NewT = getDerived().TransformType(OldT); |
| 4632 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | return SemaRef.ExprError(); |
| 4634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4635 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4636 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4637 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | if (SubExpr.isInvalid()) |
| 4639 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4642 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | return SemaRef.Owned(E->Retain()); |
| 4645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4647 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4648 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4649 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4650 | SourceLocation FakeRParenLoc |
| 4651 | = SemaRef.PP.getLocForEndOfToken( |
| 4652 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4653 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4654 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4655 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4656 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4657 | FakeRAngleLoc, |
| 4658 | FakeRAngleLoc, |
| 4659 | move(SubExpr), |
| 4660 | FakeRParenLoc); |
| 4661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4663 | template<typename Derived> |
| 4664 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4665 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4666 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4668 | |
| 4669 | template<typename Derived> |
| 4670 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4671 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4672 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4675 | template<typename Derived> |
| 4676 | Sema::OwningExprResult |
| 4677 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4678 | CXXReinterpretCastExpr *E) { |
| 4679 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4681 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4682 | template<typename Derived> |
| 4683 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4684 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4685 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4686 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4688 | template<typename Derived> |
| 4689 | Sema::OwningExprResult |
| 4690 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4691 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4692 | TypeSourceInfo *OldT; |
| 4693 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4694 | { |
| 4695 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4697 | OldT = E->getTypeInfoAsWritten(); |
| 4698 | NewT = getDerived().TransformType(OldT); |
| 4699 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | return SemaRef.ExprError(); |
| 4701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4702 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4703 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4704 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4705 | if (SubExpr.isInvalid()) |
| 4706 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4707 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4708 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4709 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4710 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4711 | return SemaRef.Owned(E->Retain()); |
| 4712 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | // FIXME: The end of the type's source range is wrong |
| 4714 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4715 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4716 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4717 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4718 | move(SubExpr), |
| 4719 | E->getRParenLoc()); |
| 4720 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | template<typename Derived> |
| 4723 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4724 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | if (E->isTypeOperand()) { |
| 4726 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4728 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4729 | if (T.isNull()) |
| 4730 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4732 | if (!getDerived().AlwaysRebuild() && |
| 4733 | T == E->getTypeOperand()) |
| 4734 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4736 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4737 | /*FIXME:*/E->getLocStart(), |
| 4738 | T, |
| 4739 | E->getLocEnd()); |
| 4740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4742 | // We don't know whether the expression is potentially evaluated until |
| 4743 | // after we perform semantic analysis, so the expression is potentially |
| 4744 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4745 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4746 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4749 | if (SubExpr.isInvalid()) |
| 4750 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4751 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | if (!getDerived().AlwaysRebuild() && |
| 4753 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | return SemaRef.Owned(E->Retain()); |
| 4755 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4756 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4757 | /*FIXME:*/E->getLocStart(), |
| 4758 | move(SubExpr), |
| 4759 | E->getLocEnd()); |
| 4760 | } |
| 4761 | |
| 4762 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4764 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4766 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4768 | template<typename Derived> |
| 4769 | Sema::OwningExprResult |
| 4770 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4771 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4775 | template<typename Derived> |
| 4776 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4777 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4778 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | QualType T = getDerived().TransformType(E->getType()); |
| 4781 | if (T.isNull()) |
| 4782 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | if (!getDerived().AlwaysRebuild() && |
| 4785 | T == E->getType()) |
| 4786 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4788 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4789 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | template<typename Derived> |
| 4792 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4793 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4795 | if (SubExpr.isInvalid()) |
| 4796 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4798 | if (!getDerived().AlwaysRebuild() && |
| 4799 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4800 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | |
| 4802 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4805 | template<typename Derived> |
| 4806 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4807 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4808 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4809 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4810 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4811 | if (!Param) |
| 4812 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4814 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4815 | Param == E->getParam()) |
| 4816 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4818 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4819 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4821 | template<typename Derived> |
| 4822 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4823 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4824 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4825 | |
| 4826 | QualType T = getDerived().TransformType(E->getType()); |
| 4827 | if (T.isNull()) |
| 4828 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | if (!getDerived().AlwaysRebuild() && |
| 4831 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | return SemaRef.Owned(E->Retain()); |
| 4833 | |
| 4834 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4835 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4836 | T, |
| 4837 | E->getRParenLoc()); |
| 4838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4840 | template<typename Derived> |
| 4841 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4842 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4843 | // Transform the type that we're allocating |
| 4844 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4845 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4846 | if (AllocType.isNull()) |
| 4847 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4848 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4849 | // Transform the size of the array we're allocating (if any). |
| 4850 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4851 | if (ArraySize.isInvalid()) |
| 4852 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4853 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4854 | // Transform the placement arguments (if any). |
| 4855 | bool ArgumentChanged = false; |
| 4856 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4857 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4858 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4859 | if (Arg.isInvalid()) |
| 4860 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4862 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4863 | PlacementArgs.push_back(Arg.take()); |
| 4864 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4866 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4867 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4868 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4869 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4870 | if (Arg.isInvalid()) |
| 4871 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4872 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4873 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4874 | ConstructorArgs.push_back(Arg.take()); |
| 4875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4877 | // Transform constructor, new operator, and delete operator. |
| 4878 | CXXConstructorDecl *Constructor = 0; |
| 4879 | if (E->getConstructor()) { |
| 4880 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4881 | getDerived().TransformDecl(E->getLocStart(), |
| 4882 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4883 | if (!Constructor) |
| 4884 | return SemaRef.ExprError(); |
| 4885 | } |
| 4886 | |
| 4887 | FunctionDecl *OperatorNew = 0; |
| 4888 | if (E->getOperatorNew()) { |
| 4889 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4890 | getDerived().TransformDecl(E->getLocStart(), |
| 4891 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4892 | if (!OperatorNew) |
| 4893 | return SemaRef.ExprError(); |
| 4894 | } |
| 4895 | |
| 4896 | FunctionDecl *OperatorDelete = 0; |
| 4897 | if (E->getOperatorDelete()) { |
| 4898 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4899 | getDerived().TransformDecl(E->getLocStart(), |
| 4900 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4901 | if (!OperatorDelete) |
| 4902 | return SemaRef.ExprError(); |
| 4903 | } |
| 4904 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | if (!getDerived().AlwaysRebuild() && |
| 4906 | AllocType == E->getAllocatedType() && |
| 4907 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4908 | Constructor == E->getConstructor() && |
| 4909 | OperatorNew == E->getOperatorNew() && |
| 4910 | OperatorDelete == E->getOperatorDelete() && |
| 4911 | !ArgumentChanged) { |
| 4912 | // Mark any declarations we need as referenced. |
| 4913 | // FIXME: instantiation-specific. |
| 4914 | if (Constructor) |
| 4915 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4916 | if (OperatorNew) |
| 4917 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4918 | if (OperatorDelete) |
| 4919 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4920 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4922 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4923 | if (!ArraySize.get()) { |
| 4924 | // If no array size was specified, but the new expression was |
| 4925 | // instantiated with an array type (e.g., "new T" where T is |
| 4926 | // instantiated with "int[4]"), extract the outer bound from the |
| 4927 | // array type as our array size. We do this with constant and |
| 4928 | // dependently-sized array types. |
| 4929 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4930 | if (!ArrayT) { |
| 4931 | // Do nothing |
| 4932 | } else if (const ConstantArrayType *ConsArrayT |
| 4933 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4934 | ArraySize |
| 4935 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4936 | ConsArrayT->getSize(), |
| 4937 | SemaRef.Context.getSizeType(), |
| 4938 | /*FIXME:*/E->getLocStart())); |
| 4939 | AllocType = ConsArrayT->getElementType(); |
| 4940 | } else if (const DependentSizedArrayType *DepArrayT |
| 4941 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4942 | if (DepArrayT->getSizeExpr()) { |
| 4943 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4944 | AllocType = DepArrayT->getElementType(); |
| 4945 | } |
| 4946 | } |
| 4947 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4949 | E->isGlobalNew(), |
| 4950 | /*FIXME:*/E->getLocStart(), |
| 4951 | move_arg(PlacementArgs), |
| 4952 | /*FIXME:*/E->getLocStart(), |
| 4953 | E->isParenTypeId(), |
| 4954 | AllocType, |
| 4955 | /*FIXME:*/E->getLocStart(), |
| 4956 | /*FIXME:*/SourceRange(), |
| 4957 | move(ArraySize), |
| 4958 | /*FIXME:*/E->getLocStart(), |
| 4959 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4960 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4963 | template<typename Derived> |
| 4964 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4965 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4966 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4967 | if (Operand.isInvalid()) |
| 4968 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4969 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4970 | // Transform the delete operator, if known. |
| 4971 | FunctionDecl *OperatorDelete = 0; |
| 4972 | if (E->getOperatorDelete()) { |
| 4973 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4974 | getDerived().TransformDecl(E->getLocStart(), |
| 4975 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4976 | if (!OperatorDelete) |
| 4977 | return SemaRef.ExprError(); |
| 4978 | } |
| 4979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4980 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4981 | Operand.get() == E->getArgument() && |
| 4982 | OperatorDelete == E->getOperatorDelete()) { |
| 4983 | // Mark any declarations we need as referenced. |
| 4984 | // FIXME: instantiation-specific. |
| 4985 | if (OperatorDelete) |
| 4986 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4987 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4988 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4989 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4990 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4991 | E->isGlobalDelete(), |
| 4992 | E->isArrayForm(), |
| 4993 | move(Operand)); |
| 4994 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4996 | template<typename Derived> |
| 4997 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4998 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4999 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5000 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5001 | if (Base.isInvalid()) |
| 5002 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5003 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5004 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5005 | bool MayBePseudoDestructor = false; |
| 5006 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5007 | E->getOperatorLoc(), |
| 5008 | E->isArrow()? tok::arrow : tok::period, |
| 5009 | ObjectTypePtr, |
| 5010 | MayBePseudoDestructor); |
| 5011 | if (Base.isInvalid()) |
| 5012 | return SemaRef.ExprError(); |
| 5013 | |
| 5014 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5015 | NestedNameSpecifier *Qualifier |
| 5016 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5017 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5018 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5019 | if (E->getQualifier() && !Qualifier) |
| 5020 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5022 | PseudoDestructorTypeStorage Destroyed; |
| 5023 | if (E->getDestroyedTypeInfo()) { |
| 5024 | TypeSourceInfo *DestroyedTypeInfo |
| 5025 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5026 | if (!DestroyedTypeInfo) |
| 5027 | return SemaRef.ExprError(); |
| 5028 | Destroyed = DestroyedTypeInfo; |
| 5029 | } else if (ObjectType->isDependentType()) { |
| 5030 | // We aren't likely to be able to resolve the identifier down to a type |
| 5031 | // now anyway, so just retain the identifier. |
| 5032 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5033 | E->getDestroyedTypeLoc()); |
| 5034 | } else { |
| 5035 | // Look for a destructor known with the given name. |
| 5036 | CXXScopeSpec SS; |
| 5037 | if (Qualifier) { |
| 5038 | SS.setScopeRep(Qualifier); |
| 5039 | SS.setRange(E->getQualifierRange()); |
| 5040 | } |
| 5041 | |
| 5042 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5043 | *E->getDestroyedTypeIdentifier(), |
| 5044 | E->getDestroyedTypeLoc(), |
| 5045 | /*Scope=*/0, |
| 5046 | SS, ObjectTypePtr, |
| 5047 | false); |
| 5048 | if (!T) |
| 5049 | return SemaRef.ExprError(); |
| 5050 | |
| 5051 | Destroyed |
| 5052 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5053 | E->getDestroyedTypeLoc()); |
| 5054 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5055 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5056 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5057 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5058 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 5059 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5060 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5061 | return SemaRef.ExprError(); |
| 5062 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5063 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5064 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5065 | E->getOperatorLoc(), |
| 5066 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5067 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5068 | E->getQualifierRange(), |
| 5069 | ScopeTypeInfo, |
| 5070 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5071 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5072 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5074 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5075 | template<typename Derived> |
| 5076 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5077 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5078 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5079 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5080 | |
| 5081 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5082 | Sema::LookupOrdinaryName); |
| 5083 | |
| 5084 | // Transform all the decls. |
| 5085 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5086 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5087 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5088 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5089 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5090 | if (!InstD) { |
| 5091 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5092 | // This can happen because of dependent hiding. |
| 5093 | if (isa<UsingShadowDecl>(*I)) |
| 5094 | continue; |
| 5095 | else |
| 5096 | return SemaRef.ExprError(); |
| 5097 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5098 | |
| 5099 | // Expand using declarations. |
| 5100 | if (isa<UsingDecl>(InstD)) { |
| 5101 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5102 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5103 | E = UD->shadow_end(); I != E; ++I) |
| 5104 | R.addDecl(*I); |
| 5105 | continue; |
| 5106 | } |
| 5107 | |
| 5108 | R.addDecl(InstD); |
| 5109 | } |
| 5110 | |
| 5111 | // Resolve a kind, but don't do any further analysis. If it's |
| 5112 | // ambiguous, the callee needs to deal with it. |
| 5113 | R.resolveKind(); |
| 5114 | |
| 5115 | // Rebuild the nested-name qualifier, if present. |
| 5116 | CXXScopeSpec SS; |
| 5117 | NestedNameSpecifier *Qualifier = 0; |
| 5118 | if (Old->getQualifier()) { |
| 5119 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5120 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5121 | if (!Qualifier) |
| 5122 | return SemaRef.ExprError(); |
| 5123 | |
| 5124 | SS.setScopeRep(Qualifier); |
| 5125 | SS.setRange(Old->getQualifierRange()); |
| 5126 | } |
| 5127 | |
| 5128 | // If we have no template arguments, it's a normal declaration name. |
| 5129 | if (!Old->hasExplicitTemplateArgs()) |
| 5130 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5131 | |
| 5132 | // If we have template arguments, rebuild them, then rebuild the |
| 5133 | // templateid expression. |
| 5134 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5135 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5136 | TemplateArgumentLoc Loc; |
| 5137 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5138 | return SemaRef.ExprError(); |
| 5139 | TransArgs.addArgument(Loc); |
| 5140 | } |
| 5141 | |
| 5142 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5143 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5145 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5146 | template<typename Derived> |
| 5147 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5148 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5149 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5151 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5152 | if (T.isNull()) |
| 5153 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5155 | if (!getDerived().AlwaysRebuild() && |
| 5156 | T == E->getQueriedType()) |
| 5157 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5159 | // FIXME: Bad location information |
| 5160 | SourceLocation FakeLParenLoc |
| 5161 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5162 | |
| 5163 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5164 | E->getLocStart(), |
| 5165 | /*FIXME:*/FakeLParenLoc, |
| 5166 | T, |
| 5167 | E->getLocEnd()); |
| 5168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5170 | template<typename Derived> |
| 5171 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5173 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5174 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5175 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5176 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | if (!NNS) |
| 5178 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
| 5180 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5181 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5182 | if (!Name) |
| 5183 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5184 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5185 | if (!E->hasExplicitTemplateArgs()) { |
| 5186 | if (!getDerived().AlwaysRebuild() && |
| 5187 | NNS == E->getQualifier() && |
| 5188 | Name == E->getDeclName()) |
| 5189 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5191 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5192 | E->getQualifierRange(), |
| 5193 | Name, E->getLocation(), |
| 5194 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5195 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5196 | |
| 5197 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5198 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5199 | TemplateArgumentLoc Loc; |
| 5200 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5201 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5202 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5205 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5206 | E->getQualifierRange(), |
| 5207 | Name, E->getLocation(), |
| 5208 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | template<typename Derived> |
| 5212 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5213 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5214 | // CXXConstructExprs are always implicit, so when we have a |
| 5215 | // 1-argument construction we just transform that argument. |
| 5216 | if (E->getNumArgs() == 1 || |
| 5217 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5218 | return getDerived().TransformExpr(E->getArg(0)); |
| 5219 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5220 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5221 | |
| 5222 | QualType T = getDerived().TransformType(E->getType()); |
| 5223 | if (T.isNull()) |
| 5224 | return SemaRef.ExprError(); |
| 5225 | |
| 5226 | CXXConstructorDecl *Constructor |
| 5227 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5228 | getDerived().TransformDecl(E->getLocStart(), |
| 5229 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5230 | if (!Constructor) |
| 5231 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | bool ArgumentChanged = false; |
| 5234 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5235 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5236 | ArgEnd = E->arg_end(); |
| 5237 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5238 | if (getDerived().DropCallArgument(*Arg)) { |
| 5239 | ArgumentChanged = true; |
| 5240 | break; |
| 5241 | } |
| 5242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5243 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5244 | if (TransArg.isInvalid()) |
| 5245 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5247 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5248 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5249 | } |
| 5250 | |
| 5251 | if (!getDerived().AlwaysRebuild() && |
| 5252 | T == E->getType() && |
| 5253 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5254 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5255 | // Mark the constructor as referenced. |
| 5256 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5257 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5261 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5262 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5263 | move_arg(Args)); |
| 5264 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5265 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5266 | /// \brief Transform a C++ temporary-binding expression. |
| 5267 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5268 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5269 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5270 | template<typename Derived> |
| 5271 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5272 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5273 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5275 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5276 | /// \brief Transform a C++ reference-binding expression. |
| 5277 | /// |
| 5278 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5279 | /// transform the subexpression and return that. |
| 5280 | template<typename Derived> |
| 5281 | Sema::OwningExprResult |
| 5282 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5283 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5284 | } |
| 5285 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5286 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5287 | /// be destroyed after the expression is evaluated. |
| 5288 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5289 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5290 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5291 | template<typename Derived> |
| 5292 | Sema::OwningExprResult |
| 5293 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5294 | CXXExprWithTemporaries *E) { |
| 5295 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5298 | template<typename Derived> |
| 5299 | Sema::OwningExprResult |
| 5300 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5301 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5302 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5303 | QualType T = getDerived().TransformType(E->getType()); |
| 5304 | if (T.isNull()) |
| 5305 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5306 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5307 | CXXConstructorDecl *Constructor |
| 5308 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5309 | getDerived().TransformDecl(E->getLocStart(), |
| 5310 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5311 | if (!Constructor) |
| 5312 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5313 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5314 | bool ArgumentChanged = false; |
| 5315 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5316 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5318 | ArgEnd = E->arg_end(); |
| 5319 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5320 | if (getDerived().DropCallArgument(*Arg)) { |
| 5321 | ArgumentChanged = true; |
| 5322 | break; |
| 5323 | } |
| 5324 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5325 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5326 | if (TransArg.isInvalid()) |
| 5327 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5328 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5329 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5330 | Args.push_back((Expr *)TransArg.release()); |
| 5331 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5332 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5333 | if (!getDerived().AlwaysRebuild() && |
| 5334 | T == E->getType() && |
| 5335 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5336 | !ArgumentChanged) { |
| 5337 | // FIXME: Instantiation-specific |
| 5338 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5339 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5342 | // FIXME: Bogus location information |
| 5343 | SourceLocation CommaLoc; |
| 5344 | if (Args.size() > 1) { |
| 5345 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5346 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5347 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5348 | } |
| 5349 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5350 | T, |
| 5351 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5352 | move_arg(Args), |
| 5353 | &CommaLoc, |
| 5354 | E->getLocEnd()); |
| 5355 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5357 | template<typename Derived> |
| 5358 | Sema::OwningExprResult |
| 5359 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5360 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5361 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5362 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5363 | if (T.isNull()) |
| 5364 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5365 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5366 | bool ArgumentChanged = false; |
| 5367 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5368 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5369 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5370 | ArgEnd = E->arg_end(); |
| 5371 | Arg != ArgEnd; ++Arg) { |
| 5372 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5373 | if (TransArg.isInvalid()) |
| 5374 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5375 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5376 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5377 | FakeCommaLocs.push_back( |
| 5378 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5379 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5382 | if (!getDerived().AlwaysRebuild() && |
| 5383 | T == E->getTypeAsWritten() && |
| 5384 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5385 | return SemaRef.Owned(E->Retain()); |
| 5386 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5387 | // FIXME: we're faking the locations of the commas |
| 5388 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5389 | T, |
| 5390 | E->getLParenLoc(), |
| 5391 | move_arg(Args), |
| 5392 | FakeCommaLocs.data(), |
| 5393 | E->getRParenLoc()); |
| 5394 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5395 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5396 | template<typename Derived> |
| 5397 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5398 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5399 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5401 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5402 | Expr *OldBase; |
| 5403 | QualType BaseType; |
| 5404 | QualType ObjectType; |
| 5405 | if (!E->isImplicitAccess()) { |
| 5406 | OldBase = E->getBase(); |
| 5407 | Base = getDerived().TransformExpr(OldBase); |
| 5408 | if (Base.isInvalid()) |
| 5409 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5411 | // Start the member reference and compute the object's type. |
| 5412 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5413 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5414 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5415 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5416 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5417 | ObjectTy, |
| 5418 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5419 | if (Base.isInvalid()) |
| 5420 | return SemaRef.ExprError(); |
| 5421 | |
| 5422 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5423 | BaseType = ((Expr*) Base.get())->getType(); |
| 5424 | } else { |
| 5425 | OldBase = 0; |
| 5426 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5427 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5428 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5429 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5430 | // Transform the first part of the nested-name-specifier that qualifies |
| 5431 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5432 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5433 | = getDerived().TransformFirstQualifierInScope( |
| 5434 | E->getFirstQualifierFoundInScope(), |
| 5435 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5437 | NestedNameSpecifier *Qualifier = 0; |
| 5438 | if (E->getQualifier()) { |
| 5439 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5440 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5441 | ObjectType, |
| 5442 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5443 | if (!Qualifier) |
| 5444 | return SemaRef.ExprError(); |
| 5445 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5446 | |
| 5447 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5448 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5449 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5450 | if (!Name) |
| 5451 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5453 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5454 | // This is a reference to a member without an explicitly-specified |
| 5455 | // template argument list. Optimize for this common case. |
| 5456 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5457 | Base.get() == OldBase && |
| 5458 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5459 | Qualifier == E->getQualifier() && |
| 5460 | Name == E->getMember() && |
| 5461 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | return SemaRef.Owned(E->Retain()); |
| 5463 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5464 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5465 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5466 | E->isArrow(), |
| 5467 | E->getOperatorLoc(), |
| 5468 | Qualifier, |
| 5469 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5470 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5471 | Name, |
| 5472 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5473 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5474 | } |
| 5475 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5476 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5477 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5478 | TemplateArgumentLoc Loc; |
| 5479 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5480 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5481 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5482 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5483 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5484 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5485 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5486 | E->isArrow(), |
| 5487 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5488 | Qualifier, |
| 5489 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5490 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5491 | Name, |
| 5492 | E->getMemberLoc(), |
| 5493 | &TransArgs); |
| 5494 | } |
| 5495 | |
| 5496 | template<typename Derived> |
| 5497 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5498 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5499 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5500 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5501 | QualType BaseType; |
| 5502 | if (!Old->isImplicitAccess()) { |
| 5503 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5504 | if (Base.isInvalid()) |
| 5505 | return SemaRef.ExprError(); |
| 5506 | BaseType = ((Expr*) Base.get())->getType(); |
| 5507 | } else { |
| 5508 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5509 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5510 | |
| 5511 | NestedNameSpecifier *Qualifier = 0; |
| 5512 | if (Old->getQualifier()) { |
| 5513 | Qualifier |
| 5514 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5515 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5516 | if (Qualifier == 0) |
| 5517 | return SemaRef.ExprError(); |
| 5518 | } |
| 5519 | |
| 5520 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5521 | Sema::LookupOrdinaryName); |
| 5522 | |
| 5523 | // Transform all the decls. |
| 5524 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5525 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5526 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5527 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5528 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5529 | if (!InstD) { |
| 5530 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5531 | // This can happen because of dependent hiding. |
| 5532 | if (isa<UsingShadowDecl>(*I)) |
| 5533 | continue; |
| 5534 | else |
| 5535 | return SemaRef.ExprError(); |
| 5536 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5537 | |
| 5538 | // Expand using declarations. |
| 5539 | if (isa<UsingDecl>(InstD)) { |
| 5540 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5541 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5542 | E = UD->shadow_end(); I != E; ++I) |
| 5543 | R.addDecl(*I); |
| 5544 | continue; |
| 5545 | } |
| 5546 | |
| 5547 | R.addDecl(InstD); |
| 5548 | } |
| 5549 | |
| 5550 | R.resolveKind(); |
| 5551 | |
| 5552 | TemplateArgumentListInfo TransArgs; |
| 5553 | if (Old->hasExplicitTemplateArgs()) { |
| 5554 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5555 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5556 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5557 | TemplateArgumentLoc Loc; |
| 5558 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5559 | Loc)) |
| 5560 | return SemaRef.ExprError(); |
| 5561 | TransArgs.addArgument(Loc); |
| 5562 | } |
| 5563 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5564 | |
| 5565 | // FIXME: to do this check properly, we will need to preserve the |
| 5566 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5567 | // base (and therefore couldn't do the check) and a |
| 5568 | // nested-name-qualifier (and therefore could do the lookup). |
| 5569 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5570 | |
| 5571 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5572 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5573 | Old->getOperatorLoc(), |
| 5574 | Old->isArrow(), |
| 5575 | Qualifier, |
| 5576 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5577 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5578 | R, |
| 5579 | (Old->hasExplicitTemplateArgs() |
| 5580 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | template<typename Derived> |
| 5584 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5585 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5586 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5589 | template<typename Derived> |
| 5590 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5591 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5592 | TypeSourceInfo *EncodedTypeInfo |
| 5593 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5594 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5597 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5598 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5599 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5600 | |
| 5601 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5602 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5603 | E->getRParenLoc()); |
| 5604 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5605 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | template<typename Derived> |
| 5607 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5608 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5609 | // Transform arguments. |
| 5610 | bool ArgChanged = false; |
| 5611 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5612 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5613 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5614 | if (Arg.isInvalid()) |
| 5615 | return SemaRef.ExprError(); |
| 5616 | |
| 5617 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5618 | Args.push_back(Arg.takeAs<Expr>()); |
| 5619 | } |
| 5620 | |
| 5621 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5622 | // Class message: transform the receiver type. |
| 5623 | TypeSourceInfo *ReceiverTypeInfo |
| 5624 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5625 | if (!ReceiverTypeInfo) |
| 5626 | return SemaRef.ExprError(); |
| 5627 | |
| 5628 | // If nothing changed, just retain the existing message send. |
| 5629 | if (!getDerived().AlwaysRebuild() && |
| 5630 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5631 | return SemaRef.Owned(E->Retain()); |
| 5632 | |
| 5633 | // Build a new class message send. |
| 5634 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5635 | E->getSelector(), |
| 5636 | E->getMethodDecl(), |
| 5637 | E->getLeftLoc(), |
| 5638 | move_arg(Args), |
| 5639 | E->getRightLoc()); |
| 5640 | } |
| 5641 | |
| 5642 | // Instance message: transform the receiver |
| 5643 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5644 | "Only class and instance messages may be instantiated"); |
| 5645 | OwningExprResult Receiver |
| 5646 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5647 | if (Receiver.isInvalid()) |
| 5648 | return SemaRef.ExprError(); |
| 5649 | |
| 5650 | // If nothing changed, just retain the existing message send. |
| 5651 | if (!getDerived().AlwaysRebuild() && |
| 5652 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5653 | return SemaRef.Owned(E->Retain()); |
| 5654 | |
| 5655 | // Build a new instance message send. |
| 5656 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5657 | E->getSelector(), |
| 5658 | E->getMethodDecl(), |
| 5659 | E->getLeftLoc(), |
| 5660 | move_arg(Args), |
| 5661 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5662 | } |
| 5663 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | template<typename Derived> |
| 5665 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5666 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5667 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5668 | } |
| 5669 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | template<typename Derived> |
| 5671 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5672 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5673 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | template<typename Derived> |
| 5677 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5678 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5679 | // FIXME: Implement this! |
| 5680 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5681 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5684 | template<typename Derived> |
| 5685 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5686 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5687 | // FIXME: Implement this! |
| 5688 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | } |
| 5691 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5692 | template<typename Derived> |
| 5693 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5694 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5695 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5696 | // FIXME: Implement this! |
| 5697 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5698 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5699 | } |
| 5700 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | template<typename Derived> |
| 5702 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5703 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 5704 | // Can never occur in a dependent context. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5705 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5708 | template<typename Derived> |
| 5709 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5710 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5711 | // FIXME: Implement this! |
| 5712 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5713 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5714 | } |
| 5715 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5716 | template<typename Derived> |
| 5717 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5718 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5719 | bool ArgumentChanged = false; |
| 5720 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5721 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5722 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5723 | if (SubExpr.isInvalid()) |
| 5724 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5725 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5726 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5727 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5728 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | if (!getDerived().AlwaysRebuild() && |
| 5731 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | return SemaRef.Owned(E->Retain()); |
| 5733 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5734 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5735 | move_arg(SubExprs), |
| 5736 | E->getRParenLoc()); |
| 5737 | } |
| 5738 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5739 | template<typename Derived> |
| 5740 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5741 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5742 | // FIXME: Implement this! |
| 5743 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5744 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5747 | template<typename Derived> |
| 5748 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5749 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5750 | // FIXME: Implement this! |
| 5751 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5752 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5755 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5756 | // Type reconstruction |
| 5757 | //===----------------------------------------------------------------------===// |
| 5758 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5759 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5760 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5761 | SourceLocation Star) { |
| 5762 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5763 | getDerived().getBaseEntity()); |
| 5764 | } |
| 5765 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5766 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5767 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5768 | SourceLocation Star) { |
| 5769 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5770 | getDerived().getBaseEntity()); |
| 5771 | } |
| 5772 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5773 | template<typename Derived> |
| 5774 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5775 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5776 | bool WrittenAsLValue, |
| 5777 | SourceLocation Sigil) { |
| 5778 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5779 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
| 5782 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5783 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5784 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5785 | QualType ClassType, |
| 5786 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5787 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5788 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5792 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5793 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5794 | ArrayType::ArraySizeModifier SizeMod, |
| 5795 | const llvm::APInt *Size, |
| 5796 | Expr *SizeExpr, |
| 5797 | unsigned IndexTypeQuals, |
| 5798 | SourceRange BracketsRange) { |
| 5799 | if (SizeExpr || !Size) |
| 5800 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5801 | IndexTypeQuals, BracketsRange, |
| 5802 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | |
| 5804 | QualType Types[] = { |
| 5805 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5806 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5807 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5808 | }; |
| 5809 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5810 | QualType SizeType; |
| 5811 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5812 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5813 | SizeType = Types[I]; |
| 5814 | break; |
| 5815 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5817 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5818 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5819 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5820 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5821 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5822 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5823 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5824 | QualType |
| 5825 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5826 | ArrayType::ArraySizeModifier SizeMod, |
| 5827 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5828 | unsigned IndexTypeQuals, |
| 5829 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5830 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5831 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5835 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5836 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5837 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5838 | unsigned IndexTypeQuals, |
| 5839 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5840 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5841 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5843 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5844 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5845 | QualType |
| 5846 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5847 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5848 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5849 | unsigned IndexTypeQuals, |
| 5850 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5851 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5852 | SizeExpr.takeAs<Expr>(), |
| 5853 | IndexTypeQuals, BracketsRange); |
| 5854 | } |
| 5855 | |
| 5856 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5857 | QualType |
| 5858 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5859 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5860 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5861 | unsigned IndexTypeQuals, |
| 5862 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5863 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5864 | SizeExpr.takeAs<Expr>(), |
| 5865 | IndexTypeQuals, BracketsRange); |
| 5866 | } |
| 5867 | |
| 5868 | template<typename Derived> |
| 5869 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5870 | unsigned NumElements, |
| 5871 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5872 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5873 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5874 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5876 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5877 | template<typename Derived> |
| 5878 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5879 | unsigned NumElements, |
| 5880 | SourceLocation AttributeLoc) { |
| 5881 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5882 | NumElements, true); |
| 5883 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5884 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5885 | AttributeLoc); |
| 5886 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5887 | AttributeLoc); |
| 5888 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5889 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5890 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5891 | QualType |
| 5892 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5893 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5894 | SourceLocation AttributeLoc) { |
| 5895 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5896 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5897 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5898 | template<typename Derived> |
| 5899 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5901 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5902 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5903 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5904 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5905 | Quals, |
| 5906 | getDerived().getBaseLocation(), |
| 5907 | getDerived().getBaseEntity()); |
| 5908 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5909 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5910 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5911 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5912 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5913 | } |
| 5914 | |
| 5915 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5916 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5917 | assert(D && "no decl found"); |
| 5918 | if (D->isInvalidDecl()) return QualType(); |
| 5919 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5920 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5921 | TypeDecl *Ty; |
| 5922 | if (isa<UsingDecl>(D)) { |
| 5923 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5924 | assert(Using->isTypeName() && |
| 5925 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5926 | |
| 5927 | // A valid resolved using typename decl points to exactly one type decl. |
| 5928 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5929 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5930 | |
| 5931 | } else { |
| 5932 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5933 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5934 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5935 | } |
| 5936 | |
| 5937 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5938 | } |
| 5939 | |
| 5940 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5941 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5942 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5943 | } |
| 5944 | |
| 5945 | template<typename Derived> |
| 5946 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5947 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5948 | } |
| 5949 | |
| 5950 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5951 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5952 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5953 | } |
| 5954 | |
| 5955 | template<typename Derived> |
| 5956 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5957 | TemplateName Template, |
| 5958 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5959 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5960 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5962 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5963 | template<typename Derived> |
| 5964 | NestedNameSpecifier * |
| 5965 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5966 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5967 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5968 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5969 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5970 | CXXScopeSpec SS; |
| 5971 | // FIXME: The source location information is all wrong. |
| 5972 | SS.setRange(Range); |
| 5973 | SS.setScopeRep(Prefix); |
| 5974 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5975 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5976 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5977 | ObjectType, |
| 5978 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5979 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | template<typename Derived> |
| 5983 | NestedNameSpecifier * |
| 5984 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5985 | SourceRange Range, |
| 5986 | NamespaceDecl *NS) { |
| 5987 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5988 | } |
| 5989 | |
| 5990 | template<typename Derived> |
| 5991 | NestedNameSpecifier * |
| 5992 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5993 | SourceRange Range, |
| 5994 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5995 | QualType T) { |
| 5996 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5997 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5998 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5999 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6000 | T.getTypePtr()); |
| 6001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6002 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6003 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6004 | return 0; |
| 6005 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6006 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6007 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6008 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6009 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6010 | bool TemplateKW, |
| 6011 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6012 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6013 | Template); |
| 6014 | } |
| 6015 | |
| 6016 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6017 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6018 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6019 | const IdentifierInfo &II, |
| 6020 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6021 | CXXScopeSpec SS; |
| 6022 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6024 | UnqualifiedId Name; |
| 6025 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6026 | return getSema().ActOnDependentTemplateName( |
| 6027 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6028 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6029 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6030 | ObjectType.getAsOpaquePtr(), |
| 6031 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6032 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6033 | } |
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 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6036 | TemplateName |
| 6037 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6038 | OverloadedOperatorKind Operator, |
| 6039 | QualType ObjectType) { |
| 6040 | CXXScopeSpec SS; |
| 6041 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6042 | SS.setScopeRep(Qualifier); |
| 6043 | UnqualifiedId Name; |
| 6044 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6045 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6046 | Operator, SymbolLocations); |
| 6047 | return getSema().ActOnDependentTemplateName( |
| 6048 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6049 | SS, |
| 6050 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6051 | ObjectType.getAsOpaquePtr(), |
| 6052 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6053 | .template getAsVal<TemplateName>(); |
| 6054 | } |
| 6055 | |
| 6056 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6057 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6058 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6059 | SourceLocation OpLoc, |
| 6060 | ExprArg Callee, |
| 6061 | ExprArg First, |
| 6062 | ExprArg Second) { |
| 6063 | Expr *FirstExpr = (Expr *)First.get(); |
| 6064 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6065 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6066 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6068 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6069 | if (Op == OO_Subscript) { |
| 6070 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6071 | !SecondExpr->getType()->isOverloadableType()) |
| 6072 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6073 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6074 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6075 | } else if (Op == OO_Arrow) { |
| 6076 | // -> is never a builtin operation. |
| 6077 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6078 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6079 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6080 | // The argument is not of overloadable type, so try to create a |
| 6081 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6083 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6084 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6085 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6086 | } |
| 6087 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6088 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6089 | !SecondExpr->getType()->isOverloadableType()) { |
| 6090 | // Neither of the arguments is an overloadable type, so try to |
| 6091 | // create a built-in binary operation. |
| 6092 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6093 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6094 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6095 | if (Result.isInvalid()) |
| 6096 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6098 | First.release(); |
| 6099 | Second.release(); |
| 6100 | return move(Result); |
| 6101 | } |
| 6102 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6103 | |
| 6104 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6105 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6106 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6107 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6108 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6109 | assert(ULE->requiresADL()); |
| 6110 | |
| 6111 | // FIXME: Do we have to check |
| 6112 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6113 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6114 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6115 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 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 | // Add any functions found via argument-dependent lookup. |
| 6119 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6120 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6121 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6122 | // Create the overloaded operator invocation for unary operators. |
| 6123 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6124 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6125 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6126 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6127 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6128 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6129 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6130 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6131 | OpLoc, |
| 6132 | move(First), |
| 6133 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6134 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6135 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6136 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6137 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6138 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6139 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6140 | if (Result.isInvalid()) |
| 6141 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6142 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6143 | First.release(); |
| 6144 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6145 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6147 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6148 | template<typename Derived> |
| 6149 | Sema::OwningExprResult |
| 6150 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6151 | SourceLocation OperatorLoc, |
| 6152 | bool isArrow, |
| 6153 | NestedNameSpecifier *Qualifier, |
| 6154 | SourceRange QualifierRange, |
| 6155 | TypeSourceInfo *ScopeType, |
| 6156 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6157 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6158 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6159 | CXXScopeSpec SS; |
| 6160 | if (Qualifier) { |
| 6161 | SS.setRange(QualifierRange); |
| 6162 | SS.setScopeRep(Qualifier); |
| 6163 | } |
| 6164 | |
| 6165 | Expr *BaseE = (Expr *)Base.get(); |
| 6166 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6167 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6168 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 6169 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6170 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6171 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6172 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6173 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6174 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6175 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6176 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6177 | /*FIXME?*/true); |
| 6178 | } |
| 6179 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6180 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6181 | DeclarationName Name |
| 6182 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6183 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 6184 | |
| 6185 | // FIXME: the ScopeType should be tacked onto SS. |
| 6186 | |
| 6187 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6188 | OperatorLoc, isArrow, |
| 6189 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6190 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6191 | /*TemplateArgs*/ 0); |
| 6192 | } |
| 6193 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6194 | } // end namespace clang |
| 6195 | |
| 6196 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |