John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | 577f75a | 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 | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | b98b199 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 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 | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | b98b199 | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 99 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | 577f75a | 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 | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 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 | 577f75a | 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 | 6eef519 | 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 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | a2becad | 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 | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 194 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | a2becad | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | a2becad | 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. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 205 | QualType ObjectType = QualType()); |
John McCall | a2becad | 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 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 212 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | b98b199 | 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 | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | 577f75a | 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 | dcee1a1 | 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 | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 240 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 247 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | 6cd2198 | 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 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 253 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 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. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 259 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | 81499bb | 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 | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 1eb4433 | 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 | 670444e | 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 | 833ca99 | 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 | a93c934 | 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 | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | 124b878 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 21ef0fa | 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 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 334 | QualType ObjectType); |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 336 | QualType |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | d8383d4 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 347 | #define ABSTRACT(Stmt) |
| 348 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | 577f75a | 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 | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 85737a7 | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 85737a7 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | 577f75a | 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 | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 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 | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | a2becad | 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 | ed97649 | 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 | 577f75a | 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 | 7da2431 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
| 500 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 504 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 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 | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 515 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | 577f75a | 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 | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 524 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// \brief Build a new qualified name type. |
| 527 | /// |
Mike Stump | 1eb4433 | 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 | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | |
| 535 | /// \brief Build a new typename type that refers to a template-id. |
| 536 | /// |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 537 | /// By default, builds a new DependentNameType type from the |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 538 | /// nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 541 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 542 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 543 | if (NNS->isDependent()) { |
Douglas Gregor | 4033642 | 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 | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 548 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 552 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | } |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 561 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 562 | NestedNameSpecifier *NNS, |
| 563 | const IdentifierInfo *Id, |
| 564 | SourceRange SR) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 565 | CXXScopeSpec SS; |
| 566 | SS.setScopeRep(NNS); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 567 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 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: |
Douglas Gregor | 107de90 | 2010-04-24 15:35:55 +0000 | [diff] [blame] | 577 | // Fall through. |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 578 | case ETK_Typename: |
Douglas Gregor | 107de90 | 2010-04-24 15:35:55 +0000 | [diff] [blame] | 579 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 580 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 581 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 582 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 583 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 584 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 585 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 586 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 587 | // We had a dependent elaborated-type-specifier that as been transformed |
| 588 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 589 | // referring to. |
| 590 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 591 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 592 | if (!DC) |
| 593 | return QualType(); |
| 594 | |
| 595 | TagDecl *Tag = 0; |
| 596 | SemaRef.LookupQualifiedName(Result, DC); |
| 597 | switch (Result.getResultKind()) { |
| 598 | case LookupResult::NotFound: |
| 599 | case LookupResult::NotFoundInCurrentInstantiation: |
| 600 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 602 | case LookupResult::Found: |
| 603 | Tag = Result.getAsSingle<TagDecl>(); |
| 604 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 606 | case LookupResult::FoundOverloaded: |
| 607 | case LookupResult::FoundUnresolvedValue: |
| 608 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 609 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 611 | case LookupResult::Ambiguous: |
| 612 | // Let the LookupResult structure handle ambiguities. |
| 613 | return QualType(); |
| 614 | } |
| 615 | |
| 616 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 617 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 618 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 619 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 620 | return QualType(); |
| 621 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 622 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 623 | // FIXME: Terrible location information |
| 624 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 625 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 626 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 627 | return QualType(); |
| 628 | } |
| 629 | |
| 630 | // Build the elaborated-type-specifier type. |
| 631 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 632 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 633 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 636 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 637 | /// identifier that names the next step in the nested-name-specifier. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the new |
| 640 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 641 | /// different behavior. |
| 642 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 643 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 644 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 645 | QualType ObjectType, |
| 646 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 647 | |
| 648 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 649 | /// namespace named in the next step in the nested-name-specifier. |
| 650 | /// |
| 651 | /// By default, performs semantic analysis when building the new |
| 652 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 653 | /// different behavior. |
| 654 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 655 | SourceRange Range, |
| 656 | NamespaceDecl *NS); |
| 657 | |
| 658 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 659 | /// type named in the next step in the nested-name-specifier. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis when building the new |
| 662 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 663 | /// different behavior. |
| 664 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 665 | SourceRange Range, |
| 666 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 667 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 668 | |
| 669 | /// \brief Build a new template name given a nested name specifier, a flag |
| 670 | /// indicating whether the "template" keyword was provided, and the template |
| 671 | /// that the template name refers to. |
| 672 | /// |
| 673 | /// By default, builds the new template name directly. Subclasses may override |
| 674 | /// this routine to provide different behavior. |
| 675 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 676 | bool TemplateKW, |
| 677 | TemplateDecl *Template); |
| 678 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 679 | /// \brief Build a new template name given a nested name specifier and the |
| 680 | /// name that is referred to as a template. |
| 681 | /// |
| 682 | /// By default, performs semantic analysis to determine whether the name can |
| 683 | /// be resolved to a specific template, then builds the appropriate kind of |
| 684 | /// template name. Subclasses may override this routine to provide different |
| 685 | /// behavior. |
| 686 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 687 | const IdentifierInfo &II, |
| 688 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 690 | /// \brief Build a new template name given a nested name specifier and the |
| 691 | /// overloaded operator name that is referred to as a template. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis to determine whether the name can |
| 694 | /// be resolved to a specific template, then builds the appropriate kind of |
| 695 | /// template name. Subclasses may override this routine to provide different |
| 696 | /// behavior. |
| 697 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 698 | OverloadedOperatorKind Operator, |
| 699 | QualType ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 700 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 701 | /// \brief Build a new compound statement. |
| 702 | /// |
| 703 | /// By default, performs semantic analysis to build the new statement. |
| 704 | /// Subclasses may override this routine to provide different behavior. |
| 705 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 706 | MultiStmtArg Statements, |
| 707 | SourceLocation RBraceLoc, |
| 708 | bool IsStmtExpr) { |
| 709 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 710 | IsStmtExpr); |
| 711 | } |
| 712 | |
| 713 | /// \brief Build a new case statement. |
| 714 | /// |
| 715 | /// By default, performs semantic analysis to build the new statement. |
| 716 | /// Subclasses may override this routine to provide different behavior. |
| 717 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 718 | ExprArg LHS, |
| 719 | SourceLocation EllipsisLoc, |
| 720 | ExprArg RHS, |
| 721 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 723 | ColonLoc); |
| 724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | /// \brief Attach the body to a new case statement. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis to build the new statement. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
| 730 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 731 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 732 | return move(S); |
| 733 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | /// \brief Build a new default statement. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis to build the new statement. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | SourceLocation ColonLoc, |
| 741 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 743 | /*CurScope=*/0); |
| 744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 746 | /// \brief Build a new label statement. |
| 747 | /// |
| 748 | /// By default, performs semantic analysis to build the new statement. |
| 749 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 751 | IdentifierInfo *Id, |
| 752 | SourceLocation ColonLoc, |
| 753 | StmtArg SubStmt) { |
| 754 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 755 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 757 | /// \brief Build a new "if" statement. |
| 758 | /// |
| 759 | /// By default, performs semantic analysis to build the new statement. |
| 760 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 761 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 762 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 763 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 764 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 765 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 768 | /// \brief Start building a new switch statement. |
| 769 | /// |
| 770 | /// By default, performs semantic analysis to build the new statement. |
| 771 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 772 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 773 | Sema::ExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 774 | VarDecl *CondVar) { |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 775 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 776 | DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 779 | /// \brief Attach the body to the switch statement. |
| 780 | /// |
| 781 | /// By default, performs semantic analysis to build the new statement. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 784 | StmtArg Switch, StmtArg Body) { |
| 785 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 786 | move(Body)); |
| 787 | } |
| 788 | |
| 789 | /// \brief Build a new while statement. |
| 790 | /// |
| 791 | /// By default, performs semantic analysis to build the new statement. |
| 792 | /// Subclasses may override this routine to provide different behavior. |
| 793 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 794 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 795 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 796 | StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 797 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 798 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | /// \brief Build a new do-while statement. |
| 802 | /// |
| 803 | /// By default, performs semantic analysis to build the new statement. |
| 804 | /// Subclasses may override this routine to provide different behavior. |
| 805 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 806 | SourceLocation WhileLoc, |
| 807 | SourceLocation LParenLoc, |
| 808 | ExprArg Cond, |
| 809 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 810 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 811 | move(Cond), RParenLoc); |
| 812 | } |
| 813 | |
| 814 | /// \brief Build a new for statement. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis to build the new statement. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 818 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 819 | SourceLocation LParenLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 820 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 821 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 822 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 823 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 824 | DeclPtrTy::make(CondVar), |
| 825 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 826 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 828 | /// \brief Build a new goto statement. |
| 829 | /// |
| 830 | /// By default, performs semantic analysis to build the new statement. |
| 831 | /// Subclasses may override this routine to provide different behavior. |
| 832 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 833 | SourceLocation LabelLoc, |
| 834 | LabelStmt *Label) { |
| 835 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 836 | } |
| 837 | |
| 838 | /// \brief Build a new indirect goto statement. |
| 839 | /// |
| 840 | /// By default, performs semantic analysis to build the new statement. |
| 841 | /// Subclasses may override this routine to provide different behavior. |
| 842 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 843 | SourceLocation StarLoc, |
| 844 | ExprArg Target) { |
| 845 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 847 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 848 | /// \brief Build a new return statement. |
| 849 | /// |
| 850 | /// By default, performs semantic analysis to build the new statement. |
| 851 | /// Subclasses may override this routine to provide different behavior. |
| 852 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 853 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 855 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 856 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 858 | /// \brief Build a new declaration statement. |
| 859 | /// |
| 860 | /// By default, performs semantic analysis to build the new statement. |
| 861 | /// Subclasses may override this routine to provide different behavior. |
| 862 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 864 | SourceLocation EndLoc) { |
| 865 | return getSema().Owned( |
| 866 | new (getSema().Context) DeclStmt( |
| 867 | DeclGroupRef::Create(getSema().Context, |
| 868 | Decls, NumDecls), |
| 869 | StartLoc, EndLoc)); |
| 870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 872 | /// \brief Build a new inline asm statement. |
| 873 | /// |
| 874 | /// By default, performs semantic analysis to build the new statement. |
| 875 | /// Subclasses may override this routine to provide different behavior. |
| 876 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 877 | bool IsSimple, |
| 878 | bool IsVolatile, |
| 879 | unsigned NumOutputs, |
| 880 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 881 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 882 | MultiExprArg Constraints, |
| 883 | MultiExprArg Exprs, |
| 884 | ExprArg AsmString, |
| 885 | MultiExprArg Clobbers, |
| 886 | SourceLocation RParenLoc, |
| 887 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 888 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 889 | NumInputs, Names, move(Constraints), |
| 890 | move(Exprs), move(AsmString), move(Clobbers), |
| 891 | RParenLoc, MSAsm); |
| 892 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 893 | |
| 894 | /// \brief Build a new Objective-C @try statement. |
| 895 | /// |
| 896 | /// By default, performs semantic analysis to build the new statement. |
| 897 | /// Subclasses may override this routine to provide different behavior. |
| 898 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 899 | StmtArg TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 900 | MultiStmtArg CatchStmts, |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 901 | StmtArg Finally) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 902 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 903 | move(Finally)); |
| 904 | } |
| 905 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 906 | /// \brief Rebuild an Objective-C exception declaration. |
| 907 | /// |
| 908 | /// By default, performs semantic analysis to build the new declaration. |
| 909 | /// Subclasses may override this routine to provide different behavior. |
| 910 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 911 | TypeSourceInfo *TInfo, QualType T) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 912 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 913 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 914 | ExceptionDecl->getLocation()); |
| 915 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 916 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 917 | /// \brief Build a new Objective-C @catch statement. |
| 918 | /// |
| 919 | /// By default, performs semantic analysis to build the new statement. |
| 920 | /// Subclasses may override this routine to provide different behavior. |
| 921 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 922 | SourceLocation RParenLoc, |
| 923 | VarDecl *Var, |
| 924 | StmtArg Body) { |
| 925 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 926 | Sema::DeclPtrTy::make(Var), |
| 927 | move(Body)); |
| 928 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 930 | /// \brief Build a new Objective-C @finally statement. |
| 931 | /// |
| 932 | /// By default, performs semantic analysis to build the new statement. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
| 934 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 935 | StmtArg Body) { |
| 936 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 937 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 938 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 939 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 940 | /// |
| 941 | /// By default, performs semantic analysis to build the new statement. |
| 942 | /// Subclasses may override this routine to provide different behavior. |
| 943 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 944 | ExprArg Operand) { |
| 945 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 946 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 947 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 948 | /// \brief Build a new Objective-C @synchronized statement. |
| 949 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 950 | /// By default, performs semantic analysis to build the new statement. |
| 951 | /// Subclasses may override this routine to provide different behavior. |
| 952 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 953 | ExprArg Object, |
| 954 | StmtArg Body) { |
| 955 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 956 | move(Body)); |
| 957 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 958 | |
| 959 | /// \brief Build a new Objective-C fast enumeration statement. |
| 960 | /// |
| 961 | /// By default, performs semantic analysis to build the new statement. |
| 962 | /// Subclasses may override this routine to provide different behavior. |
| 963 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 964 | SourceLocation LParenLoc, |
| 965 | StmtArg Element, |
| 966 | ExprArg Collection, |
| 967 | SourceLocation RParenLoc, |
| 968 | StmtArg Body) { |
| 969 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 970 | move(Element), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 971 | move(Collection), |
| 972 | RParenLoc, |
| 973 | move(Body)); |
| 974 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 975 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 976 | /// \brief Build a new C++ exception declaration. |
| 977 | /// |
| 978 | /// By default, performs semantic analysis to build the new decaration. |
| 979 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 981 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 982 | IdentifierInfo *Name, |
| 983 | SourceLocation Loc, |
| 984 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 986 | TypeRange); |
| 987 | } |
| 988 | |
| 989 | /// \brief Build a new C++ catch statement. |
| 990 | /// |
| 991 | /// By default, performs semantic analysis to build the new statement. |
| 992 | /// Subclasses may override this routine to provide different behavior. |
| 993 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 994 | VarDecl *ExceptionDecl, |
| 995 | StmtArg Handler) { |
| 996 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 997 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 998 | Handler.takeAs<Stmt>())); |
| 999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1001 | /// \brief Build a new C++ try statement. |
| 1002 | /// |
| 1003 | /// By default, performs semantic analysis to build the new statement. |
| 1004 | /// Subclasses may override this routine to provide different behavior. |
| 1005 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1006 | StmtArg TryBlock, |
| 1007 | MultiStmtArg Handlers) { |
| 1008 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1011 | /// \brief Build a new expression that references a declaration. |
| 1012 | /// |
| 1013 | /// By default, performs semantic analysis to build the new expression. |
| 1014 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1015 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1016 | LookupResult &R, |
| 1017 | bool RequiresADL) { |
| 1018 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | /// \brief Build a new expression that references a declaration. |
| 1023 | /// |
| 1024 | /// By default, performs semantic analysis to build the new expression. |
| 1025 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1026 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1027 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1028 | ValueDecl *VD, SourceLocation Loc, |
| 1029 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1030 | CXXScopeSpec SS; |
| 1031 | SS.setScopeRep(Qualifier); |
| 1032 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1033 | |
| 1034 | // FIXME: loses template args. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1035 | |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1036 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1041 | /// By default, performs semantic analysis to build the new expression. |
| 1042 | /// Subclasses may override this routine to provide different behavior. |
| 1043 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1044 | SourceLocation RParen) { |
| 1045 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1046 | } |
| 1047 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1048 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1050 | /// By default, performs semantic analysis to build the new expression. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
| 1052 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1053 | SourceLocation OperatorLoc, |
| 1054 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1055 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1056 | SourceRange QualifierRange, |
| 1057 | TypeSourceInfo *ScopeType, |
| 1058 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1059 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1060 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1064 | /// By default, performs semantic analysis to build the new expression. |
| 1065 | /// Subclasses may override this routine to provide different behavior. |
| 1066 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1067 | UnaryOperator::Opcode Opc, |
| 1068 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1069 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1072 | /// \brief Build a new builtin offsetof expression. |
| 1073 | /// |
| 1074 | /// By default, performs semantic analysis to build the new expression. |
| 1075 | /// Subclasses may override this routine to provide different behavior. |
| 1076 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1077 | TypeSourceInfo *Type, |
| 1078 | Action::OffsetOfComponent *Components, |
| 1079 | unsigned NumComponents, |
| 1080 | SourceLocation RParenLoc) { |
| 1081 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1082 | NumComponents, RParenLoc); |
| 1083 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1085 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1087 | /// By default, performs semantic analysis to build the new expression. |
| 1088 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1089 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1090 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1091 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1092 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1096 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | /// By default, performs semantic analysis to build the new expression. |
| 1099 | /// Subclasses may override this routine to provide different behavior. |
| 1100 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1101 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1104 | OpLoc, isSizeOf, R); |
| 1105 | if (Result.isInvalid()) |
| 1106 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | SubExpr.release(); |
| 1109 | return move(Result); |
| 1110 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1112 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1114 | /// By default, performs semantic analysis to build the new expression. |
| 1115 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | SourceLocation LBracketLoc, |
| 1118 | ExprArg RHS, |
| 1119 | SourceLocation RBracketLoc) { |
| 1120 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | RBracketLoc); |
| 1123 | } |
| 1124 | |
| 1125 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | /// By default, performs semantic analysis to build the new expression. |
| 1128 | /// Subclasses may override this routine to provide different behavior. |
| 1129 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1130 | MultiExprArg Args, |
| 1131 | SourceLocation *CommaLocs, |
| 1132 | SourceLocation RParenLoc) { |
| 1133 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1134 | move(Args), CommaLocs, RParenLoc); |
| 1135 | } |
| 1136 | |
| 1137 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// By default, performs semantic analysis to build the new expression. |
| 1140 | /// Subclasses may override this routine to provide different behavior. |
| 1141 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1143 | NestedNameSpecifier *Qualifier, |
| 1144 | SourceRange QualifierRange, |
| 1145 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1146 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1147 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1148 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1149 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1150 | if (!Member->getDeclName()) { |
| 1151 | // We have a reference to an unnamed field. |
| 1152 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1154 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1155 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1156 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1157 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1158 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1160 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1161 | Member, MemberLoc, |
| 1162 | cast<FieldDecl>(Member)->getType()); |
| 1163 | return getSema().Owned(ME); |
| 1164 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1165 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1166 | CXXScopeSpec SS; |
| 1167 | if (Qualifier) { |
| 1168 | SS.setRange(QualifierRange); |
| 1169 | SS.setScopeRep(Qualifier); |
| 1170 | } |
| 1171 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1172 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1173 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1174 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1175 | // cases; we should avoid this when possible. |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1176 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1177 | Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1178 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1179 | R.resolveKind(); |
| 1180 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1181 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1182 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1183 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1184 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1187 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1188 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1189 | /// By default, performs semantic analysis to build the new expression. |
| 1190 | /// Subclasses may override this routine to provide different behavior. |
| 1191 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1192 | BinaryOperator::Opcode Opc, |
| 1193 | ExprArg LHS, ExprArg RHS) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1194 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1195 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1200 | /// By default, performs semantic analysis to build the new expression. |
| 1201 | /// Subclasses may override this routine to provide different behavior. |
| 1202 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1203 | SourceLocation QuestionLoc, |
| 1204 | ExprArg LHS, |
| 1205 | SourceLocation ColonLoc, |
| 1206 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | move(LHS), move(RHS)); |
| 1209 | } |
| 1210 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1211 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | /// By default, performs semantic analysis to build the new expression. |
| 1214 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1215 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1216 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | SourceLocation RParenLoc, |
| 1218 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1219 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1220 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1223 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | /// By default, performs semantic analysis to build the new expression. |
| 1226 | /// Subclasses may override this routine to provide different behavior. |
| 1227 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1228 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1229 | SourceLocation RParenLoc, |
| 1230 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1231 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1232 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1233 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1235 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | /// By default, performs semantic analysis to build the new expression. |
| 1238 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | SourceLocation OpLoc, |
| 1241 | SourceLocation AccessorLoc, |
| 1242 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1243 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1244 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1245 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1246 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1247 | OpLoc, /*IsArrow*/ false, |
| 1248 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1249 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1250 | AccessorLoc, |
| 1251 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1252 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1253 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1254 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1255 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1256 | /// By default, performs semantic analysis to build the new expression. |
| 1257 | /// Subclasses may override this routine to provide different behavior. |
| 1258 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1259 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1260 | SourceLocation RBraceLoc, |
| 1261 | QualType ResultTy) { |
| 1262 | OwningExprResult Result |
| 1263 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1264 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1265 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1266 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1267 | // Patch in the result type we were given, which may have been computed |
| 1268 | // when the initial InitListExpr was built. |
| 1269 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1270 | ILE->setType(ResultTy); |
| 1271 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1272 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1274 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1275 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1276 | /// By default, performs semantic analysis to build the new expression. |
| 1277 | /// Subclasses may override this routine to provide different behavior. |
| 1278 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1279 | MultiExprArg ArrayExprs, |
| 1280 | SourceLocation EqualOrColonLoc, |
| 1281 | bool GNUSyntax, |
| 1282 | ExprArg Init) { |
| 1283 | OwningExprResult Result |
| 1284 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1285 | move(Init)); |
| 1286 | if (Result.isInvalid()) |
| 1287 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1288 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1289 | ArrayExprs.release(); |
| 1290 | return move(Result); |
| 1291 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1293 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | /// By default, builds the implicit value initialization without performing |
| 1296 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1297 | /// different behavior. |
| 1298 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1299 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1302 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | /// By default, performs semantic analysis to build the new expression. |
| 1305 | /// Subclasses may override this routine to provide different behavior. |
| 1306 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1307 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | RParenLoc); |
| 1310 | } |
| 1311 | |
| 1312 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | /// By default, performs semantic analysis to build the new expression. |
| 1315 | /// Subclasses may override this routine to provide different behavior. |
| 1316 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1317 | MultiExprArg SubExprs, |
| 1318 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1319 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1320 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1324 | /// |
| 1325 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// rather than attempting to map the label statement itself. |
| 1327 | /// Subclasses may override this routine to provide different behavior. |
| 1328 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1329 | SourceLocation LabelLoc, |
| 1330 | LabelStmt *Label) { |
| 1331 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | /// By default, performs semantic analysis to build the new expression. |
| 1337 | /// Subclasses may override this routine to provide different behavior. |
| 1338 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1339 | StmtArg SubStmt, |
| 1340 | SourceLocation RParenLoc) { |
| 1341 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1345 | /// |
| 1346 | /// By default, performs semantic analysis to build the new expression. |
| 1347 | /// Subclasses may override this routine to provide different behavior. |
| 1348 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1349 | QualType T1, QualType T2, |
| 1350 | SourceLocation RParenLoc) { |
| 1351 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1352 | T1.getAsOpaquePtr(), |
| 1353 | T2.getAsOpaquePtr(), |
| 1354 | RParenLoc); |
| 1355 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1356 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1357 | /// \brief Build a new __builtin_choose_expr expression. |
| 1358 | /// |
| 1359 | /// By default, performs semantic analysis to build the new expression. |
| 1360 | /// Subclasses may override this routine to provide different behavior. |
| 1361 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1362 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1363 | SourceLocation RParenLoc) { |
| 1364 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1365 | move(Cond), move(LHS), move(RHS), |
| 1366 | RParenLoc); |
| 1367 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1368 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1369 | /// \brief Build a new overloaded operator call expression. |
| 1370 | /// |
| 1371 | /// By default, performs semantic analysis to build the new expression. |
| 1372 | /// The semantic analysis provides the behavior of template instantiation, |
| 1373 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1376 | /// provide different behavior. |
| 1377 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1378 | SourceLocation OpLoc, |
| 1379 | ExprArg Callee, |
| 1380 | ExprArg First, |
| 1381 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
| 1383 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1384 | /// reinterpret_cast. |
| 1385 | /// |
| 1386 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1387 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1388 | /// Subclasses may override this routine to provide different behavior. |
| 1389 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1390 | Stmt::StmtClass Class, |
| 1391 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1392 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1393 | SourceLocation RAngleLoc, |
| 1394 | SourceLocation LParenLoc, |
| 1395 | ExprArg SubExpr, |
| 1396 | SourceLocation RParenLoc) { |
| 1397 | switch (Class) { |
| 1398 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1399 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1400 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1401 | move(SubExpr), RParenLoc); |
| 1402 | |
| 1403 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1404 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1405 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1406 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1409 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | RAngleLoc, LParenLoc, |
| 1411 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1415 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1419 | default: |
| 1420 | assert(false && "Invalid C++ named cast"); |
| 1421 | break; |
| 1422 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | return getSema().ExprError(); |
| 1425 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1426 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1427 | /// \brief Build a new C++ static_cast expression. |
| 1428 | /// |
| 1429 | /// By default, performs semantic analysis to build the new expression. |
| 1430 | /// Subclasses may override this routine to provide different behavior. |
| 1431 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1432 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1433 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | SourceLocation RAngleLoc, |
| 1435 | SourceLocation LParenLoc, |
| 1436 | ExprArg SubExpr, |
| 1437 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1438 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1439 | TInfo, move(SubExpr), |
| 1440 | SourceRange(LAngleLoc, RAngleLoc), |
| 1441 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | /// \brief Build a new C++ dynamic_cast expression. |
| 1445 | /// |
| 1446 | /// By default, performs semantic analysis to build the new expression. |
| 1447 | /// Subclasses may override this routine to provide different behavior. |
| 1448 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1449 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1450 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | SourceLocation RAngleLoc, |
| 1452 | SourceLocation LParenLoc, |
| 1453 | ExprArg SubExpr, |
| 1454 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1455 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1456 | TInfo, move(SubExpr), |
| 1457 | SourceRange(LAngleLoc, RAngleLoc), |
| 1458 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1462 | /// |
| 1463 | /// By default, performs semantic analysis to build the new expression. |
| 1464 | /// Subclasses may override this routine to provide different behavior. |
| 1465 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1466 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1467 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1468 | SourceLocation RAngleLoc, |
| 1469 | SourceLocation LParenLoc, |
| 1470 | ExprArg SubExpr, |
| 1471 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1472 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1473 | TInfo, move(SubExpr), |
| 1474 | SourceRange(LAngleLoc, RAngleLoc), |
| 1475 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /// \brief Build a new C++ const_cast expression. |
| 1479 | /// |
| 1480 | /// By default, performs semantic analysis to build the new expression. |
| 1481 | /// Subclasses may override this routine to provide different behavior. |
| 1482 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1483 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1484 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | SourceLocation RAngleLoc, |
| 1486 | SourceLocation LParenLoc, |
| 1487 | ExprArg SubExpr, |
| 1488 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1489 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1490 | TInfo, move(SubExpr), |
| 1491 | SourceRange(LAngleLoc, RAngleLoc), |
| 1492 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1494 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | /// \brief Build a new C++ functional-style cast expression. |
| 1496 | /// |
| 1497 | /// By default, performs semantic analysis to build the new expression. |
| 1498 | /// Subclasses may override this routine to provide different behavior. |
| 1499 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1500 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | SourceLocation LParenLoc, |
| 1502 | ExprArg SubExpr, |
| 1503 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1504 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1505 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1506 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1508 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1509 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1510 | RParenLoc); |
| 1511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1513 | /// \brief Build a new C++ typeid(type) expression. |
| 1514 | /// |
| 1515 | /// By default, performs semantic analysis to build the new expression. |
| 1516 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1517 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1518 | SourceLocation TypeidLoc, |
| 1519 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1520 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1521 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1522 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | /// \brief Build a new C++ typeid(expr) expression. |
| 1526 | /// |
| 1527 | /// By default, performs semantic analysis to build the new expression. |
| 1528 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1529 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1530 | SourceLocation TypeidLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | ExprArg Operand, |
| 1532 | SourceLocation RParenLoc) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1533 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1534 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | /// \brief Build a new C++ "this" expression. |
| 1538 | /// |
| 1539 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1540 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1541 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1542 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1543 | QualType ThisType, |
| 1544 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1545 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1546 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1547 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | /// \brief Build a new C++ throw expression. |
| 1551 | /// |
| 1552 | /// By default, performs semantic analysis to build the new expression. |
| 1553 | /// Subclasses may override this routine to provide different behavior. |
| 1554 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1555 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1556 | } |
| 1557 | |
| 1558 | /// \brief Build a new C++ default-argument expression. |
| 1559 | /// |
| 1560 | /// By default, builds a new default-argument expression, which does not |
| 1561 | /// require any semantic analysis. Subclasses may override this routine to |
| 1562 | /// provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1563 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1564 | ParmVarDecl *Param) { |
| 1565 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1566 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | /// \brief Build a new C++ zero-initialization expression. |
| 1570 | /// |
| 1571 | /// By default, performs semantic analysis to build the new expression. |
| 1572 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | SourceLocation LParenLoc, |
| 1575 | QualType T, |
| 1576 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1577 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1578 | T.getAsOpaquePtr(), LParenLoc, |
| 1579 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1580 | 0, RParenLoc); |
| 1581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | /// \brief Build a new C++ "new" expression. |
| 1584 | /// |
| 1585 | /// By default, performs semantic analysis to build the new expression. |
| 1586 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1587 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1588 | bool UseGlobal, |
| 1589 | SourceLocation PlacementLParen, |
| 1590 | MultiExprArg PlacementArgs, |
| 1591 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | QualType AllocType, |
| 1594 | SourceLocation TypeLoc, |
| 1595 | SourceRange TypeRange, |
| 1596 | ExprArg ArraySize, |
| 1597 | SourceLocation ConstructorLParen, |
| 1598 | MultiExprArg ConstructorArgs, |
| 1599 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1600 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1601 | PlacementLParen, |
| 1602 | move(PlacementArgs), |
| 1603 | PlacementRParen, |
| 1604 | ParenTypeId, |
| 1605 | AllocType, |
| 1606 | TypeLoc, |
| 1607 | TypeRange, |
| 1608 | move(ArraySize), |
| 1609 | ConstructorLParen, |
| 1610 | move(ConstructorArgs), |
| 1611 | ConstructorRParen); |
| 1612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | /// \brief Build a new C++ "delete" expression. |
| 1615 | /// |
| 1616 | /// By default, performs semantic analysis to build the new expression. |
| 1617 | /// Subclasses may override this routine to provide different behavior. |
| 1618 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1619 | bool IsGlobalDelete, |
| 1620 | bool IsArrayForm, |
| 1621 | ExprArg Operand) { |
| 1622 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1623 | move(Operand)); |
| 1624 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | /// \brief Build a new unary type trait expression. |
| 1627 | /// |
| 1628 | /// By default, performs semantic analysis to build the new expression. |
| 1629 | /// Subclasses may override this routine to provide different behavior. |
| 1630 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1631 | SourceLocation StartLoc, |
| 1632 | SourceLocation LParenLoc, |
| 1633 | QualType T, |
| 1634 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | T.getAsOpaquePtr(), RParenLoc); |
| 1637 | } |
| 1638 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1639 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | /// expression. |
| 1641 | /// |
| 1642 | /// By default, performs semantic analysis to build the new expression. |
| 1643 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1644 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | SourceRange QualifierRange, |
| 1646 | DeclarationName Name, |
| 1647 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1648 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | CXXScopeSpec SS; |
| 1650 | SS.setRange(QualifierRange); |
| 1651 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1652 | |
| 1653 | if (TemplateArgs) |
| 1654 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1655 | *TemplateArgs); |
| 1656 | |
| 1657 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | /// \brief Build a new template-id expression. |
| 1661 | /// |
| 1662 | /// By default, performs semantic analysis to build the new expression. |
| 1663 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1664 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1665 | LookupResult &R, |
| 1666 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1667 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1668 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /// \brief Build a new object-construction expression. |
| 1672 | /// |
| 1673 | /// By default, performs semantic analysis to build the new expression. |
| 1674 | /// Subclasses may override this routine to provide different behavior. |
| 1675 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1676 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | CXXConstructorDecl *Constructor, |
| 1678 | bool IsElidable, |
| 1679 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1680 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1681 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1682 | ConvertedArgs)) |
| 1683 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1685 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1686 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | /// \brief Build a new object-construction expression. |
| 1690 | /// |
| 1691 | /// By default, performs semantic analysis to build the new expression. |
| 1692 | /// Subclasses may override this routine to provide different behavior. |
| 1693 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1694 | QualType T, |
| 1695 | SourceLocation LParenLoc, |
| 1696 | MultiExprArg Args, |
| 1697 | SourceLocation *Commas, |
| 1698 | SourceLocation RParenLoc) { |
| 1699 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1700 | T.getAsOpaquePtr(), |
| 1701 | LParenLoc, |
| 1702 | move(Args), |
| 1703 | Commas, |
| 1704 | RParenLoc); |
| 1705 | } |
| 1706 | |
| 1707 | /// \brief Build a new object-construction expression. |
| 1708 | /// |
| 1709 | /// By default, performs semantic analysis to build the new expression. |
| 1710 | /// Subclasses may override this routine to provide different behavior. |
| 1711 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1712 | QualType T, |
| 1713 | SourceLocation LParenLoc, |
| 1714 | MultiExprArg Args, |
| 1715 | SourceLocation *Commas, |
| 1716 | SourceLocation RParenLoc) { |
| 1717 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1718 | /*FIXME*/LParenLoc), |
| 1719 | T.getAsOpaquePtr(), |
| 1720 | LParenLoc, |
| 1721 | move(Args), |
| 1722 | Commas, |
| 1723 | RParenLoc); |
| 1724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | /// \brief Build a new member reference expression. |
| 1727 | /// |
| 1728 | /// By default, performs semantic analysis to build the new expression. |
| 1729 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1730 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1731 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | bool IsArrow, |
| 1733 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1734 | NestedNameSpecifier *Qualifier, |
| 1735 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1736 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1737 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1738 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1739 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1740 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1741 | SS.setRange(QualifierRange); |
| 1742 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1744 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1745 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1746 | SS, FirstQualifierInScope, |
| 1747 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1750 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1751 | /// |
| 1752 | /// By default, performs semantic analysis to build the new expression. |
| 1753 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1754 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1755 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1756 | SourceLocation OperatorLoc, |
| 1757 | bool IsArrow, |
| 1758 | NestedNameSpecifier *Qualifier, |
| 1759 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1760 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1761 | LookupResult &R, |
| 1762 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1763 | CXXScopeSpec SS; |
| 1764 | SS.setRange(QualifierRange); |
| 1765 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1767 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1768 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1769 | SS, FirstQualifierInScope, |
| 1770 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1773 | /// \brief Build a new Objective-C @encode expression. |
| 1774 | /// |
| 1775 | /// By default, performs semantic analysis to build the new expression. |
| 1776 | /// Subclasses may override this routine to provide different behavior. |
| 1777 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1778 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1780 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1784 | /// \brief Build a new Objective-C class message. |
| 1785 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1786 | Selector Sel, |
| 1787 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1788 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1789 | MultiExprArg Args, |
| 1790 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1791 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1792 | ReceiverTypeInfo->getType(), |
| 1793 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1794 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1795 | move(Args)); |
| 1796 | } |
| 1797 | |
| 1798 | /// \brief Build a new Objective-C instance message. |
| 1799 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1800 | Selector Sel, |
| 1801 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1802 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1803 | MultiExprArg Args, |
| 1804 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1805 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1806 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1807 | ReceiverType, |
| 1808 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1809 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1810 | move(Args)); |
| 1811 | } |
| 1812 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1813 | /// \brief Build a new Objective-C ivar reference expression. |
| 1814 | /// |
| 1815 | /// By default, performs semantic analysis to build the new expression. |
| 1816 | /// Subclasses may override this routine to provide different behavior. |
| 1817 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1818 | SourceLocation IvarLoc, |
| 1819 | bool IsArrow, bool IsFreeIvar) { |
| 1820 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1821 | CXXScopeSpec SS; |
| 1822 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1823 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1824 | Sema::LookupMemberName); |
| 1825 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1826 | /*FIME:*/IvarLoc, |
| 1827 | SS, DeclPtrTy()); |
| 1828 | if (Result.isInvalid()) |
| 1829 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1831 | if (Result.get()) |
| 1832 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1833 | |
| 1834 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1835 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1836 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1837 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1838 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1839 | /*TemplateArgs=*/0); |
| 1840 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1841 | |
| 1842 | /// \brief Build a new Objective-C property reference expression. |
| 1843 | /// |
| 1844 | /// By default, performs semantic analysis to build the new expression. |
| 1845 | /// Subclasses may override this routine to provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1846 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1847 | ObjCPropertyDecl *Property, |
| 1848 | SourceLocation PropertyLoc) { |
| 1849 | CXXScopeSpec SS; |
| 1850 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1851 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1852 | Sema::LookupMemberName); |
| 1853 | bool IsArrow = false; |
| 1854 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1855 | /*FIME:*/PropertyLoc, |
| 1856 | SS, DeclPtrTy()); |
| 1857 | if (Result.isInvalid()) |
| 1858 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1860 | if (Result.get()) |
| 1861 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1862 | |
| 1863 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1864 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1865 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1866 | SS, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1867 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1868 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1869 | /*TemplateArgs=*/0); |
| 1870 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1871 | |
| 1872 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1873 | /// expression. |
| 1874 | /// |
| 1875 | /// By default, performs semantic analysis to build the new expression. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1876 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1877 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1878 | ObjCMethodDecl *Getter, |
| 1879 | QualType T, |
| 1880 | ObjCMethodDecl *Setter, |
| 1881 | SourceLocation NameLoc, |
| 1882 | ExprArg Base) { |
| 1883 | // Since these expressions can only be value-dependent, we do not need to |
| 1884 | // perform semantic analysis again. |
| 1885 | return getSema().Owned( |
| 1886 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1887 | Setter, |
| 1888 | NameLoc, |
| 1889 | Base.takeAs<Expr>())); |
| 1890 | } |
| 1891 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1892 | /// \brief Build a new Objective-C "isa" expression. |
| 1893 | /// |
| 1894 | /// By default, performs semantic analysis to build the new expression. |
| 1895 | /// Subclasses may override this routine to provide different behavior. |
| 1896 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1897 | bool IsArrow) { |
| 1898 | CXXScopeSpec SS; |
| 1899 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1900 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1901 | Sema::LookupMemberName); |
| 1902 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1903 | /*FIME:*/IsaLoc, |
| 1904 | SS, DeclPtrTy()); |
| 1905 | if (Result.isInvalid()) |
| 1906 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1907 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1908 | if (Result.get()) |
| 1909 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1910 | |
| 1911 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1912 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1913 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1914 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1915 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1916 | /*TemplateArgs=*/0); |
| 1917 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1918 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | /// \brief Build a new shuffle vector expression. |
| 1920 | /// |
| 1921 | /// By default, performs semantic analysis to build the new expression. |
| 1922 | /// Subclasses may override this routine to provide different behavior. |
| 1923 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1924 | MultiExprArg SubExprs, |
| 1925 | SourceLocation RParenLoc) { |
| 1926 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1927 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1928 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1929 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1930 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1931 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1932 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1933 | // Build a reference to the __builtin_shufflevector builtin |
| 1934 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1935 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1936 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1937 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1938 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1939 | |
| 1940 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | unsigned NumSubExprs = SubExprs.size(); |
| 1942 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1943 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1944 | Subs, NumSubExprs, |
| 1945 | Builtin->getResultType(), |
| 1946 | RParenLoc); |
| 1947 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1948 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | // Type-check the __builtin_shufflevector expression. |
| 1950 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1951 | if (Result.isInvalid()) |
| 1952 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1954 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1955 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1956 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1957 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1959 | template<typename Derived> |
| 1960 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1961 | if (!S) |
| 1962 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1963 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1964 | switch (S->getStmtClass()) { |
| 1965 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1966 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1967 | // Transform individual statement nodes |
| 1968 | #define STMT(Node, Parent) \ |
| 1969 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1970 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1971 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1973 | // Transform expressions by calling TransformExpr. |
| 1974 | #define STMT(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1975 | #define ABSTRACT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1976 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1977 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1978 | { |
| 1979 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1980 | if (E.isInvalid()) |
| 1981 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1982 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1983 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1984 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1987 | return SemaRef.Owned(S->Retain()); |
| 1988 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1989 | |
| 1990 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1991 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1992 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1993 | if (!E) |
| 1994 | return SemaRef.Owned(E); |
| 1995 | |
| 1996 | switch (E->getStmtClass()) { |
| 1997 | case Stmt::NoStmtClass: break; |
| 1998 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1999 | #define ABSTRACT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2000 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2001 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2002 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2005 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2009 | NestedNameSpecifier * |
| 2010 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2011 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2012 | QualType ObjectType, |
| 2013 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2014 | if (!NNS) |
| 2015 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2017 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2018 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2019 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2021 | ObjectType, |
| 2022 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2023 | if (!Prefix) |
| 2024 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | |
| 2026 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2027 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2028 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2029 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2032 | switch (NNS->getKind()) { |
| 2033 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2035 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2036 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2037 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2038 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2039 | |
| 2040 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2041 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2042 | ObjectType, |
| 2043 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2045 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2046 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2047 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2048 | getDerived().TransformDecl(Range.getBegin(), |
| 2049 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2050 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2051 | Prefix == NNS->getPrefix() && |
| 2052 | NS == NNS->getAsNamespace()) |
| 2053 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2054 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2055 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2057 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2058 | case NestedNameSpecifier::Global: |
| 2059 | // There is no meaningful transformation that one could perform on the |
| 2060 | // global scope. |
| 2061 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2063 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2064 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2065 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2066 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2067 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2068 | if (T.isNull()) |
| 2069 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2071 | if (!getDerived().AlwaysRebuild() && |
| 2072 | Prefix == NNS->getPrefix() && |
| 2073 | T == QualType(NNS->getAsType(), 0)) |
| 2074 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2075 | |
| 2076 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2077 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2078 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2079 | } |
| 2080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2082 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2083 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2087 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2088 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2089 | SourceLocation Loc, |
| 2090 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2091 | if (!Name) |
| 2092 | return Name; |
| 2093 | |
| 2094 | switch (Name.getNameKind()) { |
| 2095 | case DeclarationName::Identifier: |
| 2096 | case DeclarationName::ObjCZeroArgSelector: |
| 2097 | case DeclarationName::ObjCOneArgSelector: |
| 2098 | case DeclarationName::ObjCMultiArgSelector: |
| 2099 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2100 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2101 | case DeclarationName::CXXUsingDirective: |
| 2102 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2103 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2104 | case DeclarationName::CXXConstructorName: |
| 2105 | case DeclarationName::CXXDestructorName: |
| 2106 | case DeclarationName::CXXConversionFunctionName: { |
| 2107 | TemporaryBase Rebase(*this, Loc, Name); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2108 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2109 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2110 | if (T.isNull()) |
| 2111 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2112 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2113 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2115 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2119 | return DeclarationName(); |
| 2120 | } |
| 2121 | |
| 2122 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2123 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2124 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2125 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2126 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2127 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2128 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2129 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2130 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2131 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2132 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2133 | if (!NNS) |
| 2134 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2136 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2137 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2138 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2139 | if (!TransTemplate) |
| 2140 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2141 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2142 | if (!getDerived().AlwaysRebuild() && |
| 2143 | NNS == QTN->getQualifier() && |
| 2144 | TransTemplate == Template) |
| 2145 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2146 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2147 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2148 | TransTemplate); |
| 2149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2150 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2151 | // These should be getting filtered out before they make it into the AST. |
| 2152 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2153 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2155 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2156 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2157 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2158 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2159 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2160 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2161 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2162 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2163 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2164 | NNS == DTN->getQualifier() && |
| 2165 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2166 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2167 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2168 | if (DTN->isIdentifier()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2169 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2170 | ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2171 | |
| 2172 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2173 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2174 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2175 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2176 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2177 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2178 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2179 | if (!TransTemplate) |
| 2180 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2182 | if (!getDerived().AlwaysRebuild() && |
| 2183 | TransTemplate == Template) |
| 2184 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2186 | return TemplateName(TransTemplate); |
| 2187 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2188 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2189 | // These should be getting filtered out before they reach the AST. |
| 2190 | assert(false && "overloaded function decl survived to here"); |
| 2191 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2195 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2196 | const TemplateArgument &Arg, |
| 2197 | TemplateArgumentLoc &Output) { |
| 2198 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2199 | switch (Arg.getKind()) { |
| 2200 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2201 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | |
| 2204 | case TemplateArgument::Type: |
| 2205 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2206 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2207 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2208 | break; |
| 2209 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2210 | case TemplateArgument::Template: |
| 2211 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2212 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2213 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2214 | case TemplateArgument::Expression: |
| 2215 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2216 | break; |
| 2217 | |
| 2218 | case TemplateArgument::Declaration: |
| 2219 | case TemplateArgument::Integral: |
| 2220 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2221 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2222 | break; |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | template<typename Derived> |
| 2227 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2228 | const TemplateArgumentLoc &Input, |
| 2229 | TemplateArgumentLoc &Output) { |
| 2230 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2231 | switch (Arg.getKind()) { |
| 2232 | case TemplateArgument::Null: |
| 2233 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2234 | Output = Input; |
| 2235 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2236 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2237 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2238 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2239 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2240 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2241 | |
| 2242 | DI = getDerived().TransformType(DI); |
| 2243 | if (!DI) return true; |
| 2244 | |
| 2245 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2246 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2247 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2248 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2249 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2250 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2251 | DeclarationName Name; |
| 2252 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2253 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2254 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2255 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2256 | if (!D) return true; |
| 2257 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2258 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2259 | if (SourceExpr) { |
| 2260 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2261 | Action::Unevaluated); |
| 2262 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2263 | if (E.isInvalid()) |
| 2264 | SourceExpr = NULL; |
| 2265 | else { |
| 2266 | SourceExpr = E.takeAs<Expr>(); |
| 2267 | SourceExpr->Retain(); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2272 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2273 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2275 | case TemplateArgument::Template: { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2276 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2277 | TemplateName Template |
| 2278 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2279 | if (Template.isNull()) |
| 2280 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2281 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2282 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2283 | Input.getTemplateQualifierRange(), |
| 2284 | Input.getTemplateNameLoc()); |
| 2285 | return false; |
| 2286 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2287 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2288 | case TemplateArgument::Expression: { |
| 2289 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2291 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2292 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2293 | Expr *InputExpr = Input.getSourceExpression(); |
| 2294 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2295 | |
| 2296 | Sema::OwningExprResult E |
| 2297 | = getDerived().TransformExpr(InputExpr); |
| 2298 | if (E.isInvalid()) return true; |
| 2299 | |
| 2300 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2301 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2302 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2303 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2305 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2306 | case TemplateArgument::Pack: { |
| 2307 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2308 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2310 | AEnd = Arg.pack_end(); |
| 2311 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2312 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2313 | // FIXME: preserve source information here when we start |
| 2314 | // caring about parameter packs. |
| 2315 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2316 | TemplateArgumentLoc InputArg; |
| 2317 | TemplateArgumentLoc OutputArg; |
| 2318 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2319 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2320 | return true; |
| 2321 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2322 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2323 | } |
| 2324 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2325 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2326 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2327 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2328 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2329 | } |
| 2330 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2331 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2332 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2333 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2336 | //===----------------------------------------------------------------------===// |
| 2337 | // Type transformation |
| 2338 | //===----------------------------------------------------------------------===// |
| 2339 | |
| 2340 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2341 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2342 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2343 | if (getDerived().AlreadyTransformed(T)) |
| 2344 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2345 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2346 | // Temporary workaround. All of these transformations should |
| 2347 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2348 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2349 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2350 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2351 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2352 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2353 | if (!NewDI) |
| 2354 | return QualType(); |
| 2355 | |
| 2356 | return NewDI->getType(); |
| 2357 | } |
| 2358 | |
| 2359 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2360 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2361 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2362 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2363 | return DI; |
| 2364 | |
| 2365 | TypeLocBuilder TLB; |
| 2366 | |
| 2367 | TypeLoc TL = DI->getTypeLoc(); |
| 2368 | TLB.reserve(TL.getFullDataSize()); |
| 2369 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2370 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2371 | if (Result.isNull()) |
| 2372 | return 0; |
| 2373 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2374 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | template<typename Derived> |
| 2378 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2379 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2380 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2381 | switch (T.getTypeLocClass()) { |
| 2382 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2383 | #define TYPELOC(CLASS, PARENT) \ |
| 2384 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2385 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2386 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2387 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2389 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2390 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2391 | return QualType(); |
| 2392 | } |
| 2393 | |
| 2394 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2395 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2396 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2397 | /// types). This is the right thing for template instantiation, but |
| 2398 | /// probably not for other clients. |
| 2399 | template<typename Derived> |
| 2400 | QualType |
| 2401 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2402 | QualifiedTypeLoc T, |
| 2403 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2404 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2405 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2406 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2407 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2408 | if (Result.isNull()) |
| 2409 | return QualType(); |
| 2410 | |
| 2411 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2412 | // FIXME: this is the right thing for template instantiation, but |
| 2413 | // probably not for other clients. |
| 2414 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2415 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2416 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2417 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2418 | |
| 2419 | TLB.push<QualifiedTypeLoc>(Result); |
| 2420 | |
| 2421 | // No location information to preserve. |
| 2422 | |
| 2423 | return Result; |
| 2424 | } |
| 2425 | |
| 2426 | template <class TyLoc> static inline |
| 2427 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2428 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2429 | NewT.setNameLoc(T.getNameLoc()); |
| 2430 | return T.getType(); |
| 2431 | } |
| 2432 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2433 | template<typename Derived> |
| 2434 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2435 | BuiltinTypeLoc T, |
| 2436 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2437 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2438 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2439 | if (T.needsExtraLocalData()) |
| 2440 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2441 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2444 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2445 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2446 | ComplexTypeLoc T, |
| 2447 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2448 | // FIXME: recurse? |
| 2449 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2450 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2451 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2452 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2453 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2454 | PointerTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2455 | QualType ObjectType) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2456 | QualType PointeeType |
| 2457 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2458 | if (PointeeType.isNull()) |
| 2459 | return QualType(); |
| 2460 | |
| 2461 | QualType Result = TL.getType(); |
| 2462 | if (PointeeType->isObjCInterfaceType()) { |
| 2463 | // A dependent pointer type 'T *' has is being transformed such |
| 2464 | // that an Objective-C class type is being replaced for 'T'. The |
| 2465 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2466 | // PointerType. |
| 2467 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2468 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2469 | const_cast<ObjCProtocolDecl **>( |
| 2470 | IFace->qual_begin()), |
| 2471 | IFace->getNumProtocols()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2472 | |
| 2473 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2474 | NewT.setStarLoc(TL.getSigilLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2475 | NewT.setHasProtocolsAsWritten(false); |
| 2476 | NewT.setLAngleLoc(SourceLocation()); |
| 2477 | NewT.setRAngleLoc(SourceLocation()); |
| 2478 | NewT.setHasBaseTypeAsWritten(true); |
| 2479 | return Result; |
| 2480 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2481 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2482 | if (getDerived().AlwaysRebuild() || |
| 2483 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2484 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2485 | if (Result.isNull()) |
| 2486 | return QualType(); |
| 2487 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2488 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2489 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2490 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2491 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2493 | |
| 2494 | template<typename Derived> |
| 2495 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2496 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2497 | BlockPointerTypeLoc TL, |
| 2498 | QualType ObjectType) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2499 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2500 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2501 | if (PointeeType.isNull()) |
| 2502 | return QualType(); |
| 2503 | |
| 2504 | QualType Result = TL.getType(); |
| 2505 | if (getDerived().AlwaysRebuild() || |
| 2506 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2507 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2508 | TL.getSigilLoc()); |
| 2509 | if (Result.isNull()) |
| 2510 | return QualType(); |
| 2511 | } |
| 2512 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2513 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2514 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2515 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2518 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2519 | /// don't care whether the type itself is an l-value type or an r-value |
| 2520 | /// type; we only care if the type was *written* as an l-value type |
| 2521 | /// or an r-value type. |
| 2522 | template<typename Derived> |
| 2523 | QualType |
| 2524 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2525 | ReferenceTypeLoc TL, |
| 2526 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2527 | const ReferenceType *T = TL.getTypePtr(); |
| 2528 | |
| 2529 | // Note that this works with the pointee-as-written. |
| 2530 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2531 | if (PointeeType.isNull()) |
| 2532 | return QualType(); |
| 2533 | |
| 2534 | QualType Result = TL.getType(); |
| 2535 | if (getDerived().AlwaysRebuild() || |
| 2536 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2537 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2538 | T->isSpelledAsLValue(), |
| 2539 | TL.getSigilLoc()); |
| 2540 | if (Result.isNull()) |
| 2541 | return QualType(); |
| 2542 | } |
| 2543 | |
| 2544 | // r-value references can be rebuilt as l-value references. |
| 2545 | ReferenceTypeLoc NewTL; |
| 2546 | if (isa<LValueReferenceType>(Result)) |
| 2547 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2548 | else |
| 2549 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2550 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2551 | |
| 2552 | return Result; |
| 2553 | } |
| 2554 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2555 | template<typename Derived> |
| 2556 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2557 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2558 | LValueReferenceTypeLoc TL, |
| 2559 | QualType ObjectType) { |
| 2560 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2563 | template<typename Derived> |
| 2564 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2565 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2566 | RValueReferenceTypeLoc TL, |
| 2567 | QualType ObjectType) { |
| 2568 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2570 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2571 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2572 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2573 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2574 | MemberPointerTypeLoc TL, |
| 2575 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2576 | MemberPointerType *T = TL.getTypePtr(); |
| 2577 | |
| 2578 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2579 | if (PointeeType.isNull()) |
| 2580 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2582 | // TODO: preserve source information for this. |
| 2583 | QualType ClassType |
| 2584 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2585 | if (ClassType.isNull()) |
| 2586 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2588 | QualType Result = TL.getType(); |
| 2589 | if (getDerived().AlwaysRebuild() || |
| 2590 | PointeeType != T->getPointeeType() || |
| 2591 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2592 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2593 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2594 | if (Result.isNull()) |
| 2595 | return QualType(); |
| 2596 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2597 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2598 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2599 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2600 | |
| 2601 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | template<typename Derived> |
| 2605 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2606 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2607 | ConstantArrayTypeLoc TL, |
| 2608 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2609 | ConstantArrayType *T = TL.getTypePtr(); |
| 2610 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2611 | if (ElementType.isNull()) |
| 2612 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2613 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2614 | QualType Result = TL.getType(); |
| 2615 | if (getDerived().AlwaysRebuild() || |
| 2616 | ElementType != T->getElementType()) { |
| 2617 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2618 | T->getSizeModifier(), |
| 2619 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2620 | T->getIndexTypeCVRQualifiers(), |
| 2621 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2622 | if (Result.isNull()) |
| 2623 | return QualType(); |
| 2624 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2625 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2626 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2627 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2628 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2629 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2630 | Expr *Size = TL.getSizeExpr(); |
| 2631 | if (Size) { |
| 2632 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2633 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2634 | } |
| 2635 | NewTL.setSizeExpr(Size); |
| 2636 | |
| 2637 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2638 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2639 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2640 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2641 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2642 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2643 | IncompleteArrayTypeLoc TL, |
| 2644 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2645 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2646 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2647 | if (ElementType.isNull()) |
| 2648 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2649 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2650 | QualType Result = TL.getType(); |
| 2651 | if (getDerived().AlwaysRebuild() || |
| 2652 | ElementType != T->getElementType()) { |
| 2653 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2654 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2655 | T->getIndexTypeCVRQualifiers(), |
| 2656 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2657 | if (Result.isNull()) |
| 2658 | return QualType(); |
| 2659 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2660 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2661 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2662 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2663 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2664 | NewTL.setSizeExpr(0); |
| 2665 | |
| 2666 | return Result; |
| 2667 | } |
| 2668 | |
| 2669 | template<typename Derived> |
| 2670 | QualType |
| 2671 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2672 | VariableArrayTypeLoc TL, |
| 2673 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2674 | VariableArrayType *T = TL.getTypePtr(); |
| 2675 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2676 | if (ElementType.isNull()) |
| 2677 | return QualType(); |
| 2678 | |
| 2679 | // Array bounds are not potentially evaluated contexts |
| 2680 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2681 | |
| 2682 | Sema::OwningExprResult SizeResult |
| 2683 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2684 | if (SizeResult.isInvalid()) |
| 2685 | return QualType(); |
| 2686 | |
| 2687 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2688 | |
| 2689 | QualType Result = TL.getType(); |
| 2690 | if (getDerived().AlwaysRebuild() || |
| 2691 | ElementType != T->getElementType() || |
| 2692 | Size != T->getSizeExpr()) { |
| 2693 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2694 | T->getSizeModifier(), |
| 2695 | move(SizeResult), |
| 2696 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2697 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2698 | if (Result.isNull()) |
| 2699 | return QualType(); |
| 2700 | } |
| 2701 | else SizeResult.take(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2702 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2703 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2704 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2705 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2706 | NewTL.setSizeExpr(Size); |
| 2707 | |
| 2708 | return Result; |
| 2709 | } |
| 2710 | |
| 2711 | template<typename Derived> |
| 2712 | QualType |
| 2713 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2714 | DependentSizedArrayTypeLoc TL, |
| 2715 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2717 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2718 | if (ElementType.isNull()) |
| 2719 | return QualType(); |
| 2720 | |
| 2721 | // Array bounds are not potentially evaluated contexts |
| 2722 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2723 | |
| 2724 | Sema::OwningExprResult SizeResult |
| 2725 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2726 | if (SizeResult.isInvalid()) |
| 2727 | return QualType(); |
| 2728 | |
| 2729 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2730 | |
| 2731 | QualType Result = TL.getType(); |
| 2732 | if (getDerived().AlwaysRebuild() || |
| 2733 | ElementType != T->getElementType() || |
| 2734 | Size != T->getSizeExpr()) { |
| 2735 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2736 | T->getSizeModifier(), |
| 2737 | move(SizeResult), |
| 2738 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2739 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2740 | if (Result.isNull()) |
| 2741 | return QualType(); |
| 2742 | } |
| 2743 | else SizeResult.take(); |
| 2744 | |
| 2745 | // We might have any sort of array type now, but fortunately they |
| 2746 | // all have the same location layout. |
| 2747 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2748 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2749 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2750 | NewTL.setSizeExpr(Size); |
| 2751 | |
| 2752 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2753 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | |
| 2755 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2756 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2757 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2758 | DependentSizedExtVectorTypeLoc TL, |
| 2759 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2760 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2761 | |
| 2762 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2763 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2764 | if (ElementType.isNull()) |
| 2765 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2766 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2767 | // Vector sizes are not potentially evaluated contexts |
| 2768 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2769 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2770 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2771 | if (Size.isInvalid()) |
| 2772 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2773 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2774 | QualType Result = TL.getType(); |
| 2775 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2776 | ElementType != T->getElementType() || |
| 2777 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2778 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2779 | move(Size), |
| 2780 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2781 | if (Result.isNull()) |
| 2782 | return QualType(); |
| 2783 | } |
| 2784 | else Size.take(); |
| 2785 | |
| 2786 | // Result might be dependent or not. |
| 2787 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2788 | DependentSizedExtVectorTypeLoc NewTL |
| 2789 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2790 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2791 | } else { |
| 2792 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2793 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2794 | } |
| 2795 | |
| 2796 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2797 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2798 | |
| 2799 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2800 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2801 | VectorTypeLoc TL, |
| 2802 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2803 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2804 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2805 | if (ElementType.isNull()) |
| 2806 | return QualType(); |
| 2807 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2808 | QualType Result = TL.getType(); |
| 2809 | if (getDerived().AlwaysRebuild() || |
| 2810 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2811 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2812 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2813 | if (Result.isNull()) |
| 2814 | return QualType(); |
| 2815 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2816 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2817 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2818 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2819 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2820 | return Result; |
| 2821 | } |
| 2822 | |
| 2823 | template<typename Derived> |
| 2824 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2825 | ExtVectorTypeLoc TL, |
| 2826 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2827 | VectorType *T = TL.getTypePtr(); |
| 2828 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2829 | if (ElementType.isNull()) |
| 2830 | return QualType(); |
| 2831 | |
| 2832 | QualType Result = TL.getType(); |
| 2833 | if (getDerived().AlwaysRebuild() || |
| 2834 | ElementType != T->getElementType()) { |
| 2835 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2836 | T->getNumElements(), |
| 2837 | /*FIXME*/ SourceLocation()); |
| 2838 | if (Result.isNull()) |
| 2839 | return QualType(); |
| 2840 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2841 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2842 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2843 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2844 | |
| 2845 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2847 | |
| 2848 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2849 | ParmVarDecl * |
| 2850 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2851 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2852 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2853 | if (!NewDI) |
| 2854 | return 0; |
| 2855 | |
| 2856 | if (NewDI == OldDI) |
| 2857 | return OldParm; |
| 2858 | else |
| 2859 | return ParmVarDecl::Create(SemaRef.Context, |
| 2860 | OldParm->getDeclContext(), |
| 2861 | OldParm->getLocation(), |
| 2862 | OldParm->getIdentifier(), |
| 2863 | NewDI->getType(), |
| 2864 | NewDI, |
| 2865 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2866 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2867 | /* DefArg */ NULL); |
| 2868 | } |
| 2869 | |
| 2870 | template<typename Derived> |
| 2871 | bool TreeTransform<Derived>:: |
| 2872 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2873 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2874 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2875 | FunctionProtoType *T = TL.getTypePtr(); |
| 2876 | |
| 2877 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2878 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2879 | |
| 2880 | QualType NewType; |
| 2881 | ParmVarDecl *NewParm; |
| 2882 | |
| 2883 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2884 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2885 | if (!NewParm) |
| 2886 | return true; |
| 2887 | NewType = NewParm->getType(); |
| 2888 | |
| 2889 | // Deal with the possibility that we don't have a parameter |
| 2890 | // declaration for this parameter. |
| 2891 | } else { |
| 2892 | NewParm = 0; |
| 2893 | |
| 2894 | QualType OldType = T->getArgType(i); |
| 2895 | NewType = getDerived().TransformType(OldType); |
| 2896 | if (NewType.isNull()) |
| 2897 | return true; |
| 2898 | } |
| 2899 | |
| 2900 | PTypes.push_back(NewType); |
| 2901 | PVars.push_back(NewParm); |
| 2902 | } |
| 2903 | |
| 2904 | return false; |
| 2905 | } |
| 2906 | |
| 2907 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2908 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2909 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2910 | FunctionProtoTypeLoc TL, |
| 2911 | QualType ObjectType) { |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2912 | // Transform the parameters. We do this first for the benefit of template |
| 2913 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2914 | // instantiation scope before we transform the function type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2915 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2916 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2917 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2918 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2919 | |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2920 | FunctionProtoType *T = TL.getTypePtr(); |
| 2921 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2922 | if (ResultType.isNull()) |
| 2923 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2924 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2925 | QualType Result = TL.getType(); |
| 2926 | if (getDerived().AlwaysRebuild() || |
| 2927 | ResultType != T->getResultType() || |
| 2928 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2929 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2930 | ParamTypes.data(), |
| 2931 | ParamTypes.size(), |
| 2932 | T->isVariadic(), |
| 2933 | T->getTypeQuals()); |
| 2934 | if (Result.isNull()) |
| 2935 | return QualType(); |
| 2936 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2937 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2938 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2939 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2940 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2941 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2942 | NewTL.setArg(i, ParamDecls[i]); |
| 2943 | |
| 2944 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2945 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2946 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2947 | template<typename Derived> |
| 2948 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2949 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2950 | FunctionNoProtoTypeLoc TL, |
| 2951 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2952 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2953 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2954 | if (ResultType.isNull()) |
| 2955 | return QualType(); |
| 2956 | |
| 2957 | QualType Result = TL.getType(); |
| 2958 | if (getDerived().AlwaysRebuild() || |
| 2959 | ResultType != T->getResultType()) |
| 2960 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2961 | |
| 2962 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2963 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2964 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2965 | |
| 2966 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2967 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2969 | template<typename Derived> QualType |
| 2970 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2971 | UnresolvedUsingTypeLoc TL, |
| 2972 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2973 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2974 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2975 | if (!D) |
| 2976 | return QualType(); |
| 2977 | |
| 2978 | QualType Result = TL.getType(); |
| 2979 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2980 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2981 | if (Result.isNull()) |
| 2982 | return QualType(); |
| 2983 | } |
| 2984 | |
| 2985 | // We might get an arbitrary type spec type back. We should at |
| 2986 | // least always get a type spec type, though. |
| 2987 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2988 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2989 | |
| 2990 | return Result; |
| 2991 | } |
| 2992 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2993 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2994 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2995 | TypedefTypeLoc TL, |
| 2996 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2997 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2998 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2999 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3000 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3001 | if (!Typedef) |
| 3002 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3003 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3004 | QualType Result = TL.getType(); |
| 3005 | if (getDerived().AlwaysRebuild() || |
| 3006 | Typedef != T->getDecl()) { |
| 3007 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3008 | if (Result.isNull()) |
| 3009 | return QualType(); |
| 3010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3012 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3013 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3014 | |
| 3015 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3017 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3018 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3019 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3020 | TypeOfExprTypeLoc TL, |
| 3021 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3022 | // typeof expressions are not potentially evaluated contexts |
| 3023 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3025 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3026 | if (E.isInvalid()) |
| 3027 | return QualType(); |
| 3028 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3029 | QualType Result = TL.getType(); |
| 3030 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3031 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3032 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3033 | if (Result.isNull()) |
| 3034 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3035 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3036 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3039 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3040 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3041 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3042 | |
| 3043 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3044 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
| 3046 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3047 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3048 | TypeOfTypeLoc TL, |
| 3049 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3050 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3051 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3052 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3053 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3054 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3055 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3056 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3057 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3058 | if (Result.isNull()) |
| 3059 | return QualType(); |
| 3060 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3063 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3064 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3065 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3066 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3067 | |
| 3068 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3070 | |
| 3071 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3072 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3073 | DecltypeTypeLoc TL, |
| 3074 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3075 | DecltypeType *T = TL.getTypePtr(); |
| 3076 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3077 | // decltype expressions are not potentially evaluated contexts |
| 3078 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3079 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3080 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3081 | if (E.isInvalid()) |
| 3082 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3084 | QualType Result = TL.getType(); |
| 3085 | if (getDerived().AlwaysRebuild() || |
| 3086 | E.get() != T->getUnderlyingExpr()) { |
| 3087 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3088 | if (Result.isNull()) |
| 3089 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3090 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3091 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3092 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3093 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3094 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3095 | |
| 3096 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3100 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3101 | RecordTypeLoc TL, |
| 3102 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3103 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3104 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3105 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3106 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3107 | if (!Record) |
| 3108 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3110 | QualType Result = TL.getType(); |
| 3111 | if (getDerived().AlwaysRebuild() || |
| 3112 | Record != T->getDecl()) { |
| 3113 | Result = getDerived().RebuildRecordType(Record); |
| 3114 | if (Result.isNull()) |
| 3115 | return QualType(); |
| 3116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3117 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3118 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3119 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3120 | |
| 3121 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3122 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3123 | |
| 3124 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3125 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3126 | EnumTypeLoc TL, |
| 3127 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3128 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3129 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3130 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3131 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3132 | if (!Enum) |
| 3133 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3134 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3135 | QualType Result = TL.getType(); |
| 3136 | if (getDerived().AlwaysRebuild() || |
| 3137 | Enum != T->getDecl()) { |
| 3138 | Result = getDerived().RebuildEnumType(Enum); |
| 3139 | if (Result.isNull()) |
| 3140 | return QualType(); |
| 3141 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3142 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3143 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3144 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3145 | |
| 3146 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3147 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3148 | |
| 3149 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3150 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3151 | ElaboratedTypeLoc TL, |
| 3152 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3153 | ElaboratedType *T = TL.getTypePtr(); |
| 3154 | |
| 3155 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3156 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 3157 | if (Underlying.isNull()) |
| 3158 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3159 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3160 | QualType Result = TL.getType(); |
| 3161 | if (getDerived().AlwaysRebuild() || |
| 3162 | Underlying != T->getUnderlyingType()) { |
| 3163 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 3164 | if (Result.isNull()) |
| 3165 | return QualType(); |
| 3166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3168 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3169 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3170 | |
| 3171 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3174 | template<typename Derived> |
| 3175 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3176 | TypeLocBuilder &TLB, |
| 3177 | InjectedClassNameTypeLoc TL, |
| 3178 | QualType ObjectType) { |
| 3179 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3180 | TL.getTypePtr()->getDecl()); |
| 3181 | if (!D) return QualType(); |
| 3182 | |
| 3183 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3184 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3185 | return T; |
| 3186 | } |
| 3187 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3189 | template<typename Derived> |
| 3190 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3191 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3192 | TemplateTypeParmTypeLoc TL, |
| 3193 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3194 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3198 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3199 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3200 | SubstTemplateTypeParmTypeLoc TL, |
| 3201 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3202 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3206 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3207 | const TemplateSpecializationType *TST, |
| 3208 | QualType ObjectType) { |
| 3209 | // FIXME: this entire method is a temporary workaround; callers |
| 3210 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3211 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3212 | // Fake up a TemplateSpecializationTypeLoc. |
| 3213 | TypeLocBuilder TLB; |
| 3214 | TemplateSpecializationTypeLoc TL |
| 3215 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3216 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3217 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3218 | |
| 3219 | TL.setTemplateNameLoc(BaseLoc); |
| 3220 | TL.setLAngleLoc(BaseLoc); |
| 3221 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3222 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3223 | const TemplateArgument &TA = TST->getArg(i); |
| 3224 | TemplateArgumentLoc TAL; |
| 3225 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3226 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3227 | } |
| 3228 | |
| 3229 | TypeLocBuilder IgnoredTLB; |
| 3230 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3231 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3232 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3233 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3234 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3235 | TypeLocBuilder &TLB, |
| 3236 | TemplateSpecializationTypeLoc TL, |
| 3237 | QualType ObjectType) { |
| 3238 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3239 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3241 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3242 | if (Template.isNull()) |
| 3243 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3245 | TemplateArgumentListInfo NewTemplateArgs; |
| 3246 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3247 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3248 | |
| 3249 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3250 | TemplateArgumentLoc Loc; |
| 3251 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3252 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3253 | NewTemplateArgs.addArgument(Loc); |
| 3254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3256 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3257 | |
| 3258 | QualType Result = |
| 3259 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3260 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3261 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3262 | |
| 3263 | if (!Result.isNull()) { |
| 3264 | TemplateSpecializationTypeLoc NewTL |
| 3265 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3266 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3267 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3268 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3269 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3270 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3272 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3273 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | |
| 3276 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3277 | QualType |
| 3278 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3279 | QualifiedNameTypeLoc TL, |
| 3280 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3281 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3282 | NestedNameSpecifier *NNS |
| 3283 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3284 | SourceRange(), |
| 3285 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3286 | if (!NNS) |
| 3287 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3288 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3289 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3290 | if (Named.isNull()) |
| 3291 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3292 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3293 | QualType Result = TL.getType(); |
| 3294 | if (getDerived().AlwaysRebuild() || |
| 3295 | NNS != T->getQualifier() || |
| 3296 | Named != T->getNamedType()) { |
| 3297 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3298 | if (Result.isNull()) |
| 3299 | return QualType(); |
| 3300 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3301 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3302 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3303 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3304 | |
| 3305 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | |
| 3308 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3309 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3310 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3311 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3312 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3313 | |
| 3314 | /* FIXME: preserve source information better than this */ |
| 3315 | SourceRange SR(TL.getNameLoc()); |
| 3316 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3317 | NestedNameSpecifier *NNS |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3318 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3319 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3320 | if (!NNS) |
| 3321 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3322 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3323 | QualType Result; |
| 3324 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3325 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3327 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3328 | if (NewTemplateId.isNull()) |
| 3329 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3330 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3331 | if (!getDerived().AlwaysRebuild() && |
| 3332 | NNS == T->getQualifier() && |
| 3333 | NewTemplateId == QualType(TemplateId, 0)) |
| 3334 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3335 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3336 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3337 | NewTemplateId); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3338 | } else { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3339 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3340 | T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3341 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3342 | if (Result.isNull()) |
| 3343 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3344 | |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3345 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3346 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3347 | |
| 3348 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3351 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3352 | QualType |
| 3353 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3354 | ObjCInterfaceTypeLoc TL, |
| 3355 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3356 | // ObjCInterfaceType is never dependent. |
| 3357 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | |
| 3360 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3361 | QualType |
| 3362 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3363 | ObjCObjectPointerTypeLoc TL, |
| 3364 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3365 | // ObjCObjectPointerType is never dependent. |
| 3366 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3369 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3370 | // Statement transformation |
| 3371 | //===----------------------------------------------------------------------===// |
| 3372 | template<typename Derived> |
| 3373 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3375 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | template<typename Derived> |
| 3379 | Sema::OwningStmtResult |
| 3380 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3381 | return getDerived().TransformCompoundStmt(S, false); |
| 3382 | } |
| 3383 | |
| 3384 | template<typename Derived> |
| 3385 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3386 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3387 | bool IsStmtExpr) { |
| 3388 | bool SubStmtChanged = false; |
| 3389 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3390 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3391 | B != BEnd; ++B) { |
| 3392 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3393 | if (Result.isInvalid()) |
| 3394 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3396 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3397 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3399 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3400 | if (!getDerived().AlwaysRebuild() && |
| 3401 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3402 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3403 | |
| 3404 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3405 | move_arg(Statements), |
| 3406 | S->getRBracLoc(), |
| 3407 | IsStmtExpr); |
| 3408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3410 | template<typename Derived> |
| 3411 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3412 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3413 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3414 | { |
| 3415 | // The case value expressions are not potentially evaluated. |
| 3416 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3418 | // Transform the left-hand case value. |
| 3419 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3420 | if (LHS.isInvalid()) |
| 3421 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3423 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3424 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3425 | if (RHS.isInvalid()) |
| 3426 | return SemaRef.StmtError(); |
| 3427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | // Build the case statement. |
| 3430 | // Case statements are always rebuilt so that they will attached to their |
| 3431 | // transformed switch statement. |
| 3432 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3433 | move(LHS), |
| 3434 | S->getEllipsisLoc(), |
| 3435 | move(RHS), |
| 3436 | S->getColonLoc()); |
| 3437 | if (Case.isInvalid()) |
| 3438 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3439 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3440 | // Transform the statement following the case |
| 3441 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3442 | if (SubStmt.isInvalid()) |
| 3443 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3444 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3445 | // Attach the body to the case statement |
| 3446 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3447 | } |
| 3448 | |
| 3449 | template<typename Derived> |
| 3450 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3451 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3452 | // Transform the statement following the default case |
| 3453 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3454 | if (SubStmt.isInvalid()) |
| 3455 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3457 | // Default statements are always rebuilt |
| 3458 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3459 | move(SubStmt)); |
| 3460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | template<typename Derived> |
| 3463 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3466 | if (SubStmt.isInvalid()) |
| 3467 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3468 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3469 | // FIXME: Pass the real colon location in. |
| 3470 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3471 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3472 | move(SubStmt)); |
| 3473 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3476 | Sema::OwningStmtResult |
| 3477 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3478 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3479 | OwningExprResult Cond(SemaRef); |
| 3480 | VarDecl *ConditionVar = 0; |
| 3481 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3482 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3483 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3484 | getDerived().TransformDefinition( |
| 3485 | S->getConditionVariable()->getLocation(), |
| 3486 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3487 | if (!ConditionVar) |
| 3488 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3489 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3490 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3491 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3492 | if (Cond.isInvalid()) |
| 3493 | return SemaRef.StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3494 | |
| 3495 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame^] | 3496 | if (S->getCond()) { |
| 3497 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3498 | S->getIfLoc(), |
| 3499 | move(Cond)); |
| 3500 | if (CondE.isInvalid()) |
| 3501 | return getSema().StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3502 | |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame^] | 3503 | Cond = move(CondE); |
| 3504 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3505 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3506 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3507 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3508 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3509 | return SemaRef.StmtError(); |
| 3510 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3511 | // Transform the "then" branch. |
| 3512 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3513 | if (Then.isInvalid()) |
| 3514 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3515 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3516 | // Transform the "else" branch. |
| 3517 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3518 | if (Else.isInvalid()) |
| 3519 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3520 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3521 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3522 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3523 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | Then.get() == S->getThen() && |
| 3525 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | return SemaRef.Owned(S->Retain()); |
| 3527 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3528 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3529 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | template<typename Derived> |
| 3534 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3537 | OwningExprResult Cond(SemaRef); |
| 3538 | VarDecl *ConditionVar = 0; |
| 3539 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3540 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3541 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3542 | getDerived().TransformDefinition( |
| 3543 | S->getConditionVariable()->getLocation(), |
| 3544 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3545 | if (!ConditionVar) |
| 3546 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3547 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3548 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3549 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3550 | if (Cond.isInvalid()) |
| 3551 | return SemaRef.StmtError(); |
| 3552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3554 | // Rebuild the switch statement. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3555 | OwningStmtResult Switch |
| 3556 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3557 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3558 | if (Switch.isInvalid()) |
| 3559 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3560 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3561 | // Transform the body of the switch statement. |
| 3562 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3563 | if (Body.isInvalid()) |
| 3564 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3566 | // Complete the switch statement. |
| 3567 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3568 | move(Body)); |
| 3569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3570 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3571 | template<typename Derived> |
| 3572 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3574 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3575 | OwningExprResult Cond(SemaRef); |
| 3576 | VarDecl *ConditionVar = 0; |
| 3577 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3578 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3579 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3580 | getDerived().TransformDefinition( |
| 3581 | S->getConditionVariable()->getLocation(), |
| 3582 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3583 | if (!ConditionVar) |
| 3584 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3585 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3586 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3587 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3588 | if (Cond.isInvalid()) |
| 3589 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame^] | 3590 | |
| 3591 | if (S->getCond()) { |
| 3592 | // Convert the condition to a boolean value. |
| 3593 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3594 | S->getWhileLoc(), |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame^] | 3595 | move(Cond)); |
| 3596 | if (CondE.isInvalid()) |
| 3597 | return getSema().StmtError(); |
| 3598 | Cond = move(CondE); |
| 3599 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3602 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3603 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3604 | return SemaRef.StmtError(); |
| 3605 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3606 | // Transform the body |
| 3607 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3608 | if (Body.isInvalid()) |
| 3609 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3611 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3612 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3613 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3614 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | return SemaRef.Owned(S->Retain()); |
| 3616 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3617 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3618 | ConditionVar, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3621 | template<typename Derived> |
| 3622 | Sema::OwningStmtResult |
| 3623 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3624 | // Transform the body |
| 3625 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3626 | if (Body.isInvalid()) |
| 3627 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3629 | // Transform the condition |
| 3630 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3631 | if (Cond.isInvalid()) |
| 3632 | return SemaRef.StmtError(); |
| 3633 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3634 | if (!getDerived().AlwaysRebuild() && |
| 3635 | Cond.get() == S->getCond() && |
| 3636 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | return SemaRef.Owned(S->Retain()); |
| 3638 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3639 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3640 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3641 | S->getRParenLoc()); |
| 3642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3644 | template<typename Derived> |
| 3645 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3647 | // Transform the initialization statement |
| 3648 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3649 | if (Init.isInvalid()) |
| 3650 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3652 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3653 | OwningExprResult Cond(SemaRef); |
| 3654 | VarDecl *ConditionVar = 0; |
| 3655 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3656 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3657 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3658 | getDerived().TransformDefinition( |
| 3659 | S->getConditionVariable()->getLocation(), |
| 3660 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3661 | if (!ConditionVar) |
| 3662 | return SemaRef.StmtError(); |
| 3663 | } else { |
| 3664 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3665 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3666 | if (Cond.isInvalid()) |
| 3667 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame^] | 3668 | |
| 3669 | if (S->getCond()) { |
| 3670 | // Convert the condition to a boolean value. |
| 3671 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3672 | S->getForLoc(), |
| 3673 | move(Cond)); |
| 3674 | if (CondE.isInvalid()) |
| 3675 | return getSema().StmtError(); |
| 3676 | |
| 3677 | Cond = move(CondE); |
| 3678 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3681 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3682 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3683 | return SemaRef.StmtError(); |
| 3684 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3685 | // Transform the increment |
| 3686 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3687 | if (Inc.isInvalid()) |
| 3688 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3690 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3691 | if (S->getInc() && !FullInc->get()) |
| 3692 | return SemaRef.StmtError(); |
| 3693 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3694 | // Transform the body |
| 3695 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3696 | if (Body.isInvalid()) |
| 3697 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3698 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3699 | if (!getDerived().AlwaysRebuild() && |
| 3700 | Init.get() == S->getInit() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3701 | FullCond->get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3702 | Inc.get() == S->getInc() && |
| 3703 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3704 | return SemaRef.Owned(S->Retain()); |
| 3705 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3706 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3707 | move(Init), FullCond, ConditionVar, |
| 3708 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | Sema::OwningStmtResult |
| 3713 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3714 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3716 | S->getLabel()); |
| 3717 | } |
| 3718 | |
| 3719 | template<typename Derived> |
| 3720 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3722 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3723 | if (Target.isInvalid()) |
| 3724 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3726 | if (!getDerived().AlwaysRebuild() && |
| 3727 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3728 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3729 | |
| 3730 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3731 | move(Target)); |
| 3732 | } |
| 3733 | |
| 3734 | template<typename Derived> |
| 3735 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3736 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3737 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3739 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3740 | template<typename Derived> |
| 3741 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3743 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3746 | template<typename Derived> |
| 3747 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3748 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3749 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3750 | if (Result.isInvalid()) |
| 3751 | return SemaRef.StmtError(); |
| 3752 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3754 | // to tell whether the return type of the function has changed. |
| 3755 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3757 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3758 | template<typename Derived> |
| 3759 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3761 | bool DeclChanged = false; |
| 3762 | llvm::SmallVector<Decl *, 4> Decls; |
| 3763 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3764 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3765 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3766 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3767 | if (!Transformed) |
| 3768 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3769 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3770 | if (Transformed != *D) |
| 3771 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3772 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3773 | Decls.push_back(Transformed); |
| 3774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3775 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3776 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | return SemaRef.Owned(S->Retain()); |
| 3778 | |
| 3779 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3780 | S->getStartLoc(), S->getEndLoc()); |
| 3781 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3783 | template<typename Derived> |
| 3784 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3785 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3786 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | template<typename Derived> |
| 3791 | Sema::OwningStmtResult |
| 3792 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3793 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3794 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3795 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3796 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3797 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3798 | OwningExprResult AsmString(SemaRef); |
| 3799 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3800 | |
| 3801 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3802 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3803 | // Go through the outputs. |
| 3804 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3805 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3806 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3807 | // No need to transform the constraint literal. |
| 3808 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3809 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3810 | // Transform the output expr. |
| 3811 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3812 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3813 | if (Result.isInvalid()) |
| 3814 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3815 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3816 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3817 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3818 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3819 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3820 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3821 | // Go through the inputs. |
| 3822 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3823 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3824 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3825 | // No need to transform the constraint literal. |
| 3826 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3827 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3828 | // Transform the input expr. |
| 3829 | Expr *InputExpr = S->getInputExpr(I); |
| 3830 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3831 | if (Result.isInvalid()) |
| 3832 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3833 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3834 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3835 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3836 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3837 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3838 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3839 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3840 | return SemaRef.Owned(S->Retain()); |
| 3841 | |
| 3842 | // Go through the clobbers. |
| 3843 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3844 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3845 | |
| 3846 | // No need to transform the asm string literal. |
| 3847 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3848 | |
| 3849 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3850 | S->isSimple(), |
| 3851 | S->isVolatile(), |
| 3852 | S->getNumOutputs(), |
| 3853 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3854 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3855 | move_arg(Constraints), |
| 3856 | move_arg(Exprs), |
| 3857 | move(AsmString), |
| 3858 | move_arg(Clobbers), |
| 3859 | S->getRParenLoc(), |
| 3860 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | |
| 3864 | template<typename Derived> |
| 3865 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3867 | // Transform the body of the @try. |
| 3868 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3869 | if (TryBody.isInvalid()) |
| 3870 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3872 | // Transform the @catch statements (if present). |
| 3873 | bool AnyCatchChanged = false; |
| 3874 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3875 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3876 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3877 | if (Catch.isInvalid()) |
| 3878 | return SemaRef.StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3879 | if (Catch.get() != S->getCatchStmt(I)) |
| 3880 | AnyCatchChanged = true; |
| 3881 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3882 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3883 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3884 | // Transform the @finally statement (if present). |
| 3885 | OwningStmtResult Finally(SemaRef); |
| 3886 | if (S->getFinallyStmt()) { |
| 3887 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3888 | if (Finally.isInvalid()) |
| 3889 | return SemaRef.StmtError(); |
| 3890 | } |
| 3891 | |
| 3892 | // If nothing changed, just retain this statement. |
| 3893 | if (!getDerived().AlwaysRebuild() && |
| 3894 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3895 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3896 | Finally.get() == S->getFinallyStmt()) |
| 3897 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3898 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3899 | // Build a new statement. |
| 3900 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3901 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3902 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3904 | template<typename Derived> |
| 3905 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3906 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3907 | // Transform the @catch parameter, if there is one. |
| 3908 | VarDecl *Var = 0; |
| 3909 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3910 | TypeSourceInfo *TSInfo = 0; |
| 3911 | if (FromVar->getTypeSourceInfo()) { |
| 3912 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3913 | if (!TSInfo) |
| 3914 | return SemaRef.StmtError(); |
| 3915 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3916 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3917 | QualType T; |
| 3918 | if (TSInfo) |
| 3919 | T = TSInfo->getType(); |
| 3920 | else { |
| 3921 | T = getDerived().TransformType(FromVar->getType()); |
| 3922 | if (T.isNull()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3923 | return SemaRef.StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3924 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3925 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3926 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3927 | if (!Var) |
| 3928 | return SemaRef.StmtError(); |
| 3929 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3930 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3931 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3932 | if (Body.isInvalid()) |
| 3933 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3934 | |
| 3935 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3936 | S->getRParenLoc(), |
| 3937 | Var, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3938 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3940 | template<typename Derived> |
| 3941 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3943 | // Transform the body. |
| 3944 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 3945 | if (Body.isInvalid()) |
| 3946 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3947 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3948 | // If nothing changed, just retain this statement. |
| 3949 | if (!getDerived().AlwaysRebuild() && |
| 3950 | Body.get() == S->getFinallyBody()) |
| 3951 | return SemaRef.Owned(S->Retain()); |
| 3952 | |
| 3953 | // Build a new statement. |
| 3954 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 3955 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3956 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3957 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3958 | template<typename Derived> |
| 3959 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3961 | OwningExprResult Operand(SemaRef); |
| 3962 | if (S->getThrowExpr()) { |
| 3963 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3964 | if (Operand.isInvalid()) |
| 3965 | return getSema().StmtError(); |
| 3966 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3967 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3968 | if (!getDerived().AlwaysRebuild() && |
| 3969 | Operand.get() == S->getThrowExpr()) |
| 3970 | return getSema().Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3971 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3972 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3973 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3975 | template<typename Derived> |
| 3976 | Sema::OwningStmtResult |
| 3977 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3979 | // Transform the object we are locking. |
| 3980 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3981 | if (Object.isInvalid()) |
| 3982 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3984 | // Transform the body. |
| 3985 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3986 | if (Body.isInvalid()) |
| 3987 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3988 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3989 | // If nothing change, just retain the current statement. |
| 3990 | if (!getDerived().AlwaysRebuild() && |
| 3991 | Object.get() == S->getSynchExpr() && |
| 3992 | Body.get() == S->getSynchBody()) |
| 3993 | return SemaRef.Owned(S->Retain()); |
| 3994 | |
| 3995 | // Build a new statement. |
| 3996 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 3997 | move(Object), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | template<typename Derived> |
| 4001 | Sema::OwningStmtResult |
| 4002 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4003 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4004 | // Transform the element statement. |
| 4005 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 4006 | if (Element.isInvalid()) |
| 4007 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4008 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4009 | // Transform the collection expression. |
| 4010 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 4011 | if (Collection.isInvalid()) |
| 4012 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4014 | // Transform the body. |
| 4015 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 4016 | if (Body.isInvalid()) |
| 4017 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4018 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4019 | // If nothing changed, just retain this statement. |
| 4020 | if (!getDerived().AlwaysRebuild() && |
| 4021 | Element.get() == S->getElement() && |
| 4022 | Collection.get() == S->getCollection() && |
| 4023 | Body.get() == S->getBody()) |
| 4024 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4025 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4026 | // Build a new statement. |
| 4027 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4028 | /*FIXME:*/S->getForLoc(), |
| 4029 | move(Element), |
| 4030 | move(Collection), |
| 4031 | S->getRParenLoc(), |
| 4032 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | |
| 4036 | template<typename Derived> |
| 4037 | Sema::OwningStmtResult |
| 4038 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4039 | // Transform the exception declaration, if any. |
| 4040 | VarDecl *Var = 0; |
| 4041 | if (S->getExceptionDecl()) { |
| 4042 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4043 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4044 | ExceptionDecl->getDeclName()); |
| 4045 | |
| 4046 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4047 | if (T.isNull()) |
| 4048 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4050 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4051 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4052 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4053 | ExceptionDecl->getIdentifier(), |
| 4054 | ExceptionDecl->getLocation(), |
| 4055 | /*FIXME: Inaccurate*/ |
| 4056 | SourceRange(ExceptionDecl->getLocation())); |
| 4057 | if (!Var || Var->isInvalidDecl()) { |
| 4058 | if (Var) |
| 4059 | Var->Destroy(SemaRef.Context); |
| 4060 | return SemaRef.StmtError(); |
| 4061 | } |
| 4062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4064 | // Transform the actual exception handler. |
| 4065 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 4066 | if (Handler.isInvalid()) { |
| 4067 | if (Var) |
| 4068 | Var->Destroy(SemaRef.Context); |
| 4069 | return SemaRef.StmtError(); |
| 4070 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4071 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4072 | if (!getDerived().AlwaysRebuild() && |
| 4073 | !Var && |
| 4074 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4076 | |
| 4077 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4078 | Var, |
| 4079 | move(Handler)); |
| 4080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4082 | template<typename Derived> |
| 4083 | Sema::OwningStmtResult |
| 4084 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4085 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4086 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4087 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4088 | if (TryBlock.isInvalid()) |
| 4089 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4091 | // Transform the handlers. |
| 4092 | bool HandlerChanged = false; |
| 4093 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4094 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4095 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4096 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4097 | if (Handler.isInvalid()) |
| 4098 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4100 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4101 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4103 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4104 | if (!getDerived().AlwaysRebuild() && |
| 4105 | TryBlock.get() == S->getTryBlock() && |
| 4106 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4108 | |
| 4109 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4111 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4112 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4113 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | // Expression transformation |
| 4115 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | template<typename Derived> |
| 4117 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4118 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4119 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4121 | |
| 4122 | template<typename Derived> |
| 4123 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4124 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4125 | NestedNameSpecifier *Qualifier = 0; |
| 4126 | if (E->getQualifier()) { |
| 4127 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4128 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4129 | if (!Qualifier) |
| 4130 | return SemaRef.ExprError(); |
| 4131 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4132 | |
| 4133 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4134 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4135 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4136 | if (!ND) |
| 4137 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4139 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4140 | Qualifier == E->getQualifier() && |
| 4141 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4142 | !E->hasExplicitTemplateArgumentList()) { |
| 4143 | |
| 4144 | // Mark it referenced in the new context regardless. |
| 4145 | // FIXME: this is a bit instantiation-specific. |
| 4146 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4147 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4149 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4150 | |
| 4151 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4152 | if (E->hasExplicitTemplateArgumentList()) { |
| 4153 | TemplateArgs = &TransArgs; |
| 4154 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4155 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4156 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4157 | TemplateArgumentLoc Loc; |
| 4158 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4159 | return SemaRef.ExprError(); |
| 4160 | TransArgs.addArgument(Loc); |
| 4161 | } |
| 4162 | } |
| 4163 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4164 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4165 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4168 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4169 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4170 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4171 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4174 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4176 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4180 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4182 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4186 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4188 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4194 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | return SemaRef.Owned(E->Retain()); |
| 4196 | } |
| 4197 | |
| 4198 | template<typename Derived> |
| 4199 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4200 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4201 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4202 | if (SubExpr.isInvalid()) |
| 4203 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4204 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | return SemaRef.Owned(E->Retain()); |
| 4207 | |
| 4208 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4209 | E->getRParen()); |
| 4210 | } |
| 4211 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | template<typename Derived> |
| 4213 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4214 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4215 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4216 | if (SubExpr.isInvalid()) |
| 4217 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4220 | return SemaRef.Owned(E->Retain()); |
| 4221 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4223 | E->getOpcode(), |
| 4224 | move(SubExpr)); |
| 4225 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | Sema::OwningExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4229 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4230 | // Transform the type. |
| 4231 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4232 | if (!Type) |
| 4233 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4234 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4235 | // Transform all of the components into components similar to what the |
| 4236 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4237 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4238 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4239 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4240 | // template code that we don't care. |
| 4241 | bool ExprChanged = false; |
| 4242 | typedef Action::OffsetOfComponent Component; |
| 4243 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4244 | llvm::SmallVector<Component, 4> Components; |
| 4245 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4246 | const Node &ON = E->getComponent(I); |
| 4247 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4248 | Comp.isBrackets = true; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4249 | Comp.LocStart = ON.getRange().getBegin(); |
| 4250 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4251 | switch (ON.getKind()) { |
| 4252 | case Node::Array: { |
| 4253 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4254 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4255 | if (Index.isInvalid()) |
| 4256 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4257 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4258 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4259 | Comp.isBrackets = true; |
| 4260 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4261 | break; |
| 4262 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4263 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4264 | case Node::Field: |
| 4265 | case Node::Identifier: |
| 4266 | Comp.isBrackets = false; |
| 4267 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4268 | if (!Comp.U.IdentInfo) |
| 4269 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4270 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4271 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4272 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4273 | case Node::Base: |
| 4274 | // Will be recomputed during the rebuild. |
| 4275 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4276 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4277 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4278 | Components.push_back(Comp); |
| 4279 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4281 | // If nothing changed, retain the existing expression. |
| 4282 | if (!getDerived().AlwaysRebuild() && |
| 4283 | Type == E->getTypeSourceInfo() && |
| 4284 | !ExprChanged) |
| 4285 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4286 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4287 | // Build a new offsetof expression. |
| 4288 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4289 | Components.data(), Components.size(), |
| 4290 | E->getRParenLoc()); |
| 4291 | } |
| 4292 | |
| 4293 | template<typename Derived> |
| 4294 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4295 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4297 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4298 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4299 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4300 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4302 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4303 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4305 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4306 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4308 | E->getSourceRange()); |
| 4309 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4310 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | // C++0x [expr.sizeof]p1: |
| 4314 | // The operand is either an expression, which is an unevaluated operand |
| 4315 | // [...] |
| 4316 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4317 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4318 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4319 | if (SubExpr.isInvalid()) |
| 4320 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4321 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4322 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4323 | return SemaRef.Owned(E->Retain()); |
| 4324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4327 | E->isSizeOf(), |
| 4328 | E->getSourceRange()); |
| 4329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4332 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4333 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4334 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4335 | if (LHS.isInvalid()) |
| 4336 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4337 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4338 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4339 | if (RHS.isInvalid()) |
| 4340 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | |
| 4342 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | if (!getDerived().AlwaysRebuild() && |
| 4344 | LHS.get() == E->getLHS() && |
| 4345 | RHS.get() == E->getRHS()) |
| 4346 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4349 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4350 | move(RHS), |
| 4351 | E->getRBracketLoc()); |
| 4352 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | |
| 4354 | template<typename Derived> |
| 4355 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4356 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4357 | // Transform the callee. |
| 4358 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4359 | if (Callee.isInvalid()) |
| 4360 | return SemaRef.ExprError(); |
| 4361 | |
| 4362 | // Transform arguments. |
| 4363 | bool ArgChanged = false; |
| 4364 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4365 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4366 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4367 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4368 | if (Arg.isInvalid()) |
| 4369 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4371 | // FIXME: Wrong source location information for the ','. |
| 4372 | FakeCommaLocs.push_back( |
| 4373 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | |
| 4375 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4376 | Args.push_back(Arg.takeAs<Expr>()); |
| 4377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | if (!getDerived().AlwaysRebuild() && |
| 4380 | Callee.get() == E->getCallee() && |
| 4381 | !ArgChanged) |
| 4382 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4387 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4388 | move_arg(Args), |
| 4389 | FakeCommaLocs.data(), |
| 4390 | E->getRParenLoc()); |
| 4391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | |
| 4393 | template<typename Derived> |
| 4394 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4395 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4396 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4397 | if (Base.isInvalid()) |
| 4398 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4400 | NestedNameSpecifier *Qualifier = 0; |
| 4401 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4403 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4404 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4405 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4406 | return SemaRef.ExprError(); |
| 4407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4409 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4410 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4411 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | if (!Member) |
| 4413 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4415 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4416 | if (FoundDecl == E->getMemberDecl()) { |
| 4417 | FoundDecl = Member; |
| 4418 | } else { |
| 4419 | FoundDecl = cast_or_null<NamedDecl>( |
| 4420 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4421 | if (!FoundDecl) |
| 4422 | return SemaRef.ExprError(); |
| 4423 | } |
| 4424 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | if (!getDerived().AlwaysRebuild() && |
| 4426 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4427 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4428 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4429 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4430 | !E->hasExplicitTemplateArgumentList()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4431 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4432 | // Mark it referenced in the new context regardless. |
| 4433 | // FIXME: this is a bit instantiation-specific. |
| 4434 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4436 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4438 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4439 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4440 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4441 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4442 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4443 | TemplateArgumentLoc Loc; |
| 4444 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4445 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4446 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4447 | } |
| 4448 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4449 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4450 | // FIXME: Bogus source location for the operator |
| 4451 | SourceLocation FakeOperatorLoc |
| 4452 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4453 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4454 | // FIXME: to do this check properly, we will need to preserve the |
| 4455 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4456 | // base (and therefore couldn't do the check) and a |
| 4457 | // nested-name-qualifier (and therefore could do the lookup). |
| 4458 | NamedDecl *FirstQualifierInScope = 0; |
| 4459 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4461 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4462 | Qualifier, |
| 4463 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4464 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4465 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4466 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4467 | (E->hasExplicitTemplateArgumentList() |
| 4468 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4469 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4473 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4474 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4476 | if (LHS.isInvalid()) |
| 4477 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4480 | if (RHS.isInvalid()) |
| 4481 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | if (!getDerived().AlwaysRebuild() && |
| 4484 | LHS.get() == E->getLHS() && |
| 4485 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | return SemaRef.Owned(E->Retain()); |
| 4487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4489 | move(LHS), move(RHS)); |
| 4490 | } |
| 4491 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4493 | Sema::OwningExprResult |
| 4494 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4495 | CompoundAssignOperator *E) { |
| 4496 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4498 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4499 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4501 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4503 | if (Cond.isInvalid()) |
| 4504 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4507 | if (LHS.isInvalid()) |
| 4508 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4509 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4510 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4511 | if (RHS.isInvalid()) |
| 4512 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | if (!getDerived().AlwaysRebuild() && |
| 4515 | Cond.get() == E->getCond() && |
| 4516 | LHS.get() == E->getLHS() && |
| 4517 | RHS.get() == E->getRHS()) |
| 4518 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | |
| 4520 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4521 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4522 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4523 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | move(RHS)); |
| 4525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4526 | |
| 4527 | template<typename Derived> |
| 4528 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4529 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4530 | // Implicit casts are eliminated during transformation, since they |
| 4531 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4532 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4533 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4534 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4535 | template<typename Derived> |
| 4536 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4537 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4538 | TypeSourceInfo *OldT; |
| 4539 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | { |
| 4541 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4544 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4545 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4546 | OldT = E->getTypeInfoAsWritten(); |
| 4547 | NewT = getDerived().TransformType(OldT); |
| 4548 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | return SemaRef.ExprError(); |
| 4550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4552 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4553 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4554 | if (SubExpr.isInvalid()) |
| 4555 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4558 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | return SemaRef.Owned(E->Retain()); |
| 4561 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4562 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4563 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4564 | E->getRParenLoc(), |
| 4565 | move(SubExpr)); |
| 4566 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4568 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4570 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4571 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4572 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4573 | if (!NewT) |
| 4574 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4576 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4577 | if (Init.isInvalid()) |
| 4578 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4579 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4580 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4581 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4585 | // Note: the expression type doesn't necessarily match the |
| 4586 | // type-as-written, but that's okay, because it should always be |
| 4587 | // derivable from the initializer. |
| 4588 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4589 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4590 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4591 | move(Init)); |
| 4592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4594 | template<typename Derived> |
| 4595 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4596 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4597 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4598 | if (Base.isInvalid()) |
| 4599 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4600 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | if (!getDerived().AlwaysRebuild() && |
| 4602 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | return SemaRef.Owned(E->Retain()); |
| 4604 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4605 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4607 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4608 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4609 | E->getAccessorLoc(), |
| 4610 | E->getAccessor()); |
| 4611 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4613 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4614 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4615 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4616 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4617 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4618 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4619 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4620 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4621 | if (Init.isInvalid()) |
| 4622 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4624 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4625 | Inits.push_back(Init.takeAs<Expr>()); |
| 4626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4628 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4629 | return SemaRef.Owned(E->Retain()); |
| 4630 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4631 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4632 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4635 | template<typename Derived> |
| 4636 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4637 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4640 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4642 | if (Init.isInvalid()) |
| 4643 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4645 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4647 | bool ExprChanged = false; |
| 4648 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4649 | DEnd = E->designators_end(); |
| 4650 | D != DEnd; ++D) { |
| 4651 | if (D->isFieldDesignator()) { |
| 4652 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4653 | D->getDotLoc(), |
| 4654 | D->getFieldLoc())); |
| 4655 | continue; |
| 4656 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | if (D->isArrayDesignator()) { |
| 4659 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4660 | if (Index.isInvalid()) |
| 4661 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | |
| 4663 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4664 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4667 | ArrayExprs.push_back(Index.release()); |
| 4668 | continue; |
| 4669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4671 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4673 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4674 | if (Start.isInvalid()) |
| 4675 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4676 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4677 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4678 | if (End.isInvalid()) |
| 4679 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | |
| 4681 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4682 | End.get(), |
| 4683 | D->getLBracketLoc(), |
| 4684 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4685 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4686 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4687 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | ArrayExprs.push_back(Start.release()); |
| 4690 | ArrayExprs.push_back(End.release()); |
| 4691 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4693 | if (!getDerived().AlwaysRebuild() && |
| 4694 | Init.get() == E->getInit() && |
| 4695 | !ExprChanged) |
| 4696 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4697 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4698 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4699 | E->getEqualOrColonLoc(), |
| 4700 | E->usesGNUSyntax(), move(Init)); |
| 4701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4702 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4703 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4705 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4706 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4707 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4708 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4709 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4710 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4711 | QualType T = getDerived().TransformType(E->getType()); |
| 4712 | if (T.isNull()) |
| 4713 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4714 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4715 | if (!getDerived().AlwaysRebuild() && |
| 4716 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4717 | return SemaRef.Owned(E->Retain()); |
| 4718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4724 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | // FIXME: Do we want the type as written? |
| 4726 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4728 | { |
| 4729 | // FIXME: Source location isn't quite accurate. |
| 4730 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4731 | T = getDerived().TransformType(E->getType()); |
| 4732 | if (T.isNull()) |
| 4733 | return SemaRef.ExprError(); |
| 4734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4736 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4737 | if (SubExpr.isInvalid()) |
| 4738 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4739 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4740 | if (!getDerived().AlwaysRebuild() && |
| 4741 | T == E->getType() && |
| 4742 | SubExpr.get() == E->getSubExpr()) |
| 4743 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4745 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4746 | T, E->getRParenLoc()); |
| 4747 | } |
| 4748 | |
| 4749 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4750 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4751 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | bool ArgumentChanged = false; |
| 4753 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4754 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4755 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4756 | if (Init.isInvalid()) |
| 4757 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4759 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4760 | Inits.push_back(Init.takeAs<Expr>()); |
| 4761 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4762 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4763 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4764 | move_arg(Inits), |
| 4765 | E->getRParenLoc()); |
| 4766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4768 | /// \brief Transform an address-of-label expression. |
| 4769 | /// |
| 4770 | /// By default, the transformation of an address-of-label expression always |
| 4771 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4772 | /// the corresponding label statement by semantic analysis. |
| 4773 | template<typename Derived> |
| 4774 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4775 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4777 | E->getLabel()); |
| 4778 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | |
| 4780 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4781 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4782 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4783 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4785 | if (SubStmt.isInvalid()) |
| 4786 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4788 | if (!getDerived().AlwaysRebuild() && |
| 4789 | SubStmt.get() == E->getSubStmt()) |
| 4790 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4791 | |
| 4792 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4793 | move(SubStmt), |
| 4794 | E->getRParenLoc()); |
| 4795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4797 | template<typename Derived> |
| 4798 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4799 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | QualType T1, T2; |
| 4801 | { |
| 4802 | // FIXME: Source location isn't quite accurate. |
| 4803 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4805 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4806 | if (T1.isNull()) |
| 4807 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4808 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4809 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4810 | if (T2.isNull()) |
| 4811 | return SemaRef.ExprError(); |
| 4812 | } |
| 4813 | |
| 4814 | if (!getDerived().AlwaysRebuild() && |
| 4815 | T1 == E->getArgType1() && |
| 4816 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | return SemaRef.Owned(E->Retain()); |
| 4818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4819 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4820 | T1, T2, E->getRParenLoc()); |
| 4821 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4823 | template<typename Derived> |
| 4824 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4825 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4826 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4827 | if (Cond.isInvalid()) |
| 4828 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4831 | if (LHS.isInvalid()) |
| 4832 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4835 | if (RHS.isInvalid()) |
| 4836 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | if (!getDerived().AlwaysRebuild() && |
| 4839 | Cond.get() == E->getCond() && |
| 4840 | LHS.get() == E->getLHS() && |
| 4841 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | return SemaRef.Owned(E->Retain()); |
| 4843 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4844 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4845 | move(Cond), move(LHS), move(RHS), |
| 4846 | E->getRParenLoc()); |
| 4847 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4848 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4849 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4850 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4851 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4852 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | template<typename Derived> |
| 4856 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4857 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4858 | switch (E->getOperator()) { |
| 4859 | case OO_New: |
| 4860 | case OO_Delete: |
| 4861 | case OO_Array_New: |
| 4862 | case OO_Array_Delete: |
| 4863 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4864 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4865 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4866 | case OO_Call: { |
| 4867 | // This is a call to an object's operator(). |
| 4868 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4869 | |
| 4870 | // Transform the object itself. |
| 4871 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4872 | if (Object.isInvalid()) |
| 4873 | return SemaRef.ExprError(); |
| 4874 | |
| 4875 | // FIXME: Poor location information |
| 4876 | SourceLocation FakeLParenLoc |
| 4877 | = SemaRef.PP.getLocForEndOfToken( |
| 4878 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4879 | |
| 4880 | // Transform the call arguments. |
| 4881 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4882 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4883 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4884 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4885 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4886 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4887 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4888 | if (Arg.isInvalid()) |
| 4889 | return SemaRef.ExprError(); |
| 4890 | |
| 4891 | // FIXME: Poor source location information. |
| 4892 | SourceLocation FakeCommaLoc |
| 4893 | = SemaRef.PP.getLocForEndOfToken( |
| 4894 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4895 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4896 | Args.push_back(Arg.release()); |
| 4897 | } |
| 4898 | |
| 4899 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4900 | move_arg(Args), |
| 4901 | FakeCommaLocs.data(), |
| 4902 | E->getLocEnd()); |
| 4903 | } |
| 4904 | |
| 4905 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4906 | case OO_##Name: |
| 4907 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4908 | #include "clang/Basic/OperatorKinds.def" |
| 4909 | case OO_Subscript: |
| 4910 | // Handled below. |
| 4911 | break; |
| 4912 | |
| 4913 | case OO_Conditional: |
| 4914 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4915 | return SemaRef.ExprError(); |
| 4916 | |
| 4917 | case OO_None: |
| 4918 | case NUM_OVERLOADED_OPERATORS: |
| 4919 | llvm_unreachable("not an overloaded operator?"); |
| 4920 | return SemaRef.ExprError(); |
| 4921 | } |
| 4922 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4923 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4924 | if (Callee.isInvalid()) |
| 4925 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4926 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4927 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4928 | if (First.isInvalid()) |
| 4929 | return SemaRef.ExprError(); |
| 4930 | |
| 4931 | OwningExprResult Second(SemaRef); |
| 4932 | if (E->getNumArgs() == 2) { |
| 4933 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4934 | if (Second.isInvalid()) |
| 4935 | return SemaRef.ExprError(); |
| 4936 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4938 | if (!getDerived().AlwaysRebuild() && |
| 4939 | Callee.get() == E->getCallee() && |
| 4940 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4942 | return SemaRef.Owned(E->Retain()); |
| 4943 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4944 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4945 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4946 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4947 | move(First), |
| 4948 | move(Second)); |
| 4949 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4951 | template<typename Derived> |
| 4952 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4953 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4954 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4955 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4956 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4957 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4959 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4960 | TypeSourceInfo *OldT; |
| 4961 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4962 | { |
| 4963 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4964 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4965 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4966 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4967 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4968 | OldT = E->getTypeInfoAsWritten(); |
| 4969 | NewT = getDerived().TransformType(OldT); |
| 4970 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4971 | return SemaRef.ExprError(); |
| 4972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4973 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4974 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4975 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4976 | if (SubExpr.isInvalid()) |
| 4977 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4979 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4980 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4981 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4982 | return SemaRef.Owned(E->Retain()); |
| 4983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4984 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4985 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4986 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4987 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4988 | SourceLocation FakeRParenLoc |
| 4989 | = SemaRef.PP.getLocForEndOfToken( |
| 4990 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4991 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4993 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4994 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4995 | FakeRAngleLoc, |
| 4996 | FakeRAngleLoc, |
| 4997 | move(SubExpr), |
| 4998 | FakeRParenLoc); |
| 4999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5001 | template<typename Derived> |
| 5002 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5003 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5004 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5005 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5006 | |
| 5007 | template<typename Derived> |
| 5008 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5009 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5010 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5013 | template<typename Derived> |
| 5014 | Sema::OwningExprResult |
| 5015 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5016 | CXXReinterpretCastExpr *E) { |
| 5017 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5020 | template<typename Derived> |
| 5021 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5022 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5023 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5025 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5026 | template<typename Derived> |
| 5027 | Sema::OwningExprResult |
| 5028 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5029 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5030 | TypeSourceInfo *OldT; |
| 5031 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5032 | { |
| 5033 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5034 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5035 | OldT = E->getTypeInfoAsWritten(); |
| 5036 | NewT = getDerived().TransformType(OldT); |
| 5037 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5038 | return SemaRef.ExprError(); |
| 5039 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5040 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5041 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5042 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5043 | if (SubExpr.isInvalid()) |
| 5044 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5045 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5046 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5047 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | return SemaRef.Owned(E->Retain()); |
| 5050 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5051 | // FIXME: The end of the type's source range is wrong |
| 5052 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5053 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5054 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5055 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5056 | move(SubExpr), |
| 5057 | E->getRParenLoc()); |
| 5058 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5060 | template<typename Derived> |
| 5061 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5062 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5063 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5064 | TypeSourceInfo *TInfo |
| 5065 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5066 | if (!TInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5069 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5070 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5071 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5072 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5073 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5074 | E->getLocStart(), |
| 5075 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | E->getLocEnd()); |
| 5077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5078 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5079 | // We don't know whether the expression is potentially evaluated until |
| 5080 | // after we perform semantic analysis, so the expression is potentially |
| 5081 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5082 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5083 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5085 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5086 | if (SubExpr.isInvalid()) |
| 5087 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5089 | if (!getDerived().AlwaysRebuild() && |
| 5090 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | return SemaRef.Owned(E->Retain()); |
| 5092 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5093 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5094 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | move(SubExpr), |
| 5096 | E->getLocEnd()); |
| 5097 | } |
| 5098 | |
| 5099 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5100 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5101 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5102 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5103 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5104 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5105 | template<typename Derived> |
| 5106 | Sema::OwningExprResult |
| 5107 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5108 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5110 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5112 | template<typename Derived> |
| 5113 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5114 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5117 | QualType T = getDerived().TransformType(E->getType()); |
| 5118 | if (T.isNull()) |
| 5119 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | if (!getDerived().AlwaysRebuild() && |
| 5122 | T == E->getType()) |
| 5123 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5125 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5128 | template<typename Derived> |
| 5129 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5130 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5131 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5132 | if (SubExpr.isInvalid()) |
| 5133 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5135 | if (!getDerived().AlwaysRebuild() && |
| 5136 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5138 | |
| 5139 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5142 | template<typename Derived> |
| 5143 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5144 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5145 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5146 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5147 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5148 | if (!Param) |
| 5149 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5151 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5152 | Param == E->getParam()) |
| 5153 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5155 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5157 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5158 | template<typename Derived> |
| 5159 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5160 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5162 | |
| 5163 | QualType T = getDerived().TransformType(E->getType()); |
| 5164 | if (T.isNull()) |
| 5165 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5166 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5167 | if (!getDerived().AlwaysRebuild() && |
| 5168 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | return SemaRef.Owned(E->Retain()); |
| 5170 | |
| 5171 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5173 | T, |
| 5174 | E->getRParenLoc()); |
| 5175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | template<typename Derived> |
| 5178 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5179 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | // Transform the type that we're allocating |
| 5181 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5182 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5183 | if (AllocType.isNull()) |
| 5184 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5186 | // Transform the size of the array we're allocating (if any). |
| 5187 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5188 | if (ArraySize.isInvalid()) |
| 5189 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5191 | // Transform the placement arguments (if any). |
| 5192 | bool ArgumentChanged = false; |
| 5193 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5194 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5195 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5196 | if (Arg.isInvalid()) |
| 5197 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5200 | PlacementArgs.push_back(Arg.take()); |
| 5201 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5203 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5205 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 5206 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5207 | if (Arg.isInvalid()) |
| 5208 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5211 | ConstructorArgs.push_back(Arg.take()); |
| 5212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5214 | // Transform constructor, new operator, and delete operator. |
| 5215 | CXXConstructorDecl *Constructor = 0; |
| 5216 | if (E->getConstructor()) { |
| 5217 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5218 | getDerived().TransformDecl(E->getLocStart(), |
| 5219 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5220 | if (!Constructor) |
| 5221 | return SemaRef.ExprError(); |
| 5222 | } |
| 5223 | |
| 5224 | FunctionDecl *OperatorNew = 0; |
| 5225 | if (E->getOperatorNew()) { |
| 5226 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5227 | getDerived().TransformDecl(E->getLocStart(), |
| 5228 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5229 | if (!OperatorNew) |
| 5230 | return SemaRef.ExprError(); |
| 5231 | } |
| 5232 | |
| 5233 | FunctionDecl *OperatorDelete = 0; |
| 5234 | if (E->getOperatorDelete()) { |
| 5235 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5236 | getDerived().TransformDecl(E->getLocStart(), |
| 5237 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5238 | if (!OperatorDelete) |
| 5239 | return SemaRef.ExprError(); |
| 5240 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5241 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5242 | if (!getDerived().AlwaysRebuild() && |
| 5243 | AllocType == E->getAllocatedType() && |
| 5244 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5245 | Constructor == E->getConstructor() && |
| 5246 | OperatorNew == E->getOperatorNew() && |
| 5247 | OperatorDelete == E->getOperatorDelete() && |
| 5248 | !ArgumentChanged) { |
| 5249 | // Mark any declarations we need as referenced. |
| 5250 | // FIXME: instantiation-specific. |
| 5251 | if (Constructor) |
| 5252 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5253 | if (OperatorNew) |
| 5254 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5255 | if (OperatorDelete) |
| 5256 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5258 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5259 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5260 | if (!ArraySize.get()) { |
| 5261 | // If no array size was specified, but the new expression was |
| 5262 | // instantiated with an array type (e.g., "new T" where T is |
| 5263 | // instantiated with "int[4]"), extract the outer bound from the |
| 5264 | // array type as our array size. We do this with constant and |
| 5265 | // dependently-sized array types. |
| 5266 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5267 | if (!ArrayT) { |
| 5268 | // Do nothing |
| 5269 | } else if (const ConstantArrayType *ConsArrayT |
| 5270 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5271 | ArraySize |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5272 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5273 | ConsArrayT->getSize(), |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5274 | SemaRef.Context.getSizeType(), |
| 5275 | /*FIXME:*/E->getLocStart())); |
| 5276 | AllocType = ConsArrayT->getElementType(); |
| 5277 | } else if (const DependentSizedArrayType *DepArrayT |
| 5278 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5279 | if (DepArrayT->getSizeExpr()) { |
| 5280 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5281 | AllocType = DepArrayT->getElementType(); |
| 5282 | } |
| 5283 | } |
| 5284 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5285 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5286 | E->isGlobalNew(), |
| 5287 | /*FIXME:*/E->getLocStart(), |
| 5288 | move_arg(PlacementArgs), |
| 5289 | /*FIXME:*/E->getLocStart(), |
| 5290 | E->isParenTypeId(), |
| 5291 | AllocType, |
| 5292 | /*FIXME:*/E->getLocStart(), |
| 5293 | /*FIXME:*/SourceRange(), |
| 5294 | move(ArraySize), |
| 5295 | /*FIXME:*/E->getLocStart(), |
| 5296 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5299 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5300 | template<typename Derived> |
| 5301 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5302 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5303 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5304 | if (Operand.isInvalid()) |
| 5305 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5306 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5307 | // Transform the delete operator, if known. |
| 5308 | FunctionDecl *OperatorDelete = 0; |
| 5309 | if (E->getOperatorDelete()) { |
| 5310 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5311 | getDerived().TransformDecl(E->getLocStart(), |
| 5312 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5313 | if (!OperatorDelete) |
| 5314 | return SemaRef.ExprError(); |
| 5315 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5316 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5317 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5318 | Operand.get() == E->getArgument() && |
| 5319 | OperatorDelete == E->getOperatorDelete()) { |
| 5320 | // Mark any declarations we need as referenced. |
| 5321 | // FIXME: instantiation-specific. |
| 5322 | if (OperatorDelete) |
| 5323 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5324 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5327 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5328 | E->isGlobalDelete(), |
| 5329 | E->isArrayForm(), |
| 5330 | move(Operand)); |
| 5331 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5332 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5333 | template<typename Derived> |
| 5334 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5335 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5336 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5337 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5338 | if (Base.isInvalid()) |
| 5339 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5341 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5342 | bool MayBePseudoDestructor = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5343 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5344 | E->getOperatorLoc(), |
| 5345 | E->isArrow()? tok::arrow : tok::period, |
| 5346 | ObjectTypePtr, |
| 5347 | MayBePseudoDestructor); |
| 5348 | if (Base.isInvalid()) |
| 5349 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5350 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5351 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5352 | NestedNameSpecifier *Qualifier |
| 5353 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5354 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5355 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5356 | if (E->getQualifier() && !Qualifier) |
| 5357 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5358 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5359 | PseudoDestructorTypeStorage Destroyed; |
| 5360 | if (E->getDestroyedTypeInfo()) { |
| 5361 | TypeSourceInfo *DestroyedTypeInfo |
| 5362 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5363 | if (!DestroyedTypeInfo) |
| 5364 | return SemaRef.ExprError(); |
| 5365 | Destroyed = DestroyedTypeInfo; |
| 5366 | } else if (ObjectType->isDependentType()) { |
| 5367 | // We aren't likely to be able to resolve the identifier down to a type |
| 5368 | // now anyway, so just retain the identifier. |
| 5369 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5370 | E->getDestroyedTypeLoc()); |
| 5371 | } else { |
| 5372 | // Look for a destructor known with the given name. |
| 5373 | CXXScopeSpec SS; |
| 5374 | if (Qualifier) { |
| 5375 | SS.setScopeRep(Qualifier); |
| 5376 | SS.setRange(E->getQualifierRange()); |
| 5377 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5378 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5379 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5380 | *E->getDestroyedTypeIdentifier(), |
| 5381 | E->getDestroyedTypeLoc(), |
| 5382 | /*Scope=*/0, |
| 5383 | SS, ObjectTypePtr, |
| 5384 | false); |
| 5385 | if (!T) |
| 5386 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5387 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5388 | Destroyed |
| 5389 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5390 | E->getDestroyedTypeLoc()); |
| 5391 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5392 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5393 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5394 | if (E->getScopeTypeInfo()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5395 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5396 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5397 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5398 | return SemaRef.ExprError(); |
| 5399 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5400 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5401 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5402 | E->getOperatorLoc(), |
| 5403 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5404 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5405 | E->getQualifierRange(), |
| 5406 | ScopeTypeInfo, |
| 5407 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5408 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5409 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5410 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5412 | template<typename Derived> |
| 5413 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5414 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5415 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5416 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5417 | |
| 5418 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5419 | Sema::LookupOrdinaryName); |
| 5420 | |
| 5421 | // Transform all the decls. |
| 5422 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5423 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5424 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5425 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5426 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5427 | if (!InstD) { |
| 5428 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5429 | // This can happen because of dependent hiding. |
| 5430 | if (isa<UsingShadowDecl>(*I)) |
| 5431 | continue; |
| 5432 | else |
| 5433 | return SemaRef.ExprError(); |
| 5434 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5435 | |
| 5436 | // Expand using declarations. |
| 5437 | if (isa<UsingDecl>(InstD)) { |
| 5438 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5439 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5440 | E = UD->shadow_end(); I != E; ++I) |
| 5441 | R.addDecl(*I); |
| 5442 | continue; |
| 5443 | } |
| 5444 | |
| 5445 | R.addDecl(InstD); |
| 5446 | } |
| 5447 | |
| 5448 | // Resolve a kind, but don't do any further analysis. If it's |
| 5449 | // ambiguous, the callee needs to deal with it. |
| 5450 | R.resolveKind(); |
| 5451 | |
| 5452 | // Rebuild the nested-name qualifier, if present. |
| 5453 | CXXScopeSpec SS; |
| 5454 | NestedNameSpecifier *Qualifier = 0; |
| 5455 | if (Old->getQualifier()) { |
| 5456 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5457 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5458 | if (!Qualifier) |
| 5459 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5460 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5461 | SS.setScopeRep(Qualifier); |
| 5462 | SS.setRange(Old->getQualifierRange()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5463 | } |
| 5464 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5465 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5466 | CXXRecordDecl *NamingClass |
| 5467 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5468 | Old->getNameLoc(), |
| 5469 | Old->getNamingClass())); |
| 5470 | if (!NamingClass) |
| 5471 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5472 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5473 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | // If we have no template arguments, it's a normal declaration name. |
| 5477 | if (!Old->hasExplicitTemplateArgs()) |
| 5478 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5479 | |
| 5480 | // If we have template arguments, rebuild them, then rebuild the |
| 5481 | // templateid expression. |
| 5482 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5483 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5484 | TemplateArgumentLoc Loc; |
| 5485 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5486 | return SemaRef.ExprError(); |
| 5487 | TransArgs.addArgument(Loc); |
| 5488 | } |
| 5489 | |
| 5490 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5491 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5494 | template<typename Derived> |
| 5495 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5496 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5497 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5498 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5500 | if (T.isNull()) |
| 5501 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5503 | if (!getDerived().AlwaysRebuild() && |
| 5504 | T == E->getQueriedType()) |
| 5505 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5507 | // FIXME: Bad location information |
| 5508 | SourceLocation FakeLParenLoc |
| 5509 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5510 | |
| 5511 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5512 | E->getLocStart(), |
| 5513 | /*FIXME:*/FakeLParenLoc, |
| 5514 | T, |
| 5515 | E->getLocEnd()); |
| 5516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
| 5519 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5520 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5521 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5522 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5523 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5524 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5525 | if (!NNS) |
| 5526 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5527 | |
| 5528 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5529 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5530 | if (!Name) |
| 5531 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5532 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5533 | if (!E->hasExplicitTemplateArgs()) { |
| 5534 | if (!getDerived().AlwaysRebuild() && |
| 5535 | NNS == E->getQualifier() && |
| 5536 | Name == E->getDeclName()) |
| 5537 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5538 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5539 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5540 | E->getQualifierRange(), |
| 5541 | Name, E->getLocation(), |
| 5542 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5543 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5544 | |
| 5545 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5546 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5547 | TemplateArgumentLoc Loc; |
| 5548 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5549 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5550 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5551 | } |
| 5552 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5553 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5554 | E->getQualifierRange(), |
| 5555 | Name, E->getLocation(), |
| 5556 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | template<typename Derived> |
| 5560 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5561 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5562 | // CXXConstructExprs are always implicit, so when we have a |
| 5563 | // 1-argument construction we just transform that argument. |
| 5564 | if (E->getNumArgs() == 1 || |
| 5565 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5566 | return getDerived().TransformExpr(E->getArg(0)); |
| 5567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5569 | |
| 5570 | QualType T = getDerived().TransformType(E->getType()); |
| 5571 | if (T.isNull()) |
| 5572 | return SemaRef.ExprError(); |
| 5573 | |
| 5574 | CXXConstructorDecl *Constructor |
| 5575 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5576 | getDerived().TransformDecl(E->getLocStart(), |
| 5577 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5578 | if (!Constructor) |
| 5579 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5581 | bool ArgumentChanged = false; |
| 5582 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5584 | ArgEnd = E->arg_end(); |
| 5585 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5586 | if (getDerived().DropCallArgument(*Arg)) { |
| 5587 | ArgumentChanged = true; |
| 5588 | break; |
| 5589 | } |
| 5590 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5592 | if (TransArg.isInvalid()) |
| 5593 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5596 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5597 | } |
| 5598 | |
| 5599 | if (!getDerived().AlwaysRebuild() && |
| 5600 | T == E->getType() && |
| 5601 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5602 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5603 | // Mark the constructor as referenced. |
| 5604 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5605 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5608 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5609 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5610 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5611 | move_arg(Args)); |
| 5612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5614 | /// \brief Transform a C++ temporary-binding expression. |
| 5615 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5616 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5617 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5618 | template<typename Derived> |
| 5619 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5620 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5621 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5623 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5624 | /// \brief Transform a C++ reference-binding expression. |
| 5625 | /// |
| 5626 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5627 | /// transform the subexpression and return that. |
| 5628 | template<typename Derived> |
| 5629 | Sema::OwningExprResult |
| 5630 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5631 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5632 | } |
| 5633 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5635 | /// be destroyed after the expression is evaluated. |
| 5636 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5637 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5638 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5639 | template<typename Derived> |
| 5640 | Sema::OwningExprResult |
| 5641 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5642 | CXXExprWithTemporaries *E) { |
| 5643 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5646 | template<typename Derived> |
| 5647 | Sema::OwningExprResult |
| 5648 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5649 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5650 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5651 | QualType T = getDerived().TransformType(E->getType()); |
| 5652 | if (T.isNull()) |
| 5653 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5654 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5655 | CXXConstructorDecl *Constructor |
| 5656 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5657 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5658 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5659 | if (!Constructor) |
| 5660 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5661 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5662 | bool ArgumentChanged = false; |
| 5663 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5664 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5665 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5666 | ArgEnd = E->arg_end(); |
| 5667 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5668 | if (getDerived().DropCallArgument(*Arg)) { |
| 5669 | ArgumentChanged = true; |
| 5670 | break; |
| 5671 | } |
| 5672 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5673 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5674 | if (TransArg.isInvalid()) |
| 5675 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5677 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5678 | Args.push_back((Expr *)TransArg.release()); |
| 5679 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5681 | if (!getDerived().AlwaysRebuild() && |
| 5682 | T == E->getType() && |
| 5683 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5684 | !ArgumentChanged) { |
| 5685 | // FIXME: Instantiation-specific |
| 5686 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5687 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | // FIXME: Bogus location information |
| 5691 | SourceLocation CommaLoc; |
| 5692 | if (Args.size() > 1) { |
| 5693 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5694 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5695 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5696 | } |
| 5697 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5698 | T, |
| 5699 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5700 | move_arg(Args), |
| 5701 | &CommaLoc, |
| 5702 | E->getLocEnd()); |
| 5703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5705 | template<typename Derived> |
| 5706 | Sema::OwningExprResult |
| 5707 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5708 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5709 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5710 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5711 | if (T.isNull()) |
| 5712 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5714 | bool ArgumentChanged = false; |
| 5715 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5716 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5717 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5718 | ArgEnd = E->arg_end(); |
| 5719 | Arg != ArgEnd; ++Arg) { |
| 5720 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5721 | if (TransArg.isInvalid()) |
| 5722 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5723 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5724 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5725 | FakeCommaLocs.push_back( |
| 5726 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5727 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | if (!getDerived().AlwaysRebuild() && |
| 5731 | T == E->getTypeAsWritten() && |
| 5732 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5733 | return SemaRef.Owned(E->Retain()); |
| 5734 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5735 | // FIXME: we're faking the locations of the commas |
| 5736 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5737 | T, |
| 5738 | E->getLParenLoc(), |
| 5739 | move_arg(Args), |
| 5740 | FakeCommaLocs.data(), |
| 5741 | E->getRParenLoc()); |
| 5742 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5743 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5744 | template<typename Derived> |
| 5745 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5746 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5747 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5748 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5749 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5750 | Expr *OldBase; |
| 5751 | QualType BaseType; |
| 5752 | QualType ObjectType; |
| 5753 | if (!E->isImplicitAccess()) { |
| 5754 | OldBase = E->getBase(); |
| 5755 | Base = getDerived().TransformExpr(OldBase); |
| 5756 | if (Base.isInvalid()) |
| 5757 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5758 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5759 | // Start the member reference and compute the object's type. |
| 5760 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5761 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5762 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5763 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5764 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5765 | ObjectTy, |
| 5766 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5767 | if (Base.isInvalid()) |
| 5768 | return SemaRef.ExprError(); |
| 5769 | |
| 5770 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5771 | BaseType = ((Expr*) Base.get())->getType(); |
| 5772 | } else { |
| 5773 | OldBase = 0; |
| 5774 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5775 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5777 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5778 | // Transform the first part of the nested-name-specifier that qualifies |
| 5779 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5780 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5781 | = getDerived().TransformFirstQualifierInScope( |
| 5782 | E->getFirstQualifierFoundInScope(), |
| 5783 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5784 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5785 | NestedNameSpecifier *Qualifier = 0; |
| 5786 | if (E->getQualifier()) { |
| 5787 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5788 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5789 | ObjectType, |
| 5790 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5791 | if (!Qualifier) |
| 5792 | return SemaRef.ExprError(); |
| 5793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5794 | |
| 5795 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5796 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5797 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5798 | if (!Name) |
| 5799 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5800 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5801 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5802 | // This is a reference to a member without an explicitly-specified |
| 5803 | // template argument list. Optimize for this common case. |
| 5804 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5805 | Base.get() == OldBase && |
| 5806 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5807 | Qualifier == E->getQualifier() && |
| 5808 | Name == E->getMember() && |
| 5809 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5810 | return SemaRef.Owned(E->Retain()); |
| 5811 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5812 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5813 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5814 | E->isArrow(), |
| 5815 | E->getOperatorLoc(), |
| 5816 | Qualifier, |
| 5817 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5818 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5819 | Name, |
| 5820 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5821 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5822 | } |
| 5823 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5824 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5825 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5826 | TemplateArgumentLoc Loc; |
| 5827 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5828 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5829 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5830 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5831 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5832 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5833 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5834 | E->isArrow(), |
| 5835 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5836 | Qualifier, |
| 5837 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5838 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5839 | Name, |
| 5840 | E->getMemberLoc(), |
| 5841 | &TransArgs); |
| 5842 | } |
| 5843 | |
| 5844 | template<typename Derived> |
| 5845 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5846 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5847 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5848 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5849 | QualType BaseType; |
| 5850 | if (!Old->isImplicitAccess()) { |
| 5851 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5852 | if (Base.isInvalid()) |
| 5853 | return SemaRef.ExprError(); |
| 5854 | BaseType = ((Expr*) Base.get())->getType(); |
| 5855 | } else { |
| 5856 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5857 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5858 | |
| 5859 | NestedNameSpecifier *Qualifier = 0; |
| 5860 | if (Old->getQualifier()) { |
| 5861 | Qualifier |
| 5862 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5863 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5864 | if (Qualifier == 0) |
| 5865 | return SemaRef.ExprError(); |
| 5866 | } |
| 5867 | |
| 5868 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5869 | Sema::LookupOrdinaryName); |
| 5870 | |
| 5871 | // Transform all the decls. |
| 5872 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5873 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5874 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5875 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5876 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5877 | if (!InstD) { |
| 5878 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5879 | // This can happen because of dependent hiding. |
| 5880 | if (isa<UsingShadowDecl>(*I)) |
| 5881 | continue; |
| 5882 | else |
| 5883 | return SemaRef.ExprError(); |
| 5884 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5885 | |
| 5886 | // Expand using declarations. |
| 5887 | if (isa<UsingDecl>(InstD)) { |
| 5888 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5889 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5890 | E = UD->shadow_end(); I != E; ++I) |
| 5891 | R.addDecl(*I); |
| 5892 | continue; |
| 5893 | } |
| 5894 | |
| 5895 | R.addDecl(InstD); |
| 5896 | } |
| 5897 | |
| 5898 | R.resolveKind(); |
| 5899 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5900 | // Determine the naming class. |
| 5901 | if (!Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5902 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5903 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5904 | Old->getMemberLoc(), |
| 5905 | Old->getNamingClass())); |
| 5906 | if (!NamingClass) |
| 5907 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5908 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5909 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5910 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5911 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5912 | TemplateArgumentListInfo TransArgs; |
| 5913 | if (Old->hasExplicitTemplateArgs()) { |
| 5914 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5915 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5916 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5917 | TemplateArgumentLoc Loc; |
| 5918 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5919 | Loc)) |
| 5920 | return SemaRef.ExprError(); |
| 5921 | TransArgs.addArgument(Loc); |
| 5922 | } |
| 5923 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5924 | |
| 5925 | // FIXME: to do this check properly, we will need to preserve the |
| 5926 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5927 | // base (and therefore couldn't do the check) and a |
| 5928 | // nested-name-qualifier (and therefore could do the lookup). |
| 5929 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5930 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5931 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5932 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5933 | Old->getOperatorLoc(), |
| 5934 | Old->isArrow(), |
| 5935 | Qualifier, |
| 5936 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5937 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5938 | R, |
| 5939 | (Old->hasExplicitTemplateArgs() |
| 5940 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | template<typename Derived> |
| 5944 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5945 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5946 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5949 | template<typename Derived> |
| 5950 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5951 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5952 | TypeSourceInfo *EncodedTypeInfo |
| 5953 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5954 | if (!EncodedTypeInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5955 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5956 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5957 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5958 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5959 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5960 | |
| 5961 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5962 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5963 | E->getRParenLoc()); |
| 5964 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5966 | template<typename Derived> |
| 5967 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5968 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5969 | // Transform arguments. |
| 5970 | bool ArgChanged = false; |
| 5971 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5972 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5973 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5974 | if (Arg.isInvalid()) |
| 5975 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5976 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5977 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5978 | Args.push_back(Arg.takeAs<Expr>()); |
| 5979 | } |
| 5980 | |
| 5981 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5982 | // Class message: transform the receiver type. |
| 5983 | TypeSourceInfo *ReceiverTypeInfo |
| 5984 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5985 | if (!ReceiverTypeInfo) |
| 5986 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5987 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5988 | // If nothing changed, just retain the existing message send. |
| 5989 | if (!getDerived().AlwaysRebuild() && |
| 5990 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5991 | return SemaRef.Owned(E->Retain()); |
| 5992 | |
| 5993 | // Build a new class message send. |
| 5994 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5995 | E->getSelector(), |
| 5996 | E->getMethodDecl(), |
| 5997 | E->getLeftLoc(), |
| 5998 | move_arg(Args), |
| 5999 | E->getRightLoc()); |
| 6000 | } |
| 6001 | |
| 6002 | // Instance message: transform the receiver |
| 6003 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 6004 | "Only class and instance messages may be instantiated"); |
| 6005 | OwningExprResult Receiver |
| 6006 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 6007 | if (Receiver.isInvalid()) |
| 6008 | return SemaRef.ExprError(); |
| 6009 | |
| 6010 | // If nothing changed, just retain the existing message send. |
| 6011 | if (!getDerived().AlwaysRebuild() && |
| 6012 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 6013 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6014 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6015 | // Build a new instance message send. |
| 6016 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 6017 | E->getSelector(), |
| 6018 | E->getMethodDecl(), |
| 6019 | E->getLeftLoc(), |
| 6020 | move_arg(Args), |
| 6021 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6024 | template<typename Derived> |
| 6025 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6026 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6027 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6028 | } |
| 6029 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6030 | template<typename Derived> |
| 6031 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6032 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6033 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6034 | } |
| 6035 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6036 | template<typename Derived> |
| 6037 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6038 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6039 | // Transform the base expression. |
| 6040 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6041 | if (Base.isInvalid()) |
| 6042 | return SemaRef.ExprError(); |
| 6043 | |
| 6044 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6045 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6046 | // If nothing changed, just retain the existing expression. |
| 6047 | if (!getDerived().AlwaysRebuild() && |
| 6048 | Base.get() == E->getBase()) |
| 6049 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6050 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6051 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6052 | E->getLocation(), |
| 6053 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6054 | } |
| 6055 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6056 | template<typename Derived> |
| 6057 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6058 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6059 | // Transform the base expression. |
| 6060 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6061 | if (Base.isInvalid()) |
| 6062 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6063 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6064 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6065 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6066 | // If nothing changed, just retain the existing expression. |
| 6067 | if (!getDerived().AlwaysRebuild() && |
| 6068 | Base.get() == E->getBase()) |
| 6069 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6070 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6071 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6072 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6073 | } |
| 6074 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6075 | template<typename Derived> |
| 6076 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6077 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6078 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6079 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6080 | // dependent parts. Just retain the existing declaration. |
| 6081 | if (E->getInterfaceDecl()) |
| 6082 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6083 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6084 | // Transform the base expression. |
| 6085 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6086 | if (Base.isInvalid()) |
| 6087 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6088 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6089 | // We don't need to transform the getters/setters; they will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6090 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6091 | // If nothing changed, just retain the existing expression. |
| 6092 | if (!getDerived().AlwaysRebuild() && |
| 6093 | Base.get() == E->getBase()) |
| 6094 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6095 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6096 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6097 | E->getGetterMethod(), |
| 6098 | E->getType(), |
| 6099 | E->getSetterMethod(), |
| 6100 | E->getLocation(), |
| 6101 | move(Base)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6102 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6103 | } |
| 6104 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6105 | template<typename Derived> |
| 6106 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6107 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6108 | // Can never occur in a dependent context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6109 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6110 | } |
| 6111 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6112 | template<typename Derived> |
| 6113 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6114 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6115 | // Transform the base expression. |
| 6116 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6117 | if (Base.isInvalid()) |
| 6118 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6119 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6120 | // If nothing changed, just retain the existing expression. |
| 6121 | if (!getDerived().AlwaysRebuild() && |
| 6122 | Base.get() == E->getBase()) |
| 6123 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6124 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6125 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6126 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6129 | template<typename Derived> |
| 6130 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6131 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6132 | bool ArgumentChanged = false; |
| 6133 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6134 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6135 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6136 | if (SubExpr.isInvalid()) |
| 6137 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6138 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6139 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6140 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6141 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6142 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6143 | if (!getDerived().AlwaysRebuild() && |
| 6144 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6145 | return SemaRef.Owned(E->Retain()); |
| 6146 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6147 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6148 | move_arg(SubExprs), |
| 6149 | E->getRParenLoc()); |
| 6150 | } |
| 6151 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6152 | template<typename Derived> |
| 6153 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6154 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6155 | // FIXME: Implement this! |
| 6156 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6157 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6158 | } |
| 6159 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6160 | template<typename Derived> |
| 6161 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6162 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6163 | // FIXME: Implement this! |
| 6164 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6165 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6168 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6169 | // Type reconstruction |
| 6170 | //===----------------------------------------------------------------------===// |
| 6171 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6172 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6173 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6174 | SourceLocation Star) { |
| 6175 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6176 | getDerived().getBaseEntity()); |
| 6177 | } |
| 6178 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6179 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6180 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6181 | SourceLocation Star) { |
| 6182 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6183 | getDerived().getBaseEntity()); |
| 6184 | } |
| 6185 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6186 | template<typename Derived> |
| 6187 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6188 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6189 | bool WrittenAsLValue, |
| 6190 | SourceLocation Sigil) { |
| 6191 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 6192 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6196 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6197 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6198 | QualType ClassType, |
| 6199 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 6200 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6201 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6205 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6206 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6207 | ArrayType::ArraySizeModifier SizeMod, |
| 6208 | const llvm::APInt *Size, |
| 6209 | Expr *SizeExpr, |
| 6210 | unsigned IndexTypeQuals, |
| 6211 | SourceRange BracketsRange) { |
| 6212 | if (SizeExpr || !Size) |
| 6213 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6214 | IndexTypeQuals, BracketsRange, |
| 6215 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6216 | |
| 6217 | QualType Types[] = { |
| 6218 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6219 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6220 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6221 | }; |
| 6222 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6223 | QualType SizeType; |
| 6224 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6225 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6226 | SizeType = Types[I]; |
| 6227 | break; |
| 6228 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6229 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6230 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6231 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6232 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6233 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6234 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6235 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6236 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | QualType |
| 6238 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6239 | ArrayType::ArraySizeModifier SizeMod, |
| 6240 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6241 | unsigned IndexTypeQuals, |
| 6242 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6243 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6244 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6248 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6249 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6250 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6251 | unsigned IndexTypeQuals, |
| 6252 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6253 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6254 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6255 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6256 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6257 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6258 | QualType |
| 6259 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6260 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6261 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6262 | unsigned IndexTypeQuals, |
| 6263 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6264 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6265 | SizeExpr.takeAs<Expr>(), |
| 6266 | IndexTypeQuals, BracketsRange); |
| 6267 | } |
| 6268 | |
| 6269 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6270 | QualType |
| 6271 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6272 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6273 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6274 | unsigned IndexTypeQuals, |
| 6275 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6276 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6277 | SizeExpr.takeAs<Expr>(), |
| 6278 | IndexTypeQuals, BracketsRange); |
| 6279 | } |
| 6280 | |
| 6281 | template<typename Derived> |
| 6282 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6283 | unsigned NumElements, |
| 6284 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6285 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6286 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 6287 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6288 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6290 | template<typename Derived> |
| 6291 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6292 | unsigned NumElements, |
| 6293 | SourceLocation AttributeLoc) { |
| 6294 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6295 | NumElements, true); |
| 6296 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6297 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6298 | AttributeLoc); |
| 6299 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6300 | AttributeLoc); |
| 6301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6302 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6303 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6304 | QualType |
| 6305 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6306 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6307 | SourceLocation AttributeLoc) { |
| 6308 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6309 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6310 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6311 | template<typename Derived> |
| 6312 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6313 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6314 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6315 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6316 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6317 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6318 | Quals, |
| 6319 | getDerived().getBaseLocation(), |
| 6320 | getDerived().getBaseEntity()); |
| 6321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6322 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6323 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6324 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6325 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6326 | } |
| 6327 | |
| 6328 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6329 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6330 | assert(D && "no decl found"); |
| 6331 | if (D->isInvalidDecl()) return QualType(); |
| 6332 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6333 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6334 | TypeDecl *Ty; |
| 6335 | if (isa<UsingDecl>(D)) { |
| 6336 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6337 | assert(Using->isTypeName() && |
| 6338 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6339 | |
| 6340 | // A valid resolved using typename decl points to exactly one type decl. |
| 6341 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6342 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6343 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6344 | } else { |
| 6345 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6346 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6347 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6348 | } |
| 6349 | |
| 6350 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6351 | } |
| 6352 | |
| 6353 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6354 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6355 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6356 | } |
| 6357 | |
| 6358 | template<typename Derived> |
| 6359 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6360 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6361 | } |
| 6362 | |
| 6363 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6364 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6365 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6366 | } |
| 6367 | |
| 6368 | template<typename Derived> |
| 6369 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6370 | TemplateName Template, |
| 6371 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6372 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6373 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6374 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6375 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6376 | template<typename Derived> |
| 6377 | NestedNameSpecifier * |
| 6378 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6379 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6380 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6381 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6382 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6383 | CXXScopeSpec SS; |
| 6384 | // FIXME: The source location information is all wrong. |
| 6385 | SS.setRange(Range); |
| 6386 | SS.setScopeRep(Prefix); |
| 6387 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6388 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6389 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6390 | ObjectType, |
| 6391 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6392 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | template<typename Derived> |
| 6396 | NestedNameSpecifier * |
| 6397 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6398 | SourceRange Range, |
| 6399 | NamespaceDecl *NS) { |
| 6400 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6401 | } |
| 6402 | |
| 6403 | template<typename Derived> |
| 6404 | NestedNameSpecifier * |
| 6405 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6406 | SourceRange Range, |
| 6407 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6408 | QualType T) { |
| 6409 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6410 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6411 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6412 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6413 | T.getTypePtr()); |
| 6414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6415 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6416 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6417 | return 0; |
| 6418 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6419 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6420 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6421 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6422 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6423 | bool TemplateKW, |
| 6424 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6425 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6426 | Template); |
| 6427 | } |
| 6428 | |
| 6429 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6430 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6431 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6432 | const IdentifierInfo &II, |
| 6433 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6434 | CXXScopeSpec SS; |
| 6435 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6436 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6437 | UnqualifiedId Name; |
| 6438 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6439 | return getSema().ActOnDependentTemplateName( |
| 6440 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6441 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6442 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6443 | ObjectType.getAsOpaquePtr(), |
| 6444 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6445 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6446 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6447 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6448 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6449 | TemplateName |
| 6450 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6451 | OverloadedOperatorKind Operator, |
| 6452 | QualType ObjectType) { |
| 6453 | CXXScopeSpec SS; |
| 6454 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6455 | SS.setScopeRep(Qualifier); |
| 6456 | UnqualifiedId Name; |
| 6457 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6458 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6459 | Operator, SymbolLocations); |
| 6460 | return getSema().ActOnDependentTemplateName( |
| 6461 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6462 | SS, |
| 6463 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6464 | ObjectType.getAsOpaquePtr(), |
| 6465 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6466 | .template getAsVal<TemplateName>(); |
| 6467 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6468 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6469 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6470 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6471 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6472 | SourceLocation OpLoc, |
| 6473 | ExprArg Callee, |
| 6474 | ExprArg First, |
| 6475 | ExprArg Second) { |
| 6476 | Expr *FirstExpr = (Expr *)First.get(); |
| 6477 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6478 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6479 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6480 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6481 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6482 | if (Op == OO_Subscript) { |
| 6483 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6484 | !SecondExpr->getType()->isOverloadableType()) |
| 6485 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6486 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6487 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6488 | } else if (Op == OO_Arrow) { |
| 6489 | // -> is never a builtin operation. |
| 6490 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6491 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6492 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6493 | // The argument is not of overloadable type, so try to create a |
| 6494 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6495 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6496 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6497 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6498 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6499 | } |
| 6500 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6501 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6502 | !SecondExpr->getType()->isOverloadableType()) { |
| 6503 | // Neither of the arguments is an overloadable type, so try to |
| 6504 | // create a built-in binary operation. |
| 6505 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6506 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6507 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6508 | if (Result.isInvalid()) |
| 6509 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6511 | First.release(); |
| 6512 | Second.release(); |
| 6513 | return move(Result); |
| 6514 | } |
| 6515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6516 | |
| 6517 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6518 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6519 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6520 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6521 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6522 | assert(ULE->requiresADL()); |
| 6523 | |
| 6524 | // FIXME: Do we have to check |
| 6525 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6526 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6527 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6528 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6530 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6531 | // Add any functions found via argument-dependent lookup. |
| 6532 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6533 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6534 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6535 | // Create the overloaded operator invocation for unary operators. |
| 6536 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6537 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6538 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6539 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6540 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6541 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6542 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6543 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6544 | OpLoc, |
| 6545 | move(First), |
| 6546 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6547 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6548 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6549 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6550 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6551 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6552 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6553 | if (Result.isInvalid()) |
| 6554 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6555 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6556 | First.release(); |
| 6557 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6558 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6560 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6561 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6562 | Sema::OwningExprResult |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6563 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6564 | SourceLocation OperatorLoc, |
| 6565 | bool isArrow, |
| 6566 | NestedNameSpecifier *Qualifier, |
| 6567 | SourceRange QualifierRange, |
| 6568 | TypeSourceInfo *ScopeType, |
| 6569 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6570 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6571 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6572 | CXXScopeSpec SS; |
| 6573 | if (Qualifier) { |
| 6574 | SS.setRange(QualifierRange); |
| 6575 | SS.setScopeRep(Qualifier); |
| 6576 | } |
| 6577 | |
| 6578 | Expr *BaseE = (Expr *)Base.get(); |
| 6579 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6580 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6581 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6582 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6583 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6584 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6585 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6586 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6587 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6588 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6589 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6590 | /*FIXME?*/true); |
| 6591 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6592 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6593 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6594 | DeclarationName Name |
| 6595 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6596 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6597 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6598 | // FIXME: the ScopeType should be tacked onto SS. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6599 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6600 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6601 | OperatorLoc, isArrow, |
| 6602 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6603 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6604 | /*TemplateArgs*/ 0); |
| 6605 | } |
| 6606 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6607 | } // end namespace clang |
| 6608 | |
| 6609 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |