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 | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 347 | #define ABSTRACT_STMT(Stmt) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 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, |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 445 | VectorType::AltiVecSpecific AltiVecSpec); |
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 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 496 | /// |
| 497 | /// By default, performs semantic analysis when building the typeof type. |
| 498 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 499 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 500 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 502 | /// |
| 503 | /// By default, builds a new TypeOfType with the given underlying type. |
| 504 | QualType RebuildTypeOfType(QualType Underlying); |
| 505 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, performs semantic analysis when building the decltype type. |
| 509 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 510 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// \brief Build a new template specialization type. |
| 513 | /// |
| 514 | /// By default, performs semantic analysis when building the template |
| 515 | /// specialization type. Subclasses may override this routine to provide |
| 516 | /// different behavior. |
| 517 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 518 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 519 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | /// \brief Build a new qualified name type. |
| 522 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 523 | /// By default, builds a new ElaboratedType type from the keyword, |
| 524 | /// the nested-name-specifier and the named type. |
| 525 | /// Subclasses may override this routine to provide different behavior. |
| 526 | QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword, |
| 527 | NestedNameSpecifier *NNS, QualType Named) { |
| 528 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | |
| 531 | /// \brief Build a new typename type that refers to a template-id. |
| 532 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 533 | /// By default, builds a new DependentNameType type from the |
| 534 | /// nested-name-specifier and the given type. Subclasses may override |
| 535 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 536 | QualType RebuildDependentTemplateSpecializationType( |
| 537 | ElaboratedTypeKeyword Keyword, |
| 538 | NestedNameSpecifier *NNS, |
| 539 | const IdentifierInfo *Name, |
| 540 | SourceLocation NameLoc, |
| 541 | const TemplateArgumentListInfo &Args) { |
| 542 | // Rebuild the template name. |
| 543 | // TODO: avoid TemplateName abstraction |
| 544 | TemplateName InstName = |
| 545 | getDerived().RebuildTemplateName(NNS, *Name, QualType()); |
| 546 | |
Douglas Gregor | 96fb42e | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 547 | if (InstName.isNull()) |
| 548 | return QualType(); |
| 549 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 550 | // If it's still dependent, make a dependent specialization. |
| 551 | if (InstName.getAsDependentTemplateName()) |
| 552 | return SemaRef.Context.getDependentTemplateSpecializationType( |
| 553 | Keyword, NNS, Name, Args); |
| 554 | |
| 555 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 556 | // specialization. |
| 557 | QualType T = |
| 558 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 559 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 560 | |
| 561 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 563 | |
| 564 | /// \brief Build a new typename type that refers to an identifier. |
| 565 | /// |
| 566 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 567 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 568 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 569 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 570 | NestedNameSpecifier *NNS, |
| 571 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 572 | SourceLocation KeywordLoc, |
| 573 | SourceRange NNSRange, |
| 574 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 575 | CXXScopeSpec SS; |
| 576 | SS.setScopeRep(NNS); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 577 | SS.setRange(NNSRange); |
| 578 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 579 | if (NNS->isDependent()) { |
| 580 | // If the name is still dependent, just build a new dependent name type. |
| 581 | if (!SemaRef.computeDeclContext(SS)) |
| 582 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 583 | } |
| 584 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 585 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 586 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, |
| 587 | KeywordLoc, NNSRange, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 588 | |
| 589 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 590 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 591 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 592 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 593 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 594 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 595 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 596 | if (!DC) |
| 597 | return QualType(); |
| 598 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 599 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 600 | return QualType(); |
| 601 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 602 | TagDecl *Tag = 0; |
| 603 | SemaRef.LookupQualifiedName(Result, DC); |
| 604 | switch (Result.getResultKind()) { |
| 605 | case LookupResult::NotFound: |
| 606 | case LookupResult::NotFoundInCurrentInstantiation: |
| 607 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 608 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 609 | case LookupResult::Found: |
| 610 | Tag = Result.getAsSingle<TagDecl>(); |
| 611 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 613 | case LookupResult::FoundOverloaded: |
| 614 | case LookupResult::FoundUnresolvedValue: |
| 615 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 616 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 617 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 618 | case LookupResult::Ambiguous: |
| 619 | // Let the LookupResult structure handle ambiguities. |
| 620 | return QualType(); |
| 621 | } |
| 622 | |
| 623 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 624 | // FIXME: Would be nice to highlight just the source range. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 625 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 626 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 627 | return QualType(); |
| 628 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 629 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 630 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 631 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 632 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 633 | return QualType(); |
| 634 | } |
| 635 | |
| 636 | // Build the elaborated-type-specifier type. |
| 637 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 638 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 641 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 642 | /// identifier that names the next step in the nested-name-specifier. |
| 643 | /// |
| 644 | /// By default, performs semantic analysis when building the new |
| 645 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 646 | /// different behavior. |
| 647 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 648 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 649 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 650 | QualType ObjectType, |
| 651 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 652 | |
| 653 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 654 | /// namespace named in the next step in the nested-name-specifier. |
| 655 | /// |
| 656 | /// By default, performs semantic analysis when building the new |
| 657 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 658 | /// different behavior. |
| 659 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 660 | SourceRange Range, |
| 661 | NamespaceDecl *NS); |
| 662 | |
| 663 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 664 | /// type named in the next step in the nested-name-specifier. |
| 665 | /// |
| 666 | /// By default, performs semantic analysis when building the new |
| 667 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 668 | /// different behavior. |
| 669 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 670 | SourceRange Range, |
| 671 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 672 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 673 | |
| 674 | /// \brief Build a new template name given a nested name specifier, a flag |
| 675 | /// indicating whether the "template" keyword was provided, and the template |
| 676 | /// that the template name refers to. |
| 677 | /// |
| 678 | /// By default, builds the new template name directly. Subclasses may override |
| 679 | /// this routine to provide different behavior. |
| 680 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 681 | bool TemplateKW, |
| 682 | TemplateDecl *Template); |
| 683 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 684 | /// \brief Build a new template name given a nested name specifier and the |
| 685 | /// name that is referred to as a template. |
| 686 | /// |
| 687 | /// By default, performs semantic analysis to determine whether the name can |
| 688 | /// be resolved to a specific template, then builds the appropriate kind of |
| 689 | /// template name. Subclasses may override this routine to provide different |
| 690 | /// behavior. |
| 691 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 692 | const IdentifierInfo &II, |
| 693 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 695 | /// \brief Build a new template name given a nested name specifier and the |
| 696 | /// overloaded operator name that is referred to as a template. |
| 697 | /// |
| 698 | /// By default, performs semantic analysis to determine whether the name can |
| 699 | /// be resolved to a specific template, then builds the appropriate kind of |
| 700 | /// template name. Subclasses may override this routine to provide different |
| 701 | /// behavior. |
| 702 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 703 | OverloadedOperatorKind Operator, |
| 704 | QualType ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 705 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 706 | /// \brief Build a new compound statement. |
| 707 | /// |
| 708 | /// By default, performs semantic analysis to build the new statement. |
| 709 | /// Subclasses may override this routine to provide different behavior. |
| 710 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 711 | MultiStmtArg Statements, |
| 712 | SourceLocation RBraceLoc, |
| 713 | bool IsStmtExpr) { |
| 714 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 715 | IsStmtExpr); |
| 716 | } |
| 717 | |
| 718 | /// \brief Build a new case statement. |
| 719 | /// |
| 720 | /// By default, performs semantic analysis to build the new statement. |
| 721 | /// Subclasses may override this routine to provide different behavior. |
| 722 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 723 | ExprArg LHS, |
| 724 | SourceLocation EllipsisLoc, |
| 725 | ExprArg RHS, |
| 726 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 728 | ColonLoc); |
| 729 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | /// \brief Attach the body to a new case statement. |
| 732 | /// |
| 733 | /// By default, performs semantic analysis to build the new statement. |
| 734 | /// Subclasses may override this routine to provide different behavior. |
| 735 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 736 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 737 | return move(S); |
| 738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | /// \brief Build a new default statement. |
| 741 | /// |
| 742 | /// By default, performs semantic analysis to build the new statement. |
| 743 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 744 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 745 | SourceLocation ColonLoc, |
| 746 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 748 | /*CurScope=*/0); |
| 749 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 751 | /// \brief Build a new label statement. |
| 752 | /// |
| 753 | /// By default, performs semantic analysis to build the new statement. |
| 754 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 756 | IdentifierInfo *Id, |
| 757 | SourceLocation ColonLoc, |
| 758 | StmtArg SubStmt) { |
| 759 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 762 | /// \brief Build a new "if" statement. |
| 763 | /// |
| 764 | /// By default, performs semantic analysis to build the new statement. |
| 765 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 766 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 767 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 768 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 769 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 770 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 772 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 773 | /// \brief Start building a new switch statement. |
| 774 | /// |
| 775 | /// By default, performs semantic analysis to build the new statement. |
| 776 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 777 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 778 | Sema::ExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 779 | VarDecl *CondVar) { |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 780 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 781 | DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 784 | /// \brief Attach the body to the switch statement. |
| 785 | /// |
| 786 | /// By default, performs semantic analysis to build the new statement. |
| 787 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 789 | StmtArg Switch, StmtArg Body) { |
| 790 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 791 | move(Body)); |
| 792 | } |
| 793 | |
| 794 | /// \brief Build a new while statement. |
| 795 | /// |
| 796 | /// By default, performs semantic analysis to build the new statement. |
| 797 | /// Subclasses may override this routine to provide different behavior. |
| 798 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 799 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 800 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 802 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 803 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 804 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 805 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 806 | /// \brief Build a new do-while statement. |
| 807 | /// |
| 808 | /// By default, performs semantic analysis to build the new statement. |
| 809 | /// Subclasses may override this routine to provide different behavior. |
| 810 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 811 | SourceLocation WhileLoc, |
| 812 | SourceLocation LParenLoc, |
| 813 | ExprArg Cond, |
| 814 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 816 | move(Cond), RParenLoc); |
| 817 | } |
| 818 | |
| 819 | /// \brief Build a new for statement. |
| 820 | /// |
| 821 | /// By default, performs semantic analysis to build the new statement. |
| 822 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 823 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 824 | SourceLocation LParenLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 825 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 826 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 828 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 829 | DeclPtrTy::make(CondVar), |
| 830 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 833 | /// \brief Build a new goto statement. |
| 834 | /// |
| 835 | /// By default, performs semantic analysis to build the new statement. |
| 836 | /// Subclasses may override this routine to provide different behavior. |
| 837 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 838 | SourceLocation LabelLoc, |
| 839 | LabelStmt *Label) { |
| 840 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 841 | } |
| 842 | |
| 843 | /// \brief Build a new indirect goto statement. |
| 844 | /// |
| 845 | /// By default, performs semantic analysis to build the new statement. |
| 846 | /// Subclasses may override this routine to provide different behavior. |
| 847 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 848 | SourceLocation StarLoc, |
| 849 | ExprArg Target) { |
| 850 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 853 | /// \brief Build a new return statement. |
| 854 | /// |
| 855 | /// By default, performs semantic analysis to build the new statement. |
| 856 | /// Subclasses may override this routine to provide different behavior. |
| 857 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 858 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 860 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 861 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 863 | /// \brief Build a new declaration statement. |
| 864 | /// |
| 865 | /// By default, performs semantic analysis to build the new statement. |
| 866 | /// Subclasses may override this routine to provide different behavior. |
| 867 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 868 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 869 | SourceLocation EndLoc) { |
| 870 | return getSema().Owned( |
| 871 | new (getSema().Context) DeclStmt( |
| 872 | DeclGroupRef::Create(getSema().Context, |
| 873 | Decls, NumDecls), |
| 874 | StartLoc, EndLoc)); |
| 875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 877 | /// \brief Build a new inline asm statement. |
| 878 | /// |
| 879 | /// By default, performs semantic analysis to build the new statement. |
| 880 | /// Subclasses may override this routine to provide different behavior. |
| 881 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 882 | bool IsSimple, |
| 883 | bool IsVolatile, |
| 884 | unsigned NumOutputs, |
| 885 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 886 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 887 | MultiExprArg Constraints, |
| 888 | MultiExprArg Exprs, |
| 889 | ExprArg AsmString, |
| 890 | MultiExprArg Clobbers, |
| 891 | SourceLocation RParenLoc, |
| 892 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 893 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 894 | NumInputs, Names, move(Constraints), |
| 895 | move(Exprs), move(AsmString), move(Clobbers), |
| 896 | RParenLoc, MSAsm); |
| 897 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 898 | |
| 899 | /// \brief Build a new Objective-C @try statement. |
| 900 | /// |
| 901 | /// By default, performs semantic analysis to build the new statement. |
| 902 | /// Subclasses may override this routine to provide different behavior. |
| 903 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 904 | StmtArg TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 905 | MultiStmtArg CatchStmts, |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 906 | StmtArg Finally) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 907 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 908 | move(Finally)); |
| 909 | } |
| 910 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 911 | /// \brief Rebuild an Objective-C exception declaration. |
| 912 | /// |
| 913 | /// By default, performs semantic analysis to build the new declaration. |
| 914 | /// Subclasses may override this routine to provide different behavior. |
| 915 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 916 | TypeSourceInfo *TInfo, QualType T) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 917 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 918 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 919 | ExceptionDecl->getLocation()); |
| 920 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 921 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 922 | /// \brief Build a new Objective-C @catch statement. |
| 923 | /// |
| 924 | /// By default, performs semantic analysis to build the new statement. |
| 925 | /// Subclasses may override this routine to provide different behavior. |
| 926 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 927 | SourceLocation RParenLoc, |
| 928 | VarDecl *Var, |
| 929 | StmtArg Body) { |
| 930 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 931 | Sema::DeclPtrTy::make(Var), |
| 932 | move(Body)); |
| 933 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 934 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 935 | /// \brief Build a new Objective-C @finally statement. |
| 936 | /// |
| 937 | /// By default, performs semantic analysis to build the new statement. |
| 938 | /// Subclasses may override this routine to provide different behavior. |
| 939 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 940 | StmtArg Body) { |
| 941 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 942 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 944 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 945 | /// |
| 946 | /// By default, performs semantic analysis to build the new statement. |
| 947 | /// Subclasses may override this routine to provide different behavior. |
| 948 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 949 | ExprArg Operand) { |
| 950 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 951 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 952 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 953 | /// \brief Build a new Objective-C @synchronized statement. |
| 954 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 955 | /// By default, performs semantic analysis to build the new statement. |
| 956 | /// Subclasses may override this routine to provide different behavior. |
| 957 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 958 | ExprArg Object, |
| 959 | StmtArg Body) { |
| 960 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 961 | move(Body)); |
| 962 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 963 | |
| 964 | /// \brief Build a new Objective-C fast enumeration statement. |
| 965 | /// |
| 966 | /// By default, performs semantic analysis to build the new statement. |
| 967 | /// Subclasses may override this routine to provide different behavior. |
| 968 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 969 | SourceLocation LParenLoc, |
| 970 | StmtArg Element, |
| 971 | ExprArg Collection, |
| 972 | SourceLocation RParenLoc, |
| 973 | StmtArg Body) { |
| 974 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 975 | move(Element), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 976 | move(Collection), |
| 977 | RParenLoc, |
| 978 | move(Body)); |
| 979 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 980 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 981 | /// \brief Build a new C++ exception declaration. |
| 982 | /// |
| 983 | /// By default, performs semantic analysis to build the new decaration. |
| 984 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 986 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 987 | IdentifierInfo *Name, |
| 988 | SourceLocation Loc, |
| 989 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 991 | TypeRange); |
| 992 | } |
| 993 | |
| 994 | /// \brief Build a new C++ catch statement. |
| 995 | /// |
| 996 | /// By default, performs semantic analysis to build the new statement. |
| 997 | /// Subclasses may override this routine to provide different behavior. |
| 998 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 999 | VarDecl *ExceptionDecl, |
| 1000 | StmtArg Handler) { |
| 1001 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1003 | Handler.takeAs<Stmt>())); |
| 1004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1006 | /// \brief Build a new C++ try statement. |
| 1007 | /// |
| 1008 | /// By default, performs semantic analysis to build the new statement. |
| 1009 | /// Subclasses may override this routine to provide different behavior. |
| 1010 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1011 | StmtArg TryBlock, |
| 1012 | MultiStmtArg Handlers) { |
| 1013 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new expression that references a declaration. |
| 1017 | /// |
| 1018 | /// By default, performs semantic analysis to build the new expression. |
| 1019 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1020 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1021 | LookupResult &R, |
| 1022 | bool RequiresADL) { |
| 1023 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1024 | } |
| 1025 | |
| 1026 | |
| 1027 | /// \brief Build a new expression that references a declaration. |
| 1028 | /// |
| 1029 | /// By default, performs semantic analysis to build the new expression. |
| 1030 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1031 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1032 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1033 | ValueDecl *VD, SourceLocation Loc, |
| 1034 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1035 | CXXScopeSpec SS; |
| 1036 | SS.setScopeRep(Qualifier); |
| 1037 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1038 | |
| 1039 | // FIXME: loses template args. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1040 | |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1041 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1044 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | /// By default, performs semantic analysis to build the new expression. |
| 1047 | /// Subclasses may override this routine to provide different behavior. |
| 1048 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1049 | SourceLocation RParen) { |
| 1050 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1051 | } |
| 1052 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1053 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1054 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1055 | /// By default, performs semantic analysis to build the new expression. |
| 1056 | /// Subclasses may override this routine to provide different behavior. |
| 1057 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1058 | SourceLocation OperatorLoc, |
| 1059 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1060 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1061 | SourceRange QualifierRange, |
| 1062 | TypeSourceInfo *ScopeType, |
| 1063 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1064 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1065 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1067 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1069 | /// By default, performs semantic analysis to build the new expression. |
| 1070 | /// Subclasses may override this routine to provide different behavior. |
| 1071 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1072 | UnaryOperator::Opcode Opc, |
| 1073 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1074 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1075 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1076 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1077 | /// \brief Build a new builtin offsetof expression. |
| 1078 | /// |
| 1079 | /// By default, performs semantic analysis to build the new expression. |
| 1080 | /// Subclasses may override this routine to provide different behavior. |
| 1081 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1082 | TypeSourceInfo *Type, |
| 1083 | Action::OffsetOfComponent *Components, |
| 1084 | unsigned NumComponents, |
| 1085 | SourceLocation RParenLoc) { |
| 1086 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1087 | NumComponents, RParenLoc); |
| 1088 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1089 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1090 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1091 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1092 | /// By default, performs semantic analysis to build the new expression. |
| 1093 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1094 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1095 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1096 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1097 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | /// By default, performs semantic analysis to build the new expression. |
| 1104 | /// Subclasses may override this routine to provide different behavior. |
| 1105 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1106 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1109 | OpLoc, isSizeOf, R); |
| 1110 | if (Result.isInvalid()) |
| 1111 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1113 | SubExpr.release(); |
| 1114 | return move(Result); |
| 1115 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1119 | /// By default, performs semantic analysis to build the new expression. |
| 1120 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | SourceLocation LBracketLoc, |
| 1123 | ExprArg RHS, |
| 1124 | SourceLocation RBracketLoc) { |
| 1125 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | RBracketLoc); |
| 1128 | } |
| 1129 | |
| 1130 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1132 | /// By default, performs semantic analysis to build the new expression. |
| 1133 | /// Subclasses may override this routine to provide different behavior. |
| 1134 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1135 | MultiExprArg Args, |
| 1136 | SourceLocation *CommaLocs, |
| 1137 | SourceLocation RParenLoc) { |
| 1138 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1139 | move(Args), CommaLocs, RParenLoc); |
| 1140 | } |
| 1141 | |
| 1142 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1144 | /// By default, performs semantic analysis to build the new expression. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
| 1146 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1148 | NestedNameSpecifier *Qualifier, |
| 1149 | SourceRange QualifierRange, |
| 1150 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1151 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1152 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1153 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1154 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1155 | if (!Member->getDeclName()) { |
| 1156 | // We have a reference to an unnamed field. |
| 1157 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1159 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1160 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1161 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1162 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1163 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1165 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1166 | Member, MemberLoc, |
| 1167 | cast<FieldDecl>(Member)->getType()); |
| 1168 | return getSema().Owned(ME); |
| 1169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1171 | CXXScopeSpec SS; |
| 1172 | if (Qualifier) { |
| 1173 | SS.setRange(QualifierRange); |
| 1174 | SS.setScopeRep(Qualifier); |
| 1175 | } |
| 1176 | |
Douglas Gregor | 83c9abc | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1177 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 1178 | getSema().DefaultFunctionArrayConversion(BaseExpr); |
| 1179 | QualType BaseType = BaseExpr->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1180 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1181 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1182 | // cases; we should avoid this when possible. |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1183 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1184 | Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1185 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1186 | R.resolveKind(); |
| 1187 | |
Douglas Gregor | 83c9abc | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1188 | return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr), |
| 1189 | BaseType, OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1190 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1191 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1192 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1195 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | /// By default, performs semantic analysis to build the new expression. |
| 1197 | /// Subclasses may override this routine to provide different behavior. |
| 1198 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1199 | BinaryOperator::Opcode Opc, |
| 1200 | ExprArg LHS, ExprArg RHS) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1201 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1202 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1207 | /// By default, performs semantic analysis to build the new expression. |
| 1208 | /// Subclasses may override this routine to provide different behavior. |
| 1209 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1210 | SourceLocation QuestionLoc, |
| 1211 | ExprArg LHS, |
| 1212 | SourceLocation ColonLoc, |
| 1213 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | move(LHS), move(RHS)); |
| 1216 | } |
| 1217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | /// By default, performs semantic analysis to build the new expression. |
| 1221 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1222 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1223 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | SourceLocation RParenLoc, |
| 1225 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1226 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1227 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | /// By default, performs semantic analysis to build the new expression. |
| 1233 | /// Subclasses may override this routine to provide different behavior. |
| 1234 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1235 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | SourceLocation RParenLoc, |
| 1237 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1238 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1239 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | /// By default, performs semantic analysis to build the new expression. |
| 1245 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1247 | SourceLocation OpLoc, |
| 1248 | SourceLocation AccessorLoc, |
| 1249 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1250 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1251 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1252 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1253 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1254 | OpLoc, /*IsArrow*/ false, |
| 1255 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1256 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1257 | AccessorLoc, |
| 1258 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1259 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | /// By default, performs semantic analysis to build the new expression. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| 1265 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1266 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1267 | SourceLocation RBraceLoc, |
| 1268 | QualType ResultTy) { |
| 1269 | OwningExprResult Result |
| 1270 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1271 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1272 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1274 | // Patch in the result type we were given, which may have been computed |
| 1275 | // when the initial InitListExpr was built. |
| 1276 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1277 | ILE->setType(ResultTy); |
| 1278 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1280 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1281 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1283 | /// By default, performs semantic analysis to build the new expression. |
| 1284 | /// Subclasses may override this routine to provide different behavior. |
| 1285 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1286 | MultiExprArg ArrayExprs, |
| 1287 | SourceLocation EqualOrColonLoc, |
| 1288 | bool GNUSyntax, |
| 1289 | ExprArg Init) { |
| 1290 | OwningExprResult Result |
| 1291 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1292 | move(Init)); |
| 1293 | if (Result.isInvalid()) |
| 1294 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | ArrayExprs.release(); |
| 1297 | return move(Result); |
| 1298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | /// \brief Build a new value-initialized expression. |
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 | /// By default, builds the implicit value initialization without performing |
| 1303 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1304 | /// different behavior. |
| 1305 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1306 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | /// By default, performs semantic analysis to build the new expression. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1314 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | RParenLoc); |
| 1317 | } |
| 1318 | |
| 1319 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | /// By default, performs semantic analysis to build the new expression. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
| 1323 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1324 | MultiExprArg SubExprs, |
| 1325 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1326 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1327 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1329 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | /// |
| 1332 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1333 | /// rather than attempting to map the label statement itself. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1336 | SourceLocation LabelLoc, |
| 1337 | LabelStmt *Label) { |
| 1338 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1339 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1341 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | /// By default, performs semantic analysis to build the new expression. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
| 1345 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1346 | StmtArg SubStmt, |
| 1347 | SourceLocation RParenLoc) { |
| 1348 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1351 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1352 | /// |
| 1353 | /// By default, performs semantic analysis to build the new expression. |
| 1354 | /// Subclasses may override this routine to provide different behavior. |
| 1355 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1356 | QualType T1, QualType T2, |
| 1357 | SourceLocation RParenLoc) { |
| 1358 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1359 | T1.getAsOpaquePtr(), |
| 1360 | T2.getAsOpaquePtr(), |
| 1361 | RParenLoc); |
| 1362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1363 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1364 | /// \brief Build a new __builtin_choose_expr expression. |
| 1365 | /// |
| 1366 | /// By default, performs semantic analysis to build the new expression. |
| 1367 | /// Subclasses may override this routine to provide different behavior. |
| 1368 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1369 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1370 | SourceLocation RParenLoc) { |
| 1371 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1372 | move(Cond), move(LHS), move(RHS), |
| 1373 | RParenLoc); |
| 1374 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | /// \brief Build a new overloaded operator call expression. |
| 1377 | /// |
| 1378 | /// By default, performs semantic analysis to build the new expression. |
| 1379 | /// The semantic analysis provides the behavior of template instantiation, |
| 1380 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1382 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1383 | /// provide different behavior. |
| 1384 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1385 | SourceLocation OpLoc, |
| 1386 | ExprArg Callee, |
| 1387 | ExprArg First, |
| 1388 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | |
| 1390 | /// \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] | 1391 | /// reinterpret_cast. |
| 1392 | /// |
| 1393 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1395 | /// Subclasses may override this routine to provide different behavior. |
| 1396 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1397 | Stmt::StmtClass Class, |
| 1398 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1399 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | SourceLocation RAngleLoc, |
| 1401 | SourceLocation LParenLoc, |
| 1402 | ExprArg SubExpr, |
| 1403 | SourceLocation RParenLoc) { |
| 1404 | switch (Class) { |
| 1405 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1406 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | move(SubExpr), RParenLoc); |
| 1409 | |
| 1410 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1411 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1416 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | RAngleLoc, LParenLoc, |
| 1418 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1419 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1421 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1422 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | default: |
| 1427 | assert(false && "Invalid C++ named cast"); |
| 1428 | break; |
| 1429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | return getSema().ExprError(); |
| 1432 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | /// \brief Build a new C++ static_cast expression. |
| 1435 | /// |
| 1436 | /// By default, performs semantic analysis to build the new expression. |
| 1437 | /// Subclasses may override this routine to provide different behavior. |
| 1438 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1439 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1440 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1441 | SourceLocation RAngleLoc, |
| 1442 | SourceLocation LParenLoc, |
| 1443 | ExprArg SubExpr, |
| 1444 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1445 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1446 | TInfo, move(SubExpr), |
| 1447 | SourceRange(LAngleLoc, RAngleLoc), |
| 1448 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | /// \brief Build a new C++ dynamic_cast expression. |
| 1452 | /// |
| 1453 | /// By default, performs semantic analysis to build the new expression. |
| 1454 | /// Subclasses may override this routine to provide different behavior. |
| 1455 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1456 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1457 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1458 | SourceLocation RAngleLoc, |
| 1459 | SourceLocation LParenLoc, |
| 1460 | ExprArg SubExpr, |
| 1461 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1462 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1463 | TInfo, move(SubExpr), |
| 1464 | SourceRange(LAngleLoc, RAngleLoc), |
| 1465 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1469 | /// |
| 1470 | /// By default, performs semantic analysis to build the new expression. |
| 1471 | /// Subclasses may override this routine to provide different behavior. |
| 1472 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1473 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1474 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | SourceLocation RAngleLoc, |
| 1476 | SourceLocation LParenLoc, |
| 1477 | ExprArg SubExpr, |
| 1478 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1479 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1480 | TInfo, move(SubExpr), |
| 1481 | SourceRange(LAngleLoc, RAngleLoc), |
| 1482 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /// \brief Build a new C++ const_cast expression. |
| 1486 | /// |
| 1487 | /// By default, performs semantic analysis to build the new expression. |
| 1488 | /// Subclasses may override this routine to provide different behavior. |
| 1489 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1490 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1491 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | SourceLocation RAngleLoc, |
| 1493 | SourceLocation LParenLoc, |
| 1494 | ExprArg SubExpr, |
| 1495 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1496 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1497 | TInfo, move(SubExpr), |
| 1498 | SourceRange(LAngleLoc, RAngleLoc), |
| 1499 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1502 | /// \brief Build a new C++ functional-style cast expression. |
| 1503 | /// |
| 1504 | /// By default, performs semantic analysis to build the new expression. |
| 1505 | /// Subclasses may override this routine to provide different behavior. |
| 1506 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1507 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1508 | SourceLocation LParenLoc, |
| 1509 | ExprArg SubExpr, |
| 1510 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1511 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1513 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1515 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1516 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | RParenLoc); |
| 1518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1520 | /// \brief Build a new C++ typeid(type) expression. |
| 1521 | /// |
| 1522 | /// By default, performs semantic analysis to build the new expression. |
| 1523 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1524 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1525 | SourceLocation TypeidLoc, |
| 1526 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1528 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1529 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1531 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1532 | /// \brief Build a new C++ typeid(expr) expression. |
| 1533 | /// |
| 1534 | /// By default, performs semantic analysis to build the new expression. |
| 1535 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1536 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1537 | SourceLocation TypeidLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1538 | ExprArg Operand, |
| 1539 | SourceLocation RParenLoc) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1540 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1541 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | /// \brief Build a new C++ "this" expression. |
| 1545 | /// |
| 1546 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1547 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1549 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1550 | QualType ThisType, |
| 1551 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1553 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1554 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | /// \brief Build a new C++ throw expression. |
| 1558 | /// |
| 1559 | /// By default, performs semantic analysis to build the new expression. |
| 1560 | /// Subclasses may override this routine to provide different behavior. |
| 1561 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1562 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1563 | } |
| 1564 | |
| 1565 | /// \brief Build a new C++ default-argument expression. |
| 1566 | /// |
| 1567 | /// By default, builds a new default-argument expression, which does not |
| 1568 | /// require any semantic analysis. Subclasses may override this routine to |
| 1569 | /// provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1570 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1571 | ParmVarDecl *Param) { |
| 1572 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1573 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | /// \brief Build a new C++ zero-initialization expression. |
| 1577 | /// |
| 1578 | /// By default, performs semantic analysis to build the new expression. |
| 1579 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 016a4a9 | 2010-07-07 22:43:56 +0000 | [diff] [blame^] | 1580 | OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1581 | SourceLocation LParenLoc, |
| 1582 | QualType T, |
| 1583 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1584 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1585 | T.getAsOpaquePtr(), LParenLoc, |
| 1586 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | 0, RParenLoc); |
| 1588 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1590 | /// \brief Build a new C++ "new" expression. |
| 1591 | /// |
| 1592 | /// By default, performs semantic analysis to build the new expression. |
| 1593 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1594 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | bool UseGlobal, |
| 1596 | SourceLocation PlacementLParen, |
| 1597 | MultiExprArg PlacementArgs, |
| 1598 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1599 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | QualType AllocType, |
| 1601 | SourceLocation TypeLoc, |
| 1602 | SourceRange TypeRange, |
| 1603 | ExprArg ArraySize, |
| 1604 | SourceLocation ConstructorLParen, |
| 1605 | MultiExprArg ConstructorArgs, |
| 1606 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | PlacementLParen, |
| 1609 | move(PlacementArgs), |
| 1610 | PlacementRParen, |
| 1611 | ParenTypeId, |
| 1612 | AllocType, |
| 1613 | TypeLoc, |
| 1614 | TypeRange, |
| 1615 | move(ArraySize), |
| 1616 | ConstructorLParen, |
| 1617 | move(ConstructorArgs), |
| 1618 | ConstructorRParen); |
| 1619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1621 | /// \brief Build a new C++ "delete" expression. |
| 1622 | /// |
| 1623 | /// By default, performs semantic analysis to build the new expression. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
| 1625 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1626 | bool IsGlobalDelete, |
| 1627 | bool IsArrayForm, |
| 1628 | ExprArg Operand) { |
| 1629 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1630 | move(Operand)); |
| 1631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1633 | /// \brief Build a new unary type trait expression. |
| 1634 | /// |
| 1635 | /// By default, performs semantic analysis to build the new expression. |
| 1636 | /// Subclasses may override this routine to provide different behavior. |
| 1637 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1638 | SourceLocation StartLoc, |
| 1639 | SourceLocation LParenLoc, |
| 1640 | QualType T, |
| 1641 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1642 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | T.getAsOpaquePtr(), RParenLoc); |
| 1644 | } |
| 1645 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | /// expression. |
| 1648 | /// |
| 1649 | /// By default, performs semantic analysis to build the new expression. |
| 1650 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1651 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | SourceRange QualifierRange, |
| 1653 | DeclarationName Name, |
| 1654 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1655 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | CXXScopeSpec SS; |
| 1657 | SS.setRange(QualifierRange); |
| 1658 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1659 | |
| 1660 | if (TemplateArgs) |
| 1661 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1662 | *TemplateArgs); |
| 1663 | |
| 1664 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /// \brief Build a new template-id expression. |
| 1668 | /// |
| 1669 | /// By default, performs semantic analysis to build the new expression. |
| 1670 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1671 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1672 | LookupResult &R, |
| 1673 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1674 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1675 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | /// \brief Build a new object-construction expression. |
| 1679 | /// |
| 1680 | /// By default, performs semantic analysis to build the new expression. |
| 1681 | /// Subclasses may override this routine to provide different behavior. |
| 1682 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1683 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1684 | CXXConstructorDecl *Constructor, |
| 1685 | bool IsElidable, |
| 1686 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1687 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1688 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1689 | ConvertedArgs)) |
| 1690 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1691 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1692 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1693 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | /// \brief Build a new object-construction expression. |
| 1697 | /// |
| 1698 | /// By default, performs semantic analysis to build the new expression. |
| 1699 | /// Subclasses may override this routine to provide different behavior. |
| 1700 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1701 | QualType T, |
| 1702 | SourceLocation LParenLoc, |
| 1703 | MultiExprArg Args, |
| 1704 | SourceLocation *Commas, |
| 1705 | SourceLocation RParenLoc) { |
| 1706 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1707 | T.getAsOpaquePtr(), |
| 1708 | LParenLoc, |
| 1709 | move(Args), |
| 1710 | Commas, |
| 1711 | RParenLoc); |
| 1712 | } |
| 1713 | |
| 1714 | /// \brief Build a new object-construction expression. |
| 1715 | /// |
| 1716 | /// By default, performs semantic analysis to build the new expression. |
| 1717 | /// Subclasses may override this routine to provide different behavior. |
| 1718 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1719 | QualType T, |
| 1720 | SourceLocation LParenLoc, |
| 1721 | MultiExprArg Args, |
| 1722 | SourceLocation *Commas, |
| 1723 | SourceLocation RParenLoc) { |
| 1724 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1725 | /*FIXME*/LParenLoc), |
| 1726 | T.getAsOpaquePtr(), |
| 1727 | LParenLoc, |
| 1728 | move(Args), |
| 1729 | Commas, |
| 1730 | RParenLoc); |
| 1731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1732 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1733 | /// \brief Build a new member reference expression. |
| 1734 | /// |
| 1735 | /// By default, performs semantic analysis to build the new expression. |
| 1736 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1737 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1738 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1739 | bool IsArrow, |
| 1740 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1741 | NestedNameSpecifier *Qualifier, |
| 1742 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1743 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1744 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1745 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1746 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1747 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1748 | SS.setRange(QualifierRange); |
| 1749 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1751 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1752 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1753 | SS, FirstQualifierInScope, |
| 1754 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1757 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1758 | /// |
| 1759 | /// By default, performs semantic analysis to build the new expression. |
| 1760 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1761 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1762 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1763 | SourceLocation OperatorLoc, |
| 1764 | bool IsArrow, |
| 1765 | NestedNameSpecifier *Qualifier, |
| 1766 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1767 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1768 | LookupResult &R, |
| 1769 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1770 | CXXScopeSpec SS; |
| 1771 | SS.setRange(QualifierRange); |
| 1772 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1774 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1775 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1776 | SS, FirstQualifierInScope, |
| 1777 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1778 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1779 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1780 | /// \brief Build a new Objective-C @encode expression. |
| 1781 | /// |
| 1782 | /// By default, performs semantic analysis to build the new expression. |
| 1783 | /// Subclasses may override this routine to provide different behavior. |
| 1784 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1785 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1786 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1787 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1788 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1791 | /// \brief Build a new Objective-C class message. |
| 1792 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1793 | Selector Sel, |
| 1794 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1795 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1796 | MultiExprArg Args, |
| 1797 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1798 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1799 | ReceiverTypeInfo->getType(), |
| 1800 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1801 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1802 | move(Args)); |
| 1803 | } |
| 1804 | |
| 1805 | /// \brief Build a new Objective-C instance message. |
| 1806 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1807 | Selector Sel, |
| 1808 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1809 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1810 | MultiExprArg Args, |
| 1811 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1812 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1813 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1814 | ReceiverType, |
| 1815 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1816 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1817 | move(Args)); |
| 1818 | } |
| 1819 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1820 | /// \brief Build a new Objective-C ivar reference expression. |
| 1821 | /// |
| 1822 | /// By default, performs semantic analysis to build the new expression. |
| 1823 | /// Subclasses may override this routine to provide different behavior. |
| 1824 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1825 | SourceLocation IvarLoc, |
| 1826 | bool IsArrow, bool IsFreeIvar) { |
| 1827 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1828 | CXXScopeSpec SS; |
| 1829 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1830 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1831 | Sema::LookupMemberName); |
| 1832 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1833 | /*FIME:*/IvarLoc, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1834 | SS, DeclPtrTy(), |
| 1835 | false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1836 | if (Result.isInvalid()) |
| 1837 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1838 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1839 | if (Result.get()) |
| 1840 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1841 | |
| 1842 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1843 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1844 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1845 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1846 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1847 | /*TemplateArgs=*/0); |
| 1848 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1849 | |
| 1850 | /// \brief Build a new Objective-C property reference expression. |
| 1851 | /// |
| 1852 | /// By default, performs semantic analysis to build the new expression. |
| 1853 | /// Subclasses may override this routine to provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1854 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1855 | ObjCPropertyDecl *Property, |
| 1856 | SourceLocation PropertyLoc) { |
| 1857 | CXXScopeSpec SS; |
| 1858 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1859 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1860 | Sema::LookupMemberName); |
| 1861 | bool IsArrow = false; |
| 1862 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1863 | /*FIME:*/PropertyLoc, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1864 | SS, DeclPtrTy(), |
| 1865 | false); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1866 | if (Result.isInvalid()) |
| 1867 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1869 | if (Result.get()) |
| 1870 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1871 | |
| 1872 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1873 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1874 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1875 | SS, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1876 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1877 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1878 | /*TemplateArgs=*/0); |
| 1879 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1880 | |
| 1881 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1882 | /// expression. |
| 1883 | /// |
| 1884 | /// By default, performs semantic analysis to build the new expression. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1885 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1886 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1887 | ObjCMethodDecl *Getter, |
| 1888 | QualType T, |
| 1889 | ObjCMethodDecl *Setter, |
| 1890 | SourceLocation NameLoc, |
| 1891 | ExprArg Base) { |
| 1892 | // Since these expressions can only be value-dependent, we do not need to |
| 1893 | // perform semantic analysis again. |
| 1894 | return getSema().Owned( |
| 1895 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1896 | Setter, |
| 1897 | NameLoc, |
| 1898 | Base.takeAs<Expr>())); |
| 1899 | } |
| 1900 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1901 | /// \brief Build a new Objective-C "isa" expression. |
| 1902 | /// |
| 1903 | /// By default, performs semantic analysis to build the new expression. |
| 1904 | /// Subclasses may override this routine to provide different behavior. |
| 1905 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1906 | bool IsArrow) { |
| 1907 | CXXScopeSpec SS; |
| 1908 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1909 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1910 | Sema::LookupMemberName); |
| 1911 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1912 | /*FIME:*/IsaLoc, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1913 | SS, DeclPtrTy(), |
| 1914 | false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1915 | if (Result.isInvalid()) |
| 1916 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1917 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1918 | if (Result.get()) |
| 1919 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1920 | |
| 1921 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1922 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1923 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1924 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1925 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1926 | /*TemplateArgs=*/0); |
| 1927 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1928 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1929 | /// \brief Build a new shuffle vector expression. |
| 1930 | /// |
| 1931 | /// By default, performs semantic analysis to build the new expression. |
| 1932 | /// Subclasses may override this routine to provide different behavior. |
| 1933 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1934 | MultiExprArg SubExprs, |
| 1935 | SourceLocation RParenLoc) { |
| 1936 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1937 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1938 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1939 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1940 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1941 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1942 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | // Build a reference to the __builtin_shufflevector builtin |
| 1944 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1945 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1946 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1947 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1948 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
| 1950 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1951 | unsigned NumSubExprs = SubExprs.size(); |
| 1952 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1953 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1954 | Subs, NumSubExprs, |
| 1955 | Builtin->getResultType(), |
| 1956 | RParenLoc); |
| 1957 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1959 | // Type-check the __builtin_shufflevector expression. |
| 1960 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1961 | if (Result.isInvalid()) |
| 1962 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1963 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1964 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1966 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1967 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1968 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1969 | template<typename Derived> |
| 1970 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1971 | if (!S) |
| 1972 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1973 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1974 | switch (S->getStmtClass()) { |
| 1975 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1976 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1977 | // Transform individual statement nodes |
| 1978 | #define STMT(Node, Parent) \ |
| 1979 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1980 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1981 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1982 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1983 | // Transform expressions by calling TransformExpr. |
| 1984 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 1985 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1986 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1987 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1988 | { |
| 1989 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1990 | if (E.isInvalid()) |
| 1991 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1993 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1997 | return SemaRef.Owned(S->Retain()); |
| 1998 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | |
| 2000 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2001 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2002 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2003 | if (!E) |
| 2004 | return SemaRef.Owned(E); |
| 2005 | |
| 2006 | switch (E->getStmtClass()) { |
| 2007 | case Stmt::NoStmtClass: break; |
| 2008 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2009 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2010 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2011 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2012 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2015 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2019 | NestedNameSpecifier * |
| 2020 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2021 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2022 | QualType ObjectType, |
| 2023 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2024 | if (!NNS) |
| 2025 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2027 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2028 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2029 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2030 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2031 | ObjectType, |
| 2032 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2033 | if (!Prefix) |
| 2034 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | |
| 2036 | // 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] | 2037 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2038 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2039 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2041 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2042 | switch (NNS->getKind()) { |
| 2043 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2045 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2046 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2047 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2048 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2049 | |
| 2050 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2051 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2052 | ObjectType, |
| 2053 | FirstQualifierInScope); |
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 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2056 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2057 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2058 | getDerived().TransformDecl(Range.getBegin(), |
| 2059 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2060 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2061 | Prefix == NNS->getPrefix() && |
| 2062 | NS == NNS->getAsNamespace()) |
| 2063 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2064 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2065 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2066 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2068 | case NestedNameSpecifier::Global: |
| 2069 | // There is no meaningful transformation that one could perform on the |
| 2070 | // global scope. |
| 2071 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2072 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2073 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2074 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2075 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2076 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2077 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2078 | if (T.isNull()) |
| 2079 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2080 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2081 | if (!getDerived().AlwaysRebuild() && |
| 2082 | Prefix == NNS->getPrefix() && |
| 2083 | T == QualType(NNS->getAsType(), 0)) |
| 2084 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2085 | |
| 2086 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2087 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2088 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2089 | } |
| 2090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2091 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2092 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2093 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2097 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2098 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2099 | SourceLocation Loc, |
| 2100 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2101 | if (!Name) |
| 2102 | return Name; |
| 2103 | |
| 2104 | switch (Name.getNameKind()) { |
| 2105 | case DeclarationName::Identifier: |
| 2106 | case DeclarationName::ObjCZeroArgSelector: |
| 2107 | case DeclarationName::ObjCOneArgSelector: |
| 2108 | case DeclarationName::ObjCMultiArgSelector: |
| 2109 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2110 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2111 | case DeclarationName::CXXUsingDirective: |
| 2112 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2113 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2114 | case DeclarationName::CXXConstructorName: |
| 2115 | case DeclarationName::CXXDestructorName: |
| 2116 | case DeclarationName::CXXConversionFunctionName: { |
| 2117 | TemporaryBase Rebase(*this, Loc, Name); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2118 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2119 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2120 | if (T.isNull()) |
| 2121 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2122 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2123 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2124 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2125 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2129 | return DeclarationName(); |
| 2130 | } |
| 2131 | |
| 2132 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2133 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2134 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2135 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2136 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2137 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2138 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2139 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2140 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2141 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2142 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2143 | if (!NNS) |
| 2144 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2146 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2148 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2149 | if (!TransTemplate) |
| 2150 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2151 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2152 | if (!getDerived().AlwaysRebuild() && |
| 2153 | NNS == QTN->getQualifier() && |
| 2154 | TransTemplate == Template) |
| 2155 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2156 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2157 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2158 | TransTemplate); |
| 2159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2161 | // These should be getting filtered out before they make it into the AST. |
| 2162 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2163 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2164 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2165 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2167 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2168 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2169 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2170 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2171 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2172 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2173 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2174 | NNS == DTN->getQualifier() && |
| 2175 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2176 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2177 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2178 | if (DTN->isIdentifier()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2179 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2180 | ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2181 | |
| 2182 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2183 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2184 | } |
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 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2187 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2188 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2189 | if (!TransTemplate) |
| 2190 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2192 | if (!getDerived().AlwaysRebuild() && |
| 2193 | TransTemplate == Template) |
| 2194 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2195 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2196 | return TemplateName(TransTemplate); |
| 2197 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2199 | // These should be getting filtered out before they reach the AST. |
| 2200 | assert(false && "overloaded function decl survived to here"); |
| 2201 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2205 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2206 | const TemplateArgument &Arg, |
| 2207 | TemplateArgumentLoc &Output) { |
| 2208 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2209 | switch (Arg.getKind()) { |
| 2210 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2211 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2212 | break; |
| 2213 | |
| 2214 | case TemplateArgument::Type: |
| 2215 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2216 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2217 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2218 | break; |
| 2219 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2220 | case TemplateArgument::Template: |
| 2221 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2222 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2223 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2224 | case TemplateArgument::Expression: |
| 2225 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2226 | break; |
| 2227 | |
| 2228 | case TemplateArgument::Declaration: |
| 2229 | case TemplateArgument::Integral: |
| 2230 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2231 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | template<typename Derived> |
| 2237 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2238 | const TemplateArgumentLoc &Input, |
| 2239 | TemplateArgumentLoc &Output) { |
| 2240 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2241 | switch (Arg.getKind()) { |
| 2242 | case TemplateArgument::Null: |
| 2243 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2244 | Output = Input; |
| 2245 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2247 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2248 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2249 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2250 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2251 | |
| 2252 | DI = getDerived().TransformType(DI); |
| 2253 | if (!DI) return true; |
| 2254 | |
| 2255 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2256 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2257 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2258 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2259 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2260 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2261 | DeclarationName Name; |
| 2262 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2263 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2264 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2265 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2266 | if (!D) return true; |
| 2267 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2268 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2269 | if (SourceExpr) { |
| 2270 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2271 | Action::Unevaluated); |
| 2272 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2273 | if (E.isInvalid()) |
| 2274 | SourceExpr = NULL; |
| 2275 | else { |
| 2276 | SourceExpr = E.takeAs<Expr>(); |
| 2277 | SourceExpr->Retain(); |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2282 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2285 | case TemplateArgument::Template: { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2286 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2287 | TemplateName Template |
| 2288 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2289 | if (Template.isNull()) |
| 2290 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2291 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2292 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2293 | Input.getTemplateQualifierRange(), |
| 2294 | Input.getTemplateNameLoc()); |
| 2295 | return false; |
| 2296 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2297 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2298 | case TemplateArgument::Expression: { |
| 2299 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2300 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2301 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2302 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2303 | Expr *InputExpr = Input.getSourceExpression(); |
| 2304 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2305 | |
| 2306 | Sema::OwningExprResult E |
| 2307 | = getDerived().TransformExpr(InputExpr); |
| 2308 | if (E.isInvalid()) return true; |
| 2309 | |
| 2310 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2311 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2312 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2313 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2315 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2316 | case TemplateArgument::Pack: { |
| 2317 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2318 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2319 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2320 | AEnd = Arg.pack_end(); |
| 2321 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2322 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2323 | // FIXME: preserve source information here when we start |
| 2324 | // caring about parameter packs. |
| 2325 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2326 | TemplateArgumentLoc InputArg; |
| 2327 | TemplateArgumentLoc OutputArg; |
| 2328 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2329 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2330 | return true; |
| 2331 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2332 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2333 | } |
| 2334 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2335 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2336 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2337 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2338 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2339 | } |
| 2340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2341 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2342 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2343 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2346 | //===----------------------------------------------------------------------===// |
| 2347 | // Type transformation |
| 2348 | //===----------------------------------------------------------------------===// |
| 2349 | |
| 2350 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2351 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2352 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2353 | if (getDerived().AlreadyTransformed(T)) |
| 2354 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2355 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2356 | // Temporary workaround. All of these transformations should |
| 2357 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2358 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2359 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2360 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2361 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2362 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2363 | if (!NewDI) |
| 2364 | return QualType(); |
| 2365 | |
| 2366 | return NewDI->getType(); |
| 2367 | } |
| 2368 | |
| 2369 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2370 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2371 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2372 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2373 | return DI; |
| 2374 | |
| 2375 | TypeLocBuilder TLB; |
| 2376 | |
| 2377 | TypeLoc TL = DI->getTypeLoc(); |
| 2378 | TLB.reserve(TL.getFullDataSize()); |
| 2379 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2380 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2381 | if (Result.isNull()) |
| 2382 | return 0; |
| 2383 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2384 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | template<typename Derived> |
| 2388 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2389 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2390 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2391 | switch (T.getTypeLocClass()) { |
| 2392 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2393 | #define TYPELOC(CLASS, PARENT) \ |
| 2394 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2395 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2396 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2397 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2399 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2400 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2401 | return QualType(); |
| 2402 | } |
| 2403 | |
| 2404 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2405 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2406 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2407 | /// types). This is the right thing for template instantiation, but |
| 2408 | /// probably not for other clients. |
| 2409 | template<typename Derived> |
| 2410 | QualType |
| 2411 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2412 | QualifiedTypeLoc T, |
| 2413 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2414 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2415 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2416 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2417 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | if (Result.isNull()) |
| 2419 | return QualType(); |
| 2420 | |
| 2421 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2422 | // FIXME: this is the right thing for template instantiation, but |
| 2423 | // probably not for other clients. |
| 2424 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2425 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2426 | |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 2427 | if (!Quals.empty()) { |
| 2428 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 2429 | TLB.push<QualifiedTypeLoc>(Result); |
| 2430 | // No location information to preserve. |
| 2431 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2432 | |
| 2433 | return Result; |
| 2434 | } |
| 2435 | |
| 2436 | template <class TyLoc> static inline |
| 2437 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2438 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2439 | NewT.setNameLoc(T.getNameLoc()); |
| 2440 | return T.getType(); |
| 2441 | } |
| 2442 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2443 | template<typename Derived> |
| 2444 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2445 | BuiltinTypeLoc T, |
| 2446 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2447 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2448 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2449 | if (T.needsExtraLocalData()) |
| 2450 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2451 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2452 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2453 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2454 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2455 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2456 | ComplexTypeLoc T, |
| 2457 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2458 | // FIXME: recurse? |
| 2459 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2462 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2464 | PointerTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2465 | QualType ObjectType) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2466 | QualType PointeeType |
| 2467 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2468 | if (PointeeType.isNull()) |
| 2469 | return QualType(); |
| 2470 | |
| 2471 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2472 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2473 | // A dependent pointer type 'T *' has is being transformed such |
| 2474 | // that an Objective-C class type is being replaced for 'T'. The |
| 2475 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2476 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2477 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2478 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2479 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2480 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2481 | return Result; |
| 2482 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2483 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2484 | if (getDerived().AlwaysRebuild() || |
| 2485 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2486 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2487 | if (Result.isNull()) |
| 2488 | return QualType(); |
| 2489 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2490 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2491 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2492 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2493 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2495 | |
| 2496 | template<typename Derived> |
| 2497 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2498 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2499 | BlockPointerTypeLoc TL, |
| 2500 | QualType ObjectType) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2501 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2502 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2503 | if (PointeeType.isNull()) |
| 2504 | return QualType(); |
| 2505 | |
| 2506 | QualType Result = TL.getType(); |
| 2507 | if (getDerived().AlwaysRebuild() || |
| 2508 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2509 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2510 | TL.getSigilLoc()); |
| 2511 | if (Result.isNull()) |
| 2512 | return QualType(); |
| 2513 | } |
| 2514 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2515 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2516 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2517 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2518 | } |
| 2519 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2520 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2521 | /// don't care whether the type itself is an l-value type or an r-value |
| 2522 | /// type; we only care if the type was *written* as an l-value type |
| 2523 | /// or an r-value type. |
| 2524 | template<typename Derived> |
| 2525 | QualType |
| 2526 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2527 | ReferenceTypeLoc TL, |
| 2528 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2529 | const ReferenceType *T = TL.getTypePtr(); |
| 2530 | |
| 2531 | // Note that this works with the pointee-as-written. |
| 2532 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2533 | if (PointeeType.isNull()) |
| 2534 | return QualType(); |
| 2535 | |
| 2536 | QualType Result = TL.getType(); |
| 2537 | if (getDerived().AlwaysRebuild() || |
| 2538 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2539 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2540 | T->isSpelledAsLValue(), |
| 2541 | TL.getSigilLoc()); |
| 2542 | if (Result.isNull()) |
| 2543 | return QualType(); |
| 2544 | } |
| 2545 | |
| 2546 | // r-value references can be rebuilt as l-value references. |
| 2547 | ReferenceTypeLoc NewTL; |
| 2548 | if (isa<LValueReferenceType>(Result)) |
| 2549 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2550 | else |
| 2551 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2552 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2553 | |
| 2554 | return Result; |
| 2555 | } |
| 2556 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | template<typename Derived> |
| 2558 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2559 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2560 | LValueReferenceTypeLoc TL, |
| 2561 | QualType ObjectType) { |
| 2562 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | template<typename Derived> |
| 2566 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2567 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2568 | RValueReferenceTypeLoc TL, |
| 2569 | QualType ObjectType) { |
| 2570 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2571 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2572 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2573 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2575 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2576 | MemberPointerTypeLoc TL, |
| 2577 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2578 | MemberPointerType *T = TL.getTypePtr(); |
| 2579 | |
| 2580 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2581 | if (PointeeType.isNull()) |
| 2582 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2583 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2584 | // TODO: preserve source information for this. |
| 2585 | QualType ClassType |
| 2586 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2587 | if (ClassType.isNull()) |
| 2588 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2589 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2590 | QualType Result = TL.getType(); |
| 2591 | if (getDerived().AlwaysRebuild() || |
| 2592 | PointeeType != T->getPointeeType() || |
| 2593 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2594 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2595 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2596 | if (Result.isNull()) |
| 2597 | return QualType(); |
| 2598 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2599 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2600 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2601 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2602 | |
| 2603 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2606 | template<typename Derived> |
| 2607 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2608 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2609 | ConstantArrayTypeLoc TL, |
| 2610 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2611 | ConstantArrayType *T = TL.getTypePtr(); |
| 2612 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2613 | if (ElementType.isNull()) |
| 2614 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2615 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2616 | QualType Result = TL.getType(); |
| 2617 | if (getDerived().AlwaysRebuild() || |
| 2618 | ElementType != T->getElementType()) { |
| 2619 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2620 | T->getSizeModifier(), |
| 2621 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2622 | T->getIndexTypeCVRQualifiers(), |
| 2623 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2624 | if (Result.isNull()) |
| 2625 | return QualType(); |
| 2626 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2627 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2628 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2629 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2630 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2631 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2632 | Expr *Size = TL.getSizeExpr(); |
| 2633 | if (Size) { |
| 2634 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2635 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2636 | } |
| 2637 | NewTL.setSizeExpr(Size); |
| 2638 | |
| 2639 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2641 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2642 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2643 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2645 | IncompleteArrayTypeLoc TL, |
| 2646 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2647 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2648 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2649 | if (ElementType.isNull()) |
| 2650 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2651 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2652 | QualType Result = TL.getType(); |
| 2653 | if (getDerived().AlwaysRebuild() || |
| 2654 | ElementType != T->getElementType()) { |
| 2655 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2656 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2657 | T->getIndexTypeCVRQualifiers(), |
| 2658 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2659 | if (Result.isNull()) |
| 2660 | return QualType(); |
| 2661 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2662 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2663 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2664 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2665 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2666 | NewTL.setSizeExpr(0); |
| 2667 | |
| 2668 | return Result; |
| 2669 | } |
| 2670 | |
| 2671 | template<typename Derived> |
| 2672 | QualType |
| 2673 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2674 | VariableArrayTypeLoc TL, |
| 2675 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2676 | VariableArrayType *T = TL.getTypePtr(); |
| 2677 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2678 | if (ElementType.isNull()) |
| 2679 | return QualType(); |
| 2680 | |
| 2681 | // Array bounds are not potentially evaluated contexts |
| 2682 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2683 | |
| 2684 | Sema::OwningExprResult SizeResult |
| 2685 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2686 | if (SizeResult.isInvalid()) |
| 2687 | return QualType(); |
| 2688 | |
| 2689 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2690 | |
| 2691 | QualType Result = TL.getType(); |
| 2692 | if (getDerived().AlwaysRebuild() || |
| 2693 | ElementType != T->getElementType() || |
| 2694 | Size != T->getSizeExpr()) { |
| 2695 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2696 | T->getSizeModifier(), |
| 2697 | move(SizeResult), |
| 2698 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2699 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2700 | if (Result.isNull()) |
| 2701 | return QualType(); |
| 2702 | } |
| 2703 | else SizeResult.take(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2704 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2705 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2706 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2707 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2708 | NewTL.setSizeExpr(Size); |
| 2709 | |
| 2710 | return Result; |
| 2711 | } |
| 2712 | |
| 2713 | template<typename Derived> |
| 2714 | QualType |
| 2715 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2716 | DependentSizedArrayTypeLoc TL, |
| 2717 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2718 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2719 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2720 | if (ElementType.isNull()) |
| 2721 | return QualType(); |
| 2722 | |
| 2723 | // Array bounds are not potentially evaluated contexts |
| 2724 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2725 | |
| 2726 | Sema::OwningExprResult SizeResult |
| 2727 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2728 | if (SizeResult.isInvalid()) |
| 2729 | return QualType(); |
| 2730 | |
| 2731 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2732 | |
| 2733 | QualType Result = TL.getType(); |
| 2734 | if (getDerived().AlwaysRebuild() || |
| 2735 | ElementType != T->getElementType() || |
| 2736 | Size != T->getSizeExpr()) { |
| 2737 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2738 | T->getSizeModifier(), |
| 2739 | move(SizeResult), |
| 2740 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2741 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2742 | if (Result.isNull()) |
| 2743 | return QualType(); |
| 2744 | } |
| 2745 | else SizeResult.take(); |
| 2746 | |
| 2747 | // We might have any sort of array type now, but fortunately they |
| 2748 | // all have the same location layout. |
| 2749 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2750 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2751 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2752 | NewTL.setSizeExpr(Size); |
| 2753 | |
| 2754 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2755 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2756 | |
| 2757 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2758 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2759 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2760 | DependentSizedExtVectorTypeLoc TL, |
| 2761 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2762 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2763 | |
| 2764 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2765 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2766 | if (ElementType.isNull()) |
| 2767 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2768 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2769 | // Vector sizes are not potentially evaluated contexts |
| 2770 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2771 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2772 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2773 | if (Size.isInvalid()) |
| 2774 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2775 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | QualType Result = TL.getType(); |
| 2777 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2778 | ElementType != T->getElementType() || |
| 2779 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2781 | move(Size), |
| 2782 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | if (Result.isNull()) |
| 2784 | return QualType(); |
| 2785 | } |
| 2786 | else Size.take(); |
| 2787 | |
| 2788 | // Result might be dependent or not. |
| 2789 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2790 | DependentSizedExtVectorTypeLoc NewTL |
| 2791 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2792 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2793 | } else { |
| 2794 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2795 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2796 | } |
| 2797 | |
| 2798 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2800 | |
| 2801 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2803 | VectorTypeLoc TL, |
| 2804 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2805 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2806 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2807 | if (ElementType.isNull()) |
| 2808 | return QualType(); |
| 2809 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2810 | QualType Result = TL.getType(); |
| 2811 | if (getDerived().AlwaysRebuild() || |
| 2812 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2813 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2814 | T->getAltiVecSpecific()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2815 | if (Result.isNull()) |
| 2816 | return QualType(); |
| 2817 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2818 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2819 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2820 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2821 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2822 | return Result; |
| 2823 | } |
| 2824 | |
| 2825 | template<typename Derived> |
| 2826 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2827 | ExtVectorTypeLoc TL, |
| 2828 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | VectorType *T = TL.getTypePtr(); |
| 2830 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2831 | if (ElementType.isNull()) |
| 2832 | return QualType(); |
| 2833 | |
| 2834 | QualType Result = TL.getType(); |
| 2835 | if (getDerived().AlwaysRebuild() || |
| 2836 | ElementType != T->getElementType()) { |
| 2837 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2838 | T->getNumElements(), |
| 2839 | /*FIXME*/ SourceLocation()); |
| 2840 | if (Result.isNull()) |
| 2841 | return QualType(); |
| 2842 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2843 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2844 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2845 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2846 | |
| 2847 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2849 | |
| 2850 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2851 | ParmVarDecl * |
| 2852 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2853 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2854 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2855 | if (!NewDI) |
| 2856 | return 0; |
| 2857 | |
| 2858 | if (NewDI == OldDI) |
| 2859 | return OldParm; |
| 2860 | else |
| 2861 | return ParmVarDecl::Create(SemaRef.Context, |
| 2862 | OldParm->getDeclContext(), |
| 2863 | OldParm->getLocation(), |
| 2864 | OldParm->getIdentifier(), |
| 2865 | NewDI->getType(), |
| 2866 | NewDI, |
| 2867 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2868 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2869 | /* DefArg */ NULL); |
| 2870 | } |
| 2871 | |
| 2872 | template<typename Derived> |
| 2873 | bool TreeTransform<Derived>:: |
| 2874 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2875 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2876 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2877 | FunctionProtoType *T = TL.getTypePtr(); |
| 2878 | |
| 2879 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2880 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2881 | |
| 2882 | QualType NewType; |
| 2883 | ParmVarDecl *NewParm; |
| 2884 | |
| 2885 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2886 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2887 | if (!NewParm) |
| 2888 | return true; |
| 2889 | NewType = NewParm->getType(); |
| 2890 | |
| 2891 | // Deal with the possibility that we don't have a parameter |
| 2892 | // declaration for this parameter. |
| 2893 | } else { |
| 2894 | NewParm = 0; |
| 2895 | |
| 2896 | QualType OldType = T->getArgType(i); |
| 2897 | NewType = getDerived().TransformType(OldType); |
| 2898 | if (NewType.isNull()) |
| 2899 | return true; |
| 2900 | } |
| 2901 | |
| 2902 | PTypes.push_back(NewType); |
| 2903 | PVars.push_back(NewParm); |
| 2904 | } |
| 2905 | |
| 2906 | return false; |
| 2907 | } |
| 2908 | |
| 2909 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2911 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2912 | FunctionProtoTypeLoc TL, |
| 2913 | QualType ObjectType) { |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2914 | // Transform the parameters. We do this first for the benefit of template |
| 2915 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2916 | // instantiation scope before we transform the function type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2917 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2918 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2919 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2920 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2921 | |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2922 | FunctionProtoType *T = TL.getTypePtr(); |
| 2923 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2924 | if (ResultType.isNull()) |
| 2925 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2926 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | QualType Result = TL.getType(); |
| 2928 | if (getDerived().AlwaysRebuild() || |
| 2929 | ResultType != T->getResultType() || |
| 2930 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2931 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2932 | ParamTypes.data(), |
| 2933 | ParamTypes.size(), |
| 2934 | T->isVariadic(), |
| 2935 | T->getTypeQuals()); |
| 2936 | if (Result.isNull()) |
| 2937 | return QualType(); |
| 2938 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2939 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2940 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2941 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2942 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2943 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2944 | NewTL.setArg(i, ParamDecls[i]); |
| 2945 | |
| 2946 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2947 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2948 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2949 | template<typename Derived> |
| 2950 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2951 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2952 | FunctionNoProtoTypeLoc TL, |
| 2953 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2954 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2955 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2956 | if (ResultType.isNull()) |
| 2957 | return QualType(); |
| 2958 | |
| 2959 | QualType Result = TL.getType(); |
| 2960 | if (getDerived().AlwaysRebuild() || |
| 2961 | ResultType != T->getResultType()) |
| 2962 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2963 | |
| 2964 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2965 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2966 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2967 | |
| 2968 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2969 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2970 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2971 | template<typename Derived> QualType |
| 2972 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2973 | UnresolvedUsingTypeLoc TL, |
| 2974 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2975 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2976 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2977 | if (!D) |
| 2978 | return QualType(); |
| 2979 | |
| 2980 | QualType Result = TL.getType(); |
| 2981 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2982 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2983 | if (Result.isNull()) |
| 2984 | return QualType(); |
| 2985 | } |
| 2986 | |
| 2987 | // We might get an arbitrary type spec type back. We should at |
| 2988 | // least always get a type spec type, though. |
| 2989 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2990 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2991 | |
| 2992 | return Result; |
| 2993 | } |
| 2994 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2995 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2996 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2997 | TypedefTypeLoc TL, |
| 2998 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2999 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3000 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3001 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3002 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3003 | if (!Typedef) |
| 3004 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3005 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3006 | QualType Result = TL.getType(); |
| 3007 | if (getDerived().AlwaysRebuild() || |
| 3008 | Typedef != T->getDecl()) { |
| 3009 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3010 | if (Result.isNull()) |
| 3011 | return QualType(); |
| 3012 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3013 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3014 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3015 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3016 | |
| 3017 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3019 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3020 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3021 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3022 | TypeOfExprTypeLoc TL, |
| 3023 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3024 | // typeof expressions are not potentially evaluated contexts |
| 3025 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3027 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3028 | if (E.isInvalid()) |
| 3029 | return QualType(); |
| 3030 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3031 | QualType Result = TL.getType(); |
| 3032 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3033 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3034 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3035 | if (Result.isNull()) |
| 3036 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3037 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3040 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3041 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3042 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3043 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3044 | |
| 3045 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 | |
| 3048 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3049 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3050 | TypeOfTypeLoc TL, |
| 3051 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3052 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3053 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3054 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3055 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3056 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3057 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3058 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3059 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3060 | if (Result.isNull()) |
| 3061 | return QualType(); |
| 3062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3063 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3064 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3065 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3066 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3067 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3068 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3069 | |
| 3070 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3072 | |
| 3073 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3074 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3075 | DecltypeTypeLoc TL, |
| 3076 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3077 | DecltypeType *T = TL.getTypePtr(); |
| 3078 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3079 | // decltype expressions are not potentially evaluated contexts |
| 3080 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3082 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3083 | if (E.isInvalid()) |
| 3084 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3085 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3086 | QualType Result = TL.getType(); |
| 3087 | if (getDerived().AlwaysRebuild() || |
| 3088 | E.get() != T->getUnderlyingExpr()) { |
| 3089 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3090 | if (Result.isNull()) |
| 3091 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3092 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3093 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3095 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3096 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3097 | |
| 3098 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3102 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3103 | RecordTypeLoc TL, |
| 3104 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3105 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3106 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3107 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3108 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3109 | if (!Record) |
| 3110 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3112 | QualType Result = TL.getType(); |
| 3113 | if (getDerived().AlwaysRebuild() || |
| 3114 | Record != T->getDecl()) { |
| 3115 | Result = getDerived().RebuildRecordType(Record); |
| 3116 | if (Result.isNull()) |
| 3117 | return QualType(); |
| 3118 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3119 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3120 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3121 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3122 | |
| 3123 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | |
| 3126 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3127 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3128 | EnumTypeLoc TL, |
| 3129 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3130 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3131 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3132 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3133 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3134 | if (!Enum) |
| 3135 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3136 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3137 | QualType Result = TL.getType(); |
| 3138 | if (getDerived().AlwaysRebuild() || |
| 3139 | Enum != T->getDecl()) { |
| 3140 | Result = getDerived().RebuildEnumType(Enum); |
| 3141 | if (Result.isNull()) |
| 3142 | return QualType(); |
| 3143 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3144 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3145 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3146 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3147 | |
| 3148 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3149 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3150 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3151 | template<typename Derived> |
| 3152 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3153 | TypeLocBuilder &TLB, |
| 3154 | InjectedClassNameTypeLoc TL, |
| 3155 | QualType ObjectType) { |
| 3156 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3157 | TL.getTypePtr()->getDecl()); |
| 3158 | if (!D) return QualType(); |
| 3159 | |
| 3160 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3161 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3162 | return T; |
| 3163 | } |
| 3164 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3165 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3166 | template<typename Derived> |
| 3167 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3168 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3169 | TemplateTypeParmTypeLoc TL, |
| 3170 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3171 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3175 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3176 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3177 | SubstTemplateTypeParmTypeLoc TL, |
| 3178 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3179 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3183 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3184 | const TemplateSpecializationType *TST, |
| 3185 | QualType ObjectType) { |
| 3186 | // FIXME: this entire method is a temporary workaround; callers |
| 3187 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3188 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3189 | // Fake up a TemplateSpecializationTypeLoc. |
| 3190 | TypeLocBuilder TLB; |
| 3191 | TemplateSpecializationTypeLoc TL |
| 3192 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3193 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3194 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3195 | |
| 3196 | TL.setTemplateNameLoc(BaseLoc); |
| 3197 | TL.setLAngleLoc(BaseLoc); |
| 3198 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3199 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3200 | const TemplateArgument &TA = TST->getArg(i); |
| 3201 | TemplateArgumentLoc TAL; |
| 3202 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3203 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3204 | } |
| 3205 | |
| 3206 | TypeLocBuilder IgnoredTLB; |
| 3207 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3208 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3209 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3210 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3211 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3212 | TypeLocBuilder &TLB, |
| 3213 | TemplateSpecializationTypeLoc TL, |
| 3214 | QualType ObjectType) { |
| 3215 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3216 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3218 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3219 | if (Template.isNull()) |
| 3220 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3221 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3222 | TemplateArgumentListInfo NewTemplateArgs; |
| 3223 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3224 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3225 | |
| 3226 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3227 | TemplateArgumentLoc Loc; |
| 3228 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3229 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3230 | NewTemplateArgs.addArgument(Loc); |
| 3231 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3232 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3233 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3234 | |
| 3235 | QualType Result = |
| 3236 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3237 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3238 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3239 | |
| 3240 | if (!Result.isNull()) { |
| 3241 | TemplateSpecializationTypeLoc NewTL |
| 3242 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3243 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3244 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3245 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3246 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3247 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3249 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3250 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3251 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | |
| 3253 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3254 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3255 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 3256 | ElaboratedTypeLoc TL, |
| 3257 | QualType ObjectType) { |
| 3258 | ElaboratedType *T = TL.getTypePtr(); |
| 3259 | |
| 3260 | NestedNameSpecifier *NNS = 0; |
| 3261 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 3262 | if (T->getQualifier() != 0) { |
| 3263 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3264 | TL.getQualifierRange(), |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3265 | ObjectType); |
| 3266 | if (!NNS) |
| 3267 | return QualType(); |
| 3268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3269 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3270 | QualType NamedT; |
| 3271 | // FIXME: this test is meant to workaround a problem (failing assertion) |
| 3272 | // occurring if directly executing the code in the else branch. |
| 3273 | if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) { |
| 3274 | TemplateSpecializationTypeLoc OldNamedTL |
| 3275 | = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc()); |
| 3276 | const TemplateSpecializationType* OldTST |
Jim Grosbach | 9cbb4d8 | 2010-05-19 23:53:08 +0000 | [diff] [blame] | 3277 | = OldNamedTL.getType()->template getAs<TemplateSpecializationType>(); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3278 | NamedT = TransformTemplateSpecializationType(OldTST, ObjectType); |
| 3279 | if (NamedT.isNull()) |
| 3280 | return QualType(); |
| 3281 | TemplateSpecializationTypeLoc NewNamedTL |
| 3282 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3283 | NewNamedTL.copy(OldNamedTL); |
| 3284 | } |
| 3285 | else { |
| 3286 | NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 3287 | if (NamedT.isNull()) |
| 3288 | return QualType(); |
| 3289 | } |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 3290 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3291 | QualType Result = TL.getType(); |
| 3292 | if (getDerived().AlwaysRebuild() || |
| 3293 | NNS != T->getQualifier() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3294 | NamedT != T->getNamedType()) { |
| 3295 | Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3296 | if (Result.isNull()) |
| 3297 | return QualType(); |
| 3298 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3299 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3300 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3301 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3302 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3303 | |
| 3304 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3306 | |
| 3307 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3308 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3309 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3310 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3311 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3313 | NestedNameSpecifier *NNS |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3314 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3315 | TL.getQualifierRange(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3316 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3317 | if (!NNS) |
| 3318 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3320 | QualType Result |
| 3321 | = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3322 | T->getIdentifier(), |
| 3323 | TL.getKeywordLoc(), |
| 3324 | TL.getQualifierRange(), |
| 3325 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3326 | if (Result.isNull()) |
| 3327 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3328 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3329 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 3330 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3331 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 3332 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3333 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3334 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3335 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3336 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3337 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 3338 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3339 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3340 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3341 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3342 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3343 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3345 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3346 | QualType TreeTransform<Derived>:: |
| 3347 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 3348 | DependentTemplateSpecializationTypeLoc TL, |
| 3349 | QualType ObjectType) { |
| 3350 | DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 3351 | |
| 3352 | NestedNameSpecifier *NNS |
| 3353 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3354 | TL.getQualifierRange(), |
| 3355 | ObjectType); |
| 3356 | if (!NNS) |
| 3357 | return QualType(); |
| 3358 | |
| 3359 | TemplateArgumentListInfo NewTemplateArgs; |
| 3360 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3361 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3362 | |
| 3363 | for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) { |
| 3364 | TemplateArgumentLoc Loc; |
| 3365 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc)) |
| 3366 | return QualType(); |
| 3367 | NewTemplateArgs.addArgument(Loc); |
| 3368 | } |
| 3369 | |
| 3370 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| 3371 | T->getKeyword(), |
| 3372 | NNS, |
| 3373 | T->getIdentifier(), |
| 3374 | TL.getNameLoc(), |
| 3375 | NewTemplateArgs); |
| 3376 | if (Result.isNull()) |
| 3377 | return QualType(); |
| 3378 | |
| 3379 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 3380 | QualType NamedT = ElabT->getNamedType(); |
| 3381 | |
| 3382 | // Copy information relevant to the template specialization. |
| 3383 | TemplateSpecializationTypeLoc NamedTL |
| 3384 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3385 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3386 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3387 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3388 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 3389 | |
| 3390 | // Copy information relevant to the elaborated type. |
| 3391 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3392 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3393 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3394 | } else { |
Douglas Gregor | e2872d0 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 3395 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 3396 | TLB.pushFullCopy(NewTL); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3397 | } |
| 3398 | return Result; |
| 3399 | } |
| 3400 | |
| 3401 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3402 | QualType |
| 3403 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3404 | ObjCInterfaceTypeLoc TL, |
| 3405 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3406 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3407 | TLB.pushFullCopy(TL); |
| 3408 | return TL.getType(); |
| 3409 | } |
| 3410 | |
| 3411 | template<typename Derived> |
| 3412 | QualType |
| 3413 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 3414 | ObjCObjectTypeLoc TL, |
| 3415 | QualType ObjectType) { |
| 3416 | // ObjCObjectType is never dependent. |
| 3417 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3418 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3419 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3420 | |
| 3421 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3422 | QualType |
| 3423 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3424 | ObjCObjectPointerTypeLoc TL, |
| 3425 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3426 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3427 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3428 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3431 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3432 | // Statement transformation |
| 3433 | //===----------------------------------------------------------------------===// |
| 3434 | template<typename Derived> |
| 3435 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3436 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3437 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | template<typename Derived> |
| 3441 | Sema::OwningStmtResult |
| 3442 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3443 | return getDerived().TransformCompoundStmt(S, false); |
| 3444 | } |
| 3445 | |
| 3446 | template<typename Derived> |
| 3447 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3449 | bool IsStmtExpr) { |
| 3450 | bool SubStmtChanged = false; |
| 3451 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3452 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3453 | B != BEnd; ++B) { |
| 3454 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3455 | if (Result.isInvalid()) |
| 3456 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3458 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3459 | Statements.push_back(Result.takeAs<Stmt>()); |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 3463 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | |
| 3466 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3467 | move_arg(Statements), |
| 3468 | S->getRBracLoc(), |
| 3469 | IsStmtExpr); |
| 3470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3471 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3472 | template<typename Derived> |
| 3473 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3475 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3476 | { |
| 3477 | // The case value expressions are not potentially evaluated. |
| 3478 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3480 | // Transform the left-hand case value. |
| 3481 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3482 | if (LHS.isInvalid()) |
| 3483 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3484 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3485 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3486 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3487 | if (RHS.isInvalid()) |
| 3488 | return SemaRef.StmtError(); |
| 3489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3490 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3491 | // Build the case statement. |
| 3492 | // Case statements are always rebuilt so that they will attached to their |
| 3493 | // transformed switch statement. |
| 3494 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3495 | move(LHS), |
| 3496 | S->getEllipsisLoc(), |
| 3497 | move(RHS), |
| 3498 | S->getColonLoc()); |
| 3499 | if (Case.isInvalid()) |
| 3500 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3501 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3502 | // Transform the statement following the case |
| 3503 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3504 | if (SubStmt.isInvalid()) |
| 3505 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3507 | // Attach the body to the case statement |
| 3508 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3509 | } |
| 3510 | |
| 3511 | template<typename Derived> |
| 3512 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3513 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3514 | // Transform the statement following the default case |
| 3515 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3516 | if (SubStmt.isInvalid()) |
| 3517 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3519 | // Default statements are always rebuilt |
| 3520 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3521 | move(SubStmt)); |
| 3522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | template<typename Derived> |
| 3525 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3527 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3528 | if (SubStmt.isInvalid()) |
| 3529 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3531 | // FIXME: Pass the real colon location in. |
| 3532 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3533 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3534 | move(SubStmt)); |
| 3535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3537 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3538 | Sema::OwningStmtResult |
| 3539 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3540 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3541 | OwningExprResult Cond(SemaRef); |
| 3542 | VarDecl *ConditionVar = 0; |
| 3543 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3544 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3545 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3546 | getDerived().TransformDefinition( |
| 3547 | S->getConditionVariable()->getLocation(), |
| 3548 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3549 | if (!ConditionVar) |
| 3550 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3551 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3552 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3553 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3554 | if (Cond.isInvalid()) |
| 3555 | return SemaRef.StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3556 | |
| 3557 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3558 | if (S->getCond()) { |
| 3559 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3560 | S->getIfLoc(), |
| 3561 | move(Cond)); |
| 3562 | if (CondE.isInvalid()) |
| 3563 | return getSema().StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3565 | Cond = move(CondE); |
| 3566 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3567 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3568 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3569 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3570 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3571 | return SemaRef.StmtError(); |
| 3572 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3573 | // Transform the "then" branch. |
| 3574 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3575 | if (Then.isInvalid()) |
| 3576 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3577 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3578 | // Transform the "else" branch. |
| 3579 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3580 | if (Else.isInvalid()) |
| 3581 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3583 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3584 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3585 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3586 | Then.get() == S->getThen() && |
| 3587 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | return SemaRef.Owned(S->Retain()); |
| 3589 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3590 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3591 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3592 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | template<typename Derived> |
| 3596 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3597 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3598 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3599 | OwningExprResult Cond(SemaRef); |
| 3600 | VarDecl *ConditionVar = 0; |
| 3601 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3602 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3603 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3604 | getDerived().TransformDefinition( |
| 3605 | S->getConditionVariable()->getLocation(), |
| 3606 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3607 | if (!ConditionVar) |
| 3608 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3609 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3610 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3611 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3612 | if (Cond.isInvalid()) |
| 3613 | return SemaRef.StmtError(); |
| 3614 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3616 | // Rebuild the switch statement. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3617 | OwningStmtResult Switch |
| 3618 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3619 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3620 | if (Switch.isInvalid()) |
| 3621 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3623 | // Transform the body of the switch statement. |
| 3624 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3625 | if (Body.isInvalid()) |
| 3626 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3628 | // Complete the switch statement. |
| 3629 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3630 | move(Body)); |
| 3631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3633 | template<typename Derived> |
| 3634 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3636 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3637 | OwningExprResult Cond(SemaRef); |
| 3638 | VarDecl *ConditionVar = 0; |
| 3639 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3640 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3641 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3642 | getDerived().TransformDefinition( |
| 3643 | S->getConditionVariable()->getLocation(), |
| 3644 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3645 | if (!ConditionVar) |
| 3646 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3647 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3648 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3650 | if (Cond.isInvalid()) |
| 3651 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3652 | |
| 3653 | if (S->getCond()) { |
| 3654 | // Convert the condition to a boolean value. |
| 3655 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3656 | S->getWhileLoc(), |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3657 | move(Cond)); |
| 3658 | if (CondE.isInvalid()) |
| 3659 | return getSema().StmtError(); |
| 3660 | Cond = move(CondE); |
| 3661 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3662 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3664 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3665 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3666 | return SemaRef.StmtError(); |
| 3667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3668 | // Transform the body |
| 3669 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3670 | if (Body.isInvalid()) |
| 3671 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3673 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3674 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3675 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3676 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | return SemaRef.Owned(S->Retain()); |
| 3678 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3679 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3680 | ConditionVar, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3681 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3683 | template<typename Derived> |
| 3684 | Sema::OwningStmtResult |
| 3685 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3686 | // Transform the body |
| 3687 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3688 | if (Body.isInvalid()) |
| 3689 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3691 | // Transform the condition |
| 3692 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3693 | if (Cond.isInvalid()) |
| 3694 | return SemaRef.StmtError(); |
| 3695 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3696 | if (!getDerived().AlwaysRebuild() && |
| 3697 | Cond.get() == S->getCond() && |
| 3698 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | return SemaRef.Owned(S->Retain()); |
| 3700 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3701 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3702 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3703 | S->getRParenLoc()); |
| 3704 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3706 | template<typename Derived> |
| 3707 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3708 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3709 | // Transform the initialization statement |
| 3710 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3711 | if (Init.isInvalid()) |
| 3712 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3714 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3715 | OwningExprResult Cond(SemaRef); |
| 3716 | VarDecl *ConditionVar = 0; |
| 3717 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3718 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3719 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3720 | getDerived().TransformDefinition( |
| 3721 | S->getConditionVariable()->getLocation(), |
| 3722 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3723 | if (!ConditionVar) |
| 3724 | return SemaRef.StmtError(); |
| 3725 | } else { |
| 3726 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3727 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3728 | if (Cond.isInvalid()) |
| 3729 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3730 | |
| 3731 | if (S->getCond()) { |
| 3732 | // Convert the condition to a boolean value. |
| 3733 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3734 | S->getForLoc(), |
| 3735 | move(Cond)); |
| 3736 | if (CondE.isInvalid()) |
| 3737 | return getSema().StmtError(); |
| 3738 | |
| 3739 | Cond = move(CondE); |
| 3740 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3741 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3743 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3744 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3745 | return SemaRef.StmtError(); |
| 3746 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3747 | // Transform the increment |
| 3748 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3749 | if (Inc.isInvalid()) |
| 3750 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3751 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3752 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3753 | if (S->getInc() && !FullInc->get()) |
| 3754 | return SemaRef.StmtError(); |
| 3755 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3756 | // Transform the body |
| 3757 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3758 | if (Body.isInvalid()) |
| 3759 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3761 | if (!getDerived().AlwaysRebuild() && |
| 3762 | Init.get() == S->getInit() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3763 | FullCond->get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3764 | Inc.get() == S->getInc() && |
| 3765 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3766 | return SemaRef.Owned(S->Retain()); |
| 3767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3768 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3769 | move(Init), FullCond, ConditionVar, |
| 3770 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3774 | Sema::OwningStmtResult |
| 3775 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3776 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3778 | S->getLabel()); |
| 3779 | } |
| 3780 | |
| 3781 | template<typename Derived> |
| 3782 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3784 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3785 | if (Target.isInvalid()) |
| 3786 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3788 | if (!getDerived().AlwaysRebuild() && |
| 3789 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3790 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3791 | |
| 3792 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3793 | move(Target)); |
| 3794 | } |
| 3795 | |
| 3796 | template<typename Derived> |
| 3797 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3799 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3800 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3801 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3802 | template<typename Derived> |
| 3803 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3804 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3805 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3807 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3808 | template<typename Derived> |
| 3809 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3810 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3811 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3812 | if (Result.isInvalid()) |
| 3813 | return SemaRef.StmtError(); |
| 3814 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3816 | // to tell whether the return type of the function has changed. |
| 3817 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3818 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3820 | template<typename Derived> |
| 3821 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3823 | bool DeclChanged = false; |
| 3824 | llvm::SmallVector<Decl *, 4> Decls; |
| 3825 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3826 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3827 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3828 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3829 | if (!Transformed) |
| 3830 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3831 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3832 | if (Transformed != *D) |
| 3833 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3834 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3835 | Decls.push_back(Transformed); |
| 3836 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3838 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 | return SemaRef.Owned(S->Retain()); |
| 3840 | |
| 3841 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3842 | S->getStartLoc(), S->getEndLoc()); |
| 3843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3845 | template<typename Derived> |
| 3846 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3847 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3848 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | template<typename Derived> |
| 3853 | Sema::OwningStmtResult |
| 3854 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3855 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3856 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3857 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3858 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3859 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3860 | OwningExprResult AsmString(SemaRef); |
| 3861 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3862 | |
| 3863 | bool ExprsChanged = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3864 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3865 | // Go through the outputs. |
| 3866 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3867 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3868 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3869 | // No need to transform the constraint literal. |
| 3870 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3871 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3872 | // Transform the output expr. |
| 3873 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3874 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3875 | if (Result.isInvalid()) |
| 3876 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3877 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3878 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3879 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3880 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3881 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3882 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3883 | // Go through the inputs. |
| 3884 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3885 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3886 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3887 | // No need to transform the constraint literal. |
| 3888 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3889 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3890 | // Transform the input expr. |
| 3891 | Expr *InputExpr = S->getInputExpr(I); |
| 3892 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3893 | if (Result.isInvalid()) |
| 3894 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3895 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3896 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3897 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3898 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3899 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3900 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3901 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3902 | return SemaRef.Owned(S->Retain()); |
| 3903 | |
| 3904 | // Go through the clobbers. |
| 3905 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3906 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3907 | |
| 3908 | // No need to transform the asm string literal. |
| 3909 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3910 | |
| 3911 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3912 | S->isSimple(), |
| 3913 | S->isVolatile(), |
| 3914 | S->getNumOutputs(), |
| 3915 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3916 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3917 | move_arg(Constraints), |
| 3918 | move_arg(Exprs), |
| 3919 | move(AsmString), |
| 3920 | move_arg(Clobbers), |
| 3921 | S->getRParenLoc(), |
| 3922 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | |
| 3926 | template<typename Derived> |
| 3927 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3929 | // Transform the body of the @try. |
| 3930 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3931 | if (TryBody.isInvalid()) |
| 3932 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3934 | // Transform the @catch statements (if present). |
| 3935 | bool AnyCatchChanged = false; |
| 3936 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3937 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3938 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3939 | if (Catch.isInvalid()) |
| 3940 | return SemaRef.StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3941 | if (Catch.get() != S->getCatchStmt(I)) |
| 3942 | AnyCatchChanged = true; |
| 3943 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3944 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3946 | // Transform the @finally statement (if present). |
| 3947 | OwningStmtResult Finally(SemaRef); |
| 3948 | if (S->getFinallyStmt()) { |
| 3949 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3950 | if (Finally.isInvalid()) |
| 3951 | return SemaRef.StmtError(); |
| 3952 | } |
| 3953 | |
| 3954 | // If nothing changed, just retain this statement. |
| 3955 | if (!getDerived().AlwaysRebuild() && |
| 3956 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3957 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3958 | Finally.get() == S->getFinallyStmt()) |
| 3959 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3961 | // Build a new statement. |
| 3962 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3963 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3964 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3966 | template<typename Derived> |
| 3967 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3969 | // Transform the @catch parameter, if there is one. |
| 3970 | VarDecl *Var = 0; |
| 3971 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3972 | TypeSourceInfo *TSInfo = 0; |
| 3973 | if (FromVar->getTypeSourceInfo()) { |
| 3974 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3975 | if (!TSInfo) |
| 3976 | return SemaRef.StmtError(); |
| 3977 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3979 | QualType T; |
| 3980 | if (TSInfo) |
| 3981 | T = TSInfo->getType(); |
| 3982 | else { |
| 3983 | T = getDerived().TransformType(FromVar->getType()); |
| 3984 | if (T.isNull()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3985 | return SemaRef.StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3986 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3987 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3988 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3989 | if (!Var) |
| 3990 | return SemaRef.StmtError(); |
| 3991 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3993 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3994 | if (Body.isInvalid()) |
| 3995 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3996 | |
| 3997 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3998 | S->getRParenLoc(), |
| 3999 | Var, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4000 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4002 | template<typename Derived> |
| 4003 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4004 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4005 | // Transform the body. |
| 4006 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 4007 | if (Body.isInvalid()) |
| 4008 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4009 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4010 | // If nothing changed, just retain this statement. |
| 4011 | if (!getDerived().AlwaysRebuild() && |
| 4012 | Body.get() == S->getFinallyBody()) |
| 4013 | return SemaRef.Owned(S->Retain()); |
| 4014 | |
| 4015 | // Build a new statement. |
| 4016 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 4017 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4020 | template<typename Derived> |
| 4021 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4023 | OwningExprResult Operand(SemaRef); |
| 4024 | if (S->getThrowExpr()) { |
| 4025 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 4026 | if (Operand.isInvalid()) |
| 4027 | return getSema().StmtError(); |
| 4028 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4029 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4030 | if (!getDerived().AlwaysRebuild() && |
| 4031 | Operand.get() == S->getThrowExpr()) |
| 4032 | return getSema().Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4033 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4034 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4037 | template<typename Derived> |
| 4038 | Sema::OwningStmtResult |
| 4039 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4041 | // Transform the object we are locking. |
| 4042 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 4043 | if (Object.isInvalid()) |
| 4044 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4046 | // Transform the body. |
| 4047 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 4048 | if (Body.isInvalid()) |
| 4049 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4051 | // If nothing change, just retain the current statement. |
| 4052 | if (!getDerived().AlwaysRebuild() && |
| 4053 | Object.get() == S->getSynchExpr() && |
| 4054 | Body.get() == S->getSynchBody()) |
| 4055 | return SemaRef.Owned(S->Retain()); |
| 4056 | |
| 4057 | // Build a new statement. |
| 4058 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 4059 | move(Object), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | template<typename Derived> |
| 4063 | Sema::OwningStmtResult |
| 4064 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4065 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4066 | // Transform the element statement. |
| 4067 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 4068 | if (Element.isInvalid()) |
| 4069 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4070 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4071 | // Transform the collection expression. |
| 4072 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 4073 | if (Collection.isInvalid()) |
| 4074 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4075 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4076 | // Transform the body. |
| 4077 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 4078 | if (Body.isInvalid()) |
| 4079 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4081 | // If nothing changed, just retain this statement. |
| 4082 | if (!getDerived().AlwaysRebuild() && |
| 4083 | Element.get() == S->getElement() && |
| 4084 | Collection.get() == S->getCollection() && |
| 4085 | Body.get() == S->getBody()) |
| 4086 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4088 | // Build a new statement. |
| 4089 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4090 | /*FIXME:*/S->getForLoc(), |
| 4091 | move(Element), |
| 4092 | move(Collection), |
| 4093 | S->getRParenLoc(), |
| 4094 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | |
| 4098 | template<typename Derived> |
| 4099 | Sema::OwningStmtResult |
| 4100 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4101 | // Transform the exception declaration, if any. |
| 4102 | VarDecl *Var = 0; |
| 4103 | if (S->getExceptionDecl()) { |
| 4104 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4105 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4106 | ExceptionDecl->getDeclName()); |
| 4107 | |
| 4108 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4109 | if (T.isNull()) |
| 4110 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4111 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4112 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4113 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4114 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4115 | ExceptionDecl->getIdentifier(), |
| 4116 | ExceptionDecl->getLocation(), |
| 4117 | /*FIXME: Inaccurate*/ |
| 4118 | SourceRange(ExceptionDecl->getLocation())); |
| 4119 | if (!Var || Var->isInvalidDecl()) { |
| 4120 | if (Var) |
| 4121 | Var->Destroy(SemaRef.Context); |
| 4122 | return SemaRef.StmtError(); |
| 4123 | } |
| 4124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4126 | // Transform the actual exception handler. |
| 4127 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 4128 | if (Handler.isInvalid()) { |
| 4129 | if (Var) |
| 4130 | Var->Destroy(SemaRef.Context); |
| 4131 | return SemaRef.StmtError(); |
| 4132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4134 | if (!getDerived().AlwaysRebuild() && |
| 4135 | !Var && |
| 4136 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4137 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4138 | |
| 4139 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4140 | Var, |
| 4141 | move(Handler)); |
| 4142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4143 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4144 | template<typename Derived> |
| 4145 | Sema::OwningStmtResult |
| 4146 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4147 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4149 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4150 | if (TryBlock.isInvalid()) |
| 4151 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4153 | // Transform the handlers. |
| 4154 | bool HandlerChanged = false; |
| 4155 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4156 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4158 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4159 | if (Handler.isInvalid()) |
| 4160 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4161 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4162 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4163 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4164 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4165 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4166 | if (!getDerived().AlwaysRebuild() && |
| 4167 | TryBlock.get() == S->getTryBlock() && |
| 4168 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4169 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4170 | |
| 4171 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4172 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4173 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4175 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4176 | // Expression transformation |
| 4177 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4178 | template<typename Derived> |
| 4179 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4180 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | |
| 4184 | template<typename Derived> |
| 4185 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4186 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4187 | NestedNameSpecifier *Qualifier = 0; |
| 4188 | if (E->getQualifier()) { |
| 4189 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4190 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4191 | if (!Qualifier) |
| 4192 | return SemaRef.ExprError(); |
| 4193 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4194 | |
| 4195 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4196 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4197 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | if (!ND) |
| 4199 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4201 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4202 | Qualifier == E->getQualifier() && |
| 4203 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4204 | !E->hasExplicitTemplateArgumentList()) { |
| 4205 | |
| 4206 | // Mark it referenced in the new context regardless. |
| 4207 | // FIXME: this is a bit instantiation-specific. |
| 4208 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4209 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4210 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4211 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4212 | |
| 4213 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4214 | if (E->hasExplicitTemplateArgumentList()) { |
| 4215 | TemplateArgs = &TransArgs; |
| 4216 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4217 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4218 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4219 | TemplateArgumentLoc Loc; |
| 4220 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4221 | return SemaRef.ExprError(); |
| 4222 | TransArgs.addArgument(Loc); |
| 4223 | } |
| 4224 | } |
| 4225 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4226 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4227 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4228 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4230 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4231 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4232 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4234 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4235 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4236 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4237 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4238 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4239 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4240 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4241 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4242 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4244 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4245 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4248 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4249 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4250 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4251 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4252 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4256 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | return SemaRef.Owned(E->Retain()); |
| 4258 | } |
| 4259 | |
| 4260 | template<typename Derived> |
| 4261 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4262 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4264 | if (SubExpr.isInvalid()) |
| 4265 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4267 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4268 | return SemaRef.Owned(E->Retain()); |
| 4269 | |
| 4270 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4271 | E->getRParen()); |
| 4272 | } |
| 4273 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4274 | template<typename Derived> |
| 4275 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4276 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4277 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | if (SubExpr.isInvalid()) |
| 4279 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4282 | return SemaRef.Owned(E->Retain()); |
| 4283 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4284 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4285 | E->getOpcode(), |
| 4286 | move(SubExpr)); |
| 4287 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | Sema::OwningExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4291 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4292 | // Transform the type. |
| 4293 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4294 | if (!Type) |
| 4295 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4296 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4297 | // Transform all of the components into components similar to what the |
| 4298 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4299 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4300 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4301 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4302 | // template code that we don't care. |
| 4303 | bool ExprChanged = false; |
| 4304 | typedef Action::OffsetOfComponent Component; |
| 4305 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4306 | llvm::SmallVector<Component, 4> Components; |
| 4307 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4308 | const Node &ON = E->getComponent(I); |
| 4309 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4310 | Comp.isBrackets = true; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4311 | Comp.LocStart = ON.getRange().getBegin(); |
| 4312 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4313 | switch (ON.getKind()) { |
| 4314 | case Node::Array: { |
| 4315 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4316 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4317 | if (Index.isInvalid()) |
| 4318 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4319 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4320 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4321 | Comp.isBrackets = true; |
| 4322 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4323 | break; |
| 4324 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4326 | case Node::Field: |
| 4327 | case Node::Identifier: |
| 4328 | Comp.isBrackets = false; |
| 4329 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4330 | if (!Comp.U.IdentInfo) |
| 4331 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4332 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4333 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4334 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4335 | case Node::Base: |
| 4336 | // Will be recomputed during the rebuild. |
| 4337 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4338 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4339 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4340 | Components.push_back(Comp); |
| 4341 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4342 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4343 | // If nothing changed, retain the existing expression. |
| 4344 | if (!getDerived().AlwaysRebuild() && |
| 4345 | Type == E->getTypeSourceInfo() && |
| 4346 | !ExprChanged) |
| 4347 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4348 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4349 | // Build a new offsetof expression. |
| 4350 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4351 | Components.data(), Components.size(), |
| 4352 | E->getRParenLoc()); |
| 4353 | } |
| 4354 | |
| 4355 | template<typename Derived> |
| 4356 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4357 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4359 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4360 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4361 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4362 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4363 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4364 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4365 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4366 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4367 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4368 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | E->getSourceRange()); |
| 4371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4373 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | // C++0x [expr.sizeof]p1: |
| 4376 | // The operand is either an expression, which is an unevaluated operand |
| 4377 | // [...] |
| 4378 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4379 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4381 | if (SubExpr.isInvalid()) |
| 4382 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4385 | return SemaRef.Owned(E->Retain()); |
| 4386 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4389 | E->isSizeOf(), |
| 4390 | E->getSourceRange()); |
| 4391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4393 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4395 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4396 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4397 | if (LHS.isInvalid()) |
| 4398 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4401 | if (RHS.isInvalid()) |
| 4402 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4403 | |
| 4404 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4405 | if (!getDerived().AlwaysRebuild() && |
| 4406 | LHS.get() == E->getLHS() && |
| 4407 | RHS.get() == E->getRHS()) |
| 4408 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4411 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4412 | move(RHS), |
| 4413 | E->getRBracketLoc()); |
| 4414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | |
| 4416 | template<typename Derived> |
| 4417 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4418 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4419 | // Transform the callee. |
| 4420 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4421 | if (Callee.isInvalid()) |
| 4422 | return SemaRef.ExprError(); |
| 4423 | |
| 4424 | // Transform arguments. |
| 4425 | bool ArgChanged = false; |
| 4426 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4427 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4428 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4429 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4430 | if (Arg.isInvalid()) |
| 4431 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4432 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4433 | // FIXME: Wrong source location information for the ','. |
| 4434 | FakeCommaLocs.push_back( |
| 4435 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4436 | |
| 4437 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4438 | Args.push_back(Arg.takeAs<Expr>()); |
| 4439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4440 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4441 | if (!getDerived().AlwaysRebuild() && |
| 4442 | Callee.get() == E->getCallee() && |
| 4443 | !ArgChanged) |
| 4444 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4449 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4450 | move_arg(Args), |
| 4451 | FakeCommaLocs.data(), |
| 4452 | E->getRParenLoc()); |
| 4453 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4454 | |
| 4455 | template<typename Derived> |
| 4456 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4457 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4458 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4459 | if (Base.isInvalid()) |
| 4460 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4462 | NestedNameSpecifier *Qualifier = 0; |
| 4463 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4464 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4465 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4466 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4467 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4468 | return SemaRef.ExprError(); |
| 4469 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4470 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4471 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4472 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4473 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4474 | if (!Member) |
| 4475 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4477 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4478 | if (FoundDecl == E->getMemberDecl()) { |
| 4479 | FoundDecl = Member; |
| 4480 | } else { |
| 4481 | FoundDecl = cast_or_null<NamedDecl>( |
| 4482 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4483 | if (!FoundDecl) |
| 4484 | return SemaRef.ExprError(); |
| 4485 | } |
| 4486 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4487 | if (!getDerived().AlwaysRebuild() && |
| 4488 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4489 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4490 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4491 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4492 | !E->hasExplicitTemplateArgumentList()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4493 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4494 | // Mark it referenced in the new context regardless. |
| 4495 | // FIXME: this is a bit instantiation-specific. |
| 4496 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4497 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4498 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4499 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4500 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4501 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4502 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4503 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4504 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4505 | TemplateArgumentLoc Loc; |
| 4506 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4507 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4508 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4509 | } |
| 4510 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4511 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | // FIXME: Bogus source location for the operator |
| 4513 | SourceLocation FakeOperatorLoc |
| 4514 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4515 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4516 | // FIXME: to do this check properly, we will need to preserve the |
| 4517 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4518 | // base (and therefore couldn't do the check) and a |
| 4519 | // nested-name-qualifier (and therefore could do the lookup). |
| 4520 | NamedDecl *FirstQualifierInScope = 0; |
| 4521 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4523 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4524 | Qualifier, |
| 4525 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4527 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4528 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4529 | (E->hasExplicitTemplateArgumentList() |
| 4530 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4531 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4535 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4536 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4537 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4538 | if (LHS.isInvalid()) |
| 4539 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4541 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4542 | if (RHS.isInvalid()) |
| 4543 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4544 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4545 | if (!getDerived().AlwaysRebuild() && |
| 4546 | LHS.get() == E->getLHS() && |
| 4547 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | return SemaRef.Owned(E->Retain()); |
| 4549 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4550 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4551 | move(LHS), move(RHS)); |
| 4552 | } |
| 4553 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | Sema::OwningExprResult |
| 4556 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4557 | CompoundAssignOperator *E) { |
| 4558 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4563 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4564 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4565 | if (Cond.isInvalid()) |
| 4566 | return SemaRef.ExprError(); |
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 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4569 | if (LHS.isInvalid()) |
| 4570 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4573 | if (RHS.isInvalid()) |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 4577 | Cond.get() == E->getCond() && |
| 4578 | LHS.get() == E->getLHS() && |
| 4579 | RHS.get() == E->getRHS()) |
| 4580 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | |
| 4582 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4583 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4585 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4586 | move(RHS)); |
| 4587 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
| 4589 | template<typename Derived> |
| 4590 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4591 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4592 | // Implicit casts are eliminated during transformation, since they |
| 4593 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4594 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4595 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4596 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4597 | template<typename Derived> |
| 4598 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4599 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4600 | TypeSourceInfo *OldT; |
| 4601 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4602 | { |
| 4603 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4605 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4606 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4607 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4608 | OldT = E->getTypeInfoAsWritten(); |
| 4609 | NewT = getDerived().TransformType(OldT); |
| 4610 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | return SemaRef.ExprError(); |
| 4612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4613 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4614 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4615 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4616 | if (SubExpr.isInvalid()) |
| 4617 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4618 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4620 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4621 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4622 | return SemaRef.Owned(E->Retain()); |
| 4623 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4624 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4625 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4626 | E->getRParenLoc(), |
| 4627 | move(SubExpr)); |
| 4628 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4629 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4630 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4631 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4632 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4633 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4634 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4635 | if (!NewT) |
| 4636 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4639 | if (Init.isInvalid()) |
| 4640 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4642 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4643 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4647 | // Note: the expression type doesn't necessarily match the |
| 4648 | // type-as-written, but that's okay, because it should always be |
| 4649 | // derivable from the initializer. |
| 4650 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4651 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4652 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4653 | move(Init)); |
| 4654 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4655 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4656 | template<typename Derived> |
| 4657 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4658 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4660 | if (Base.isInvalid()) |
| 4661 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4663 | if (!getDerived().AlwaysRebuild() && |
| 4664 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | return SemaRef.Owned(E->Retain()); |
| 4666 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4667 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4668 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4669 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4670 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4671 | E->getAccessorLoc(), |
| 4672 | E->getAccessor()); |
| 4673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4674 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4675 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4676 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4677 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4681 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4682 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4683 | if (Init.isInvalid()) |
| 4684 | return SemaRef.ExprError(); |
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 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4687 | Inits.push_back(Init.takeAs<Expr>()); |
| 4688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4690 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | return SemaRef.Owned(E->Retain()); |
| 4692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4693 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4694 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4697 | template<typename Derived> |
| 4698 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4699 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4701 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4702 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4703 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4704 | if (Init.isInvalid()) |
| 4705 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4707 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4708 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4709 | bool ExprChanged = false; |
| 4710 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4711 | DEnd = E->designators_end(); |
| 4712 | D != DEnd; ++D) { |
| 4713 | if (D->isFieldDesignator()) { |
| 4714 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4715 | D->getDotLoc(), |
| 4716 | D->getFieldLoc())); |
| 4717 | continue; |
| 4718 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4719 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4720 | if (D->isArrayDesignator()) { |
| 4721 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4722 | if (Index.isInvalid()) |
| 4723 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4724 | |
| 4725 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4726 | D->getLBracketLoc())); |
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 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4729 | ArrayExprs.push_back(Index.release()); |
| 4730 | continue; |
| 4731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4732 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4733 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4734 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4735 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4736 | if (Start.isInvalid()) |
| 4737 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4739 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4740 | if (End.isInvalid()) |
| 4741 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4742 | |
| 4743 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4744 | End.get(), |
| 4745 | D->getLBracketLoc(), |
| 4746 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4747 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4749 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4750 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4751 | ArrayExprs.push_back(Start.release()); |
| 4752 | ArrayExprs.push_back(End.release()); |
| 4753 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | if (!getDerived().AlwaysRebuild() && |
| 4756 | Init.get() == E->getInit() && |
| 4757 | !ExprChanged) |
| 4758 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4759 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4760 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4761 | E->getEqualOrColonLoc(), |
| 4762 | E->usesGNUSyntax(), move(Init)); |
| 4763 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4765 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4766 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4768 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4769 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4771 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4772 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | QualType T = getDerived().TransformType(E->getType()); |
| 4774 | if (T.isNull()) |
| 4775 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4776 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4777 | if (!getDerived().AlwaysRebuild() && |
| 4778 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | return SemaRef.Owned(E->Retain()); |
| 4780 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4781 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4783 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4785 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4786 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | // FIXME: Do we want the type as written? |
| 4788 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4790 | { |
| 4791 | // FIXME: Source location isn't quite accurate. |
| 4792 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4793 | T = getDerived().TransformType(E->getType()); |
| 4794 | if (T.isNull()) |
| 4795 | return SemaRef.ExprError(); |
| 4796 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4798 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4799 | if (SubExpr.isInvalid()) |
| 4800 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4802 | if (!getDerived().AlwaysRebuild() && |
| 4803 | T == E->getType() && |
| 4804 | SubExpr.get() == E->getSubExpr()) |
| 4805 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4808 | T, E->getRParenLoc()); |
| 4809 | } |
| 4810 | |
| 4811 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4812 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4813 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4814 | bool ArgumentChanged = false; |
| 4815 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4816 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4817 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4818 | if (Init.isInvalid()) |
| 4819 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4821 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4822 | Inits.push_back(Init.takeAs<Expr>()); |
| 4823 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4825 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4826 | move_arg(Inits), |
| 4827 | E->getRParenLoc()); |
| 4828 | } |
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 | /// \brief Transform an address-of-label expression. |
| 4831 | /// |
| 4832 | /// By default, the transformation of an address-of-label expression always |
| 4833 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4834 | /// the corresponding label statement by semantic analysis. |
| 4835 | template<typename Derived> |
| 4836 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4837 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4839 | E->getLabel()); |
| 4840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4841 | |
| 4842 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4843 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4844 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4845 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4846 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4847 | if (SubStmt.isInvalid()) |
| 4848 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4849 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4850 | if (!getDerived().AlwaysRebuild() && |
| 4851 | SubStmt.get() == E->getSubStmt()) |
| 4852 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4853 | |
| 4854 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4855 | move(SubStmt), |
| 4856 | E->getRParenLoc()); |
| 4857 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4859 | template<typename Derived> |
| 4860 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4861 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4862 | QualType T1, T2; |
| 4863 | { |
| 4864 | // FIXME: Source location isn't quite accurate. |
| 4865 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4866 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4867 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4868 | if (T1.isNull()) |
| 4869 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4870 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4871 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4872 | if (T2.isNull()) |
| 4873 | return SemaRef.ExprError(); |
| 4874 | } |
| 4875 | |
| 4876 | if (!getDerived().AlwaysRebuild() && |
| 4877 | T1 == E->getArgType1() && |
| 4878 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4879 | return SemaRef.Owned(E->Retain()); |
| 4880 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4881 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4882 | T1, T2, E->getRParenLoc()); |
| 4883 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4884 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4885 | template<typename Derived> |
| 4886 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4887 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4888 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4889 | if (Cond.isInvalid()) |
| 4890 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4892 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4893 | if (LHS.isInvalid()) |
| 4894 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4895 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4897 | if (RHS.isInvalid()) |
| 4898 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4900 | if (!getDerived().AlwaysRebuild() && |
| 4901 | Cond.get() == E->getCond() && |
| 4902 | LHS.get() == E->getLHS() && |
| 4903 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | return SemaRef.Owned(E->Retain()); |
| 4905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4906 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4907 | move(Cond), move(LHS), move(RHS), |
| 4908 | E->getRParenLoc()); |
| 4909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4911 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4912 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4913 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | template<typename Derived> |
| 4918 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4919 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4920 | switch (E->getOperator()) { |
| 4921 | case OO_New: |
| 4922 | case OO_Delete: |
| 4923 | case OO_Array_New: |
| 4924 | case OO_Array_Delete: |
| 4925 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4926 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4927 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4928 | case OO_Call: { |
| 4929 | // This is a call to an object's operator(). |
| 4930 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4931 | |
| 4932 | // Transform the object itself. |
| 4933 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4934 | if (Object.isInvalid()) |
| 4935 | return SemaRef.ExprError(); |
| 4936 | |
| 4937 | // FIXME: Poor location information |
| 4938 | SourceLocation FakeLParenLoc |
| 4939 | = SemaRef.PP.getLocForEndOfToken( |
| 4940 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4941 | |
| 4942 | // Transform the call arguments. |
| 4943 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4944 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4945 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4946 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4947 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4948 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4949 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4950 | if (Arg.isInvalid()) |
| 4951 | return SemaRef.ExprError(); |
| 4952 | |
| 4953 | // FIXME: Poor source location information. |
| 4954 | SourceLocation FakeCommaLoc |
| 4955 | = SemaRef.PP.getLocForEndOfToken( |
| 4956 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4957 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4958 | Args.push_back(Arg.release()); |
| 4959 | } |
| 4960 | |
| 4961 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4962 | move_arg(Args), |
| 4963 | FakeCommaLocs.data(), |
| 4964 | E->getLocEnd()); |
| 4965 | } |
| 4966 | |
| 4967 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4968 | case OO_##Name: |
| 4969 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4970 | #include "clang/Basic/OperatorKinds.def" |
| 4971 | case OO_Subscript: |
| 4972 | // Handled below. |
| 4973 | break; |
| 4974 | |
| 4975 | case OO_Conditional: |
| 4976 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4977 | return SemaRef.ExprError(); |
| 4978 | |
| 4979 | case OO_None: |
| 4980 | case NUM_OVERLOADED_OPERATORS: |
| 4981 | llvm_unreachable("not an overloaded operator?"); |
| 4982 | return SemaRef.ExprError(); |
| 4983 | } |
| 4984 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4985 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4986 | if (Callee.isInvalid()) |
| 4987 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4989 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4990 | if (First.isInvalid()) |
| 4991 | return SemaRef.ExprError(); |
| 4992 | |
| 4993 | OwningExprResult Second(SemaRef); |
| 4994 | if (E->getNumArgs() == 2) { |
| 4995 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4996 | if (Second.isInvalid()) |
| 4997 | return SemaRef.ExprError(); |
| 4998 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4999 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5000 | if (!getDerived().AlwaysRebuild() && |
| 5001 | Callee.get() == E->getCallee() && |
| 5002 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5003 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 5004 | return SemaRef.Owned(E->Retain()); |
| 5005 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5006 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 5007 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5008 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5009 | move(First), |
| 5010 | move(Second)); |
| 5011 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5012 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5013 | template<typename Derived> |
| 5014 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5015 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5016 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5019 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5020 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5021 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5022 | TypeSourceInfo *OldT; |
| 5023 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | { |
| 5025 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5026 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5027 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5028 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5029 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5030 | OldT = E->getTypeInfoAsWritten(); |
| 5031 | NewT = getDerived().TransformType(OldT); |
| 5032 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5033 | return SemaRef.ExprError(); |
| 5034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5036 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5037 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5038 | if (SubExpr.isInvalid()) |
| 5039 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5040 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5041 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5042 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5043 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5044 | return SemaRef.Owned(E->Retain()); |
| 5045 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5046 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5047 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5049 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 5050 | SourceLocation FakeRParenLoc |
| 5051 | = SemaRef.PP.getLocForEndOfToken( |
| 5052 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5053 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5054 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5055 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5056 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5057 | FakeRAngleLoc, |
| 5058 | FakeRAngleLoc, |
| 5059 | move(SubExpr), |
| 5060 | FakeRParenLoc); |
| 5061 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5063 | template<typename Derived> |
| 5064 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5065 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5066 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5068 | |
| 5069 | template<typename Derived> |
| 5070 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5071 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5072 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | } |
| 5074 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | template<typename Derived> |
| 5076 | Sema::OwningExprResult |
| 5077 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5078 | CXXReinterpretCastExpr *E) { |
| 5079 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5081 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5082 | template<typename Derived> |
| 5083 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5084 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5085 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | template<typename Derived> |
| 5089 | Sema::OwningExprResult |
| 5090 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5091 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5092 | TypeSourceInfo *OldT; |
| 5093 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5094 | { |
| 5095 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5096 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5097 | OldT = E->getTypeInfoAsWritten(); |
| 5098 | NewT = getDerived().TransformType(OldT); |
| 5099 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | return SemaRef.ExprError(); |
| 5101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5102 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5103 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5104 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5105 | if (SubExpr.isInvalid()) |
| 5106 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5107 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5108 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5109 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5110 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | return SemaRef.Owned(E->Retain()); |
| 5112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5113 | // FIXME: The end of the type's source range is wrong |
| 5114 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5115 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5116 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5117 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5118 | move(SubExpr), |
| 5119 | E->getRParenLoc()); |
| 5120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5122 | template<typename Derived> |
| 5123 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5124 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5125 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5126 | TypeSourceInfo *TInfo |
| 5127 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5128 | if (!TInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5129 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5131 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5132 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5133 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5135 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5136 | E->getLocStart(), |
| 5137 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5138 | E->getLocEnd()); |
| 5139 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5140 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5141 | // We don't know whether the expression is potentially evaluated until |
| 5142 | // after we perform semantic analysis, so the expression is potentially |
| 5143 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5144 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5146 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5147 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5148 | if (SubExpr.isInvalid()) |
| 5149 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5151 | if (!getDerived().AlwaysRebuild() && |
| 5152 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | return SemaRef.Owned(E->Retain()); |
| 5154 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5155 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5156 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5157 | move(SubExpr), |
| 5158 | E->getLocEnd()); |
| 5159 | } |
| 5160 | |
| 5161 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5162 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5163 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5164 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5165 | } |
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 | template<typename Derived> |
| 5168 | Sema::OwningExprResult |
| 5169 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5170 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5174 | template<typename Derived> |
| 5175 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5176 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5178 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5179 | QualType T = getDerived().TransformType(E->getType()); |
| 5180 | if (T.isNull()) |
| 5181 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5183 | if (!getDerived().AlwaysRebuild() && |
| 5184 | T == E->getType()) |
| 5185 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5187 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5190 | template<typename Derived> |
| 5191 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5192 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5193 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5194 | if (SubExpr.isInvalid()) |
| 5195 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5196 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5197 | if (!getDerived().AlwaysRebuild() && |
| 5198 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5200 | |
| 5201 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | template<typename Derived> |
| 5205 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5206 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5207 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5208 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5209 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | if (!Param) |
| 5211 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5213 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5214 | Param == E->getParam()) |
| 5215 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5216 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5217 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5219 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5220 | template<typename Derived> |
| 5221 | Sema::OwningExprResult |
Douglas Gregor | 016a4a9 | 2010-07-07 22:43:56 +0000 | [diff] [blame^] | 5222 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5224 | |
| 5225 | QualType T = getDerived().TransformType(E->getType()); |
| 5226 | if (T.isNull()) |
| 5227 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | if (!getDerived().AlwaysRebuild() && |
| 5230 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | return SemaRef.Owned(E->Retain()); |
| 5232 | |
Douglas Gregor | 016a4a9 | 2010-07-07 22:43:56 +0000 | [diff] [blame^] | 5233 | return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(), |
| 5234 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5235 | T, |
| 5236 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5237 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5239 | template<typename Derived> |
| 5240 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5241 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5242 | // Transform the type that we're allocating |
| 5243 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5244 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5245 | if (AllocType.isNull()) |
| 5246 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5247 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5248 | // Transform the size of the array we're allocating (if any). |
| 5249 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5250 | if (ArraySize.isInvalid()) |
| 5251 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5253 | // Transform the placement arguments (if any). |
| 5254 | bool ArgumentChanged = false; |
| 5255 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5256 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5257 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5258 | if (Arg.isInvalid()) |
| 5259 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5261 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5262 | PlacementArgs.push_back(Arg.take()); |
| 5263 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5265 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5266 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5267 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
Douglas Gregor | ff2e4f4 | 2010-05-26 07:10:06 +0000 | [diff] [blame] | 5268 | if (getDerived().DropCallArgument(E->getConstructorArg(I))) |
| 5269 | break; |
| 5270 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5271 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5272 | if (Arg.isInvalid()) |
| 5273 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5274 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5275 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5276 | ConstructorArgs.push_back(Arg.take()); |
| 5277 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5279 | // Transform constructor, new operator, and delete operator. |
| 5280 | CXXConstructorDecl *Constructor = 0; |
| 5281 | if (E->getConstructor()) { |
| 5282 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5283 | getDerived().TransformDecl(E->getLocStart(), |
| 5284 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5285 | if (!Constructor) |
| 5286 | return SemaRef.ExprError(); |
| 5287 | } |
| 5288 | |
| 5289 | FunctionDecl *OperatorNew = 0; |
| 5290 | if (E->getOperatorNew()) { |
| 5291 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5292 | getDerived().TransformDecl(E->getLocStart(), |
| 5293 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5294 | if (!OperatorNew) |
| 5295 | return SemaRef.ExprError(); |
| 5296 | } |
| 5297 | |
| 5298 | FunctionDecl *OperatorDelete = 0; |
| 5299 | if (E->getOperatorDelete()) { |
| 5300 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5301 | getDerived().TransformDecl(E->getLocStart(), |
| 5302 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5303 | if (!OperatorDelete) |
| 5304 | return SemaRef.ExprError(); |
| 5305 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5306 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5307 | if (!getDerived().AlwaysRebuild() && |
| 5308 | AllocType == E->getAllocatedType() && |
| 5309 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5310 | Constructor == E->getConstructor() && |
| 5311 | OperatorNew == E->getOperatorNew() && |
| 5312 | OperatorDelete == E->getOperatorDelete() && |
| 5313 | !ArgumentChanged) { |
| 5314 | // Mark any declarations we need as referenced. |
| 5315 | // FIXME: instantiation-specific. |
| 5316 | if (Constructor) |
| 5317 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5318 | if (OperatorNew) |
| 5319 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5320 | if (OperatorDelete) |
| 5321 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5322 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5324 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5325 | if (!ArraySize.get()) { |
| 5326 | // If no array size was specified, but the new expression was |
| 5327 | // instantiated with an array type (e.g., "new T" where T is |
| 5328 | // instantiated with "int[4]"), extract the outer bound from the |
| 5329 | // array type as our array size. We do this with constant and |
| 5330 | // dependently-sized array types. |
| 5331 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5332 | if (!ArrayT) { |
| 5333 | // Do nothing |
| 5334 | } else if (const ConstantArrayType *ConsArrayT |
| 5335 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5336 | ArraySize |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5337 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5338 | ConsArrayT->getSize(), |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5339 | SemaRef.Context.getSizeType(), |
| 5340 | /*FIXME:*/E->getLocStart())); |
| 5341 | AllocType = ConsArrayT->getElementType(); |
| 5342 | } else if (const DependentSizedArrayType *DepArrayT |
| 5343 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5344 | if (DepArrayT->getSizeExpr()) { |
| 5345 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5346 | AllocType = DepArrayT->getElementType(); |
| 5347 | } |
| 5348 | } |
| 5349 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5350 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5351 | E->isGlobalNew(), |
| 5352 | /*FIXME:*/E->getLocStart(), |
| 5353 | move_arg(PlacementArgs), |
| 5354 | /*FIXME:*/E->getLocStart(), |
| 5355 | E->isParenTypeId(), |
| 5356 | AllocType, |
| 5357 | /*FIXME:*/E->getLocStart(), |
| 5358 | /*FIXME:*/SourceRange(), |
| 5359 | move(ArraySize), |
| 5360 | /*FIXME:*/E->getLocStart(), |
| 5361 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5362 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5363 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5365 | template<typename Derived> |
| 5366 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5367 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5368 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5369 | if (Operand.isInvalid()) |
| 5370 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5371 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5372 | // Transform the delete operator, if known. |
| 5373 | FunctionDecl *OperatorDelete = 0; |
| 5374 | if (E->getOperatorDelete()) { |
| 5375 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5376 | getDerived().TransformDecl(E->getLocStart(), |
| 5377 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5378 | if (!OperatorDelete) |
| 5379 | return SemaRef.ExprError(); |
| 5380 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5382 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5383 | Operand.get() == E->getArgument() && |
| 5384 | OperatorDelete == E->getOperatorDelete()) { |
| 5385 | // Mark any declarations we need as referenced. |
| 5386 | // FIXME: instantiation-specific. |
| 5387 | if (OperatorDelete) |
| 5388 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5389 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5392 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5393 | E->isGlobalDelete(), |
| 5394 | E->isArrayForm(), |
| 5395 | move(Operand)); |
| 5396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5397 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5398 | template<typename Derived> |
| 5399 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5400 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5401 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5402 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5403 | if (Base.isInvalid()) |
| 5404 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5406 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5407 | bool MayBePseudoDestructor = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5408 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5409 | E->getOperatorLoc(), |
| 5410 | E->isArrow()? tok::arrow : tok::period, |
| 5411 | ObjectTypePtr, |
| 5412 | MayBePseudoDestructor); |
| 5413 | if (Base.isInvalid()) |
| 5414 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5415 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5416 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5417 | NestedNameSpecifier *Qualifier |
| 5418 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5419 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5420 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5421 | if (E->getQualifier() && !Qualifier) |
| 5422 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5424 | PseudoDestructorTypeStorage Destroyed; |
| 5425 | if (E->getDestroyedTypeInfo()) { |
| 5426 | TypeSourceInfo *DestroyedTypeInfo |
| 5427 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5428 | if (!DestroyedTypeInfo) |
| 5429 | return SemaRef.ExprError(); |
| 5430 | Destroyed = DestroyedTypeInfo; |
| 5431 | } else if (ObjectType->isDependentType()) { |
| 5432 | // We aren't likely to be able to resolve the identifier down to a type |
| 5433 | // now anyway, so just retain the identifier. |
| 5434 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5435 | E->getDestroyedTypeLoc()); |
| 5436 | } else { |
| 5437 | // Look for a destructor known with the given name. |
| 5438 | CXXScopeSpec SS; |
| 5439 | if (Qualifier) { |
| 5440 | SS.setScopeRep(Qualifier); |
| 5441 | SS.setRange(E->getQualifierRange()); |
| 5442 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5443 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5444 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5445 | *E->getDestroyedTypeIdentifier(), |
| 5446 | E->getDestroyedTypeLoc(), |
| 5447 | /*Scope=*/0, |
| 5448 | SS, ObjectTypePtr, |
| 5449 | false); |
| 5450 | if (!T) |
| 5451 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5452 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5453 | Destroyed |
| 5454 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5455 | E->getDestroyedTypeLoc()); |
| 5456 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5457 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5458 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5459 | if (E->getScopeTypeInfo()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5460 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5461 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5462 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5463 | return SemaRef.ExprError(); |
| 5464 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5466 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5467 | E->getOperatorLoc(), |
| 5468 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5469 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5470 | E->getQualifierRange(), |
| 5471 | ScopeTypeInfo, |
| 5472 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5473 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5474 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5475 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5477 | template<typename Derived> |
| 5478 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5479 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5480 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5481 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5482 | |
| 5483 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5484 | Sema::LookupOrdinaryName); |
| 5485 | |
| 5486 | // Transform all the decls. |
| 5487 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5488 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5489 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5490 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5491 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5492 | if (!InstD) { |
| 5493 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5494 | // This can happen because of dependent hiding. |
| 5495 | if (isa<UsingShadowDecl>(*I)) |
| 5496 | continue; |
| 5497 | else |
| 5498 | return SemaRef.ExprError(); |
| 5499 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5500 | |
| 5501 | // Expand using declarations. |
| 5502 | if (isa<UsingDecl>(InstD)) { |
| 5503 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5504 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5505 | E = UD->shadow_end(); I != E; ++I) |
| 5506 | R.addDecl(*I); |
| 5507 | continue; |
| 5508 | } |
| 5509 | |
| 5510 | R.addDecl(InstD); |
| 5511 | } |
| 5512 | |
| 5513 | // Resolve a kind, but don't do any further analysis. If it's |
| 5514 | // ambiguous, the callee needs to deal with it. |
| 5515 | R.resolveKind(); |
| 5516 | |
| 5517 | // Rebuild the nested-name qualifier, if present. |
| 5518 | CXXScopeSpec SS; |
| 5519 | NestedNameSpecifier *Qualifier = 0; |
| 5520 | if (Old->getQualifier()) { |
| 5521 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5522 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5523 | if (!Qualifier) |
| 5524 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5525 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5526 | SS.setScopeRep(Qualifier); |
| 5527 | SS.setRange(Old->getQualifierRange()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5528 | } |
| 5529 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5530 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5531 | CXXRecordDecl *NamingClass |
| 5532 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5533 | Old->getNameLoc(), |
| 5534 | Old->getNamingClass())); |
| 5535 | if (!NamingClass) |
| 5536 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5537 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5538 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | // If we have no template arguments, it's a normal declaration name. |
| 5542 | if (!Old->hasExplicitTemplateArgs()) |
| 5543 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5544 | |
| 5545 | // If we have template arguments, rebuild them, then rebuild the |
| 5546 | // templateid expression. |
| 5547 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5548 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5549 | TemplateArgumentLoc Loc; |
| 5550 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5551 | return SemaRef.ExprError(); |
| 5552 | TransArgs.addArgument(Loc); |
| 5553 | } |
| 5554 | |
| 5555 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5556 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5558 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5559 | template<typename Derived> |
| 5560 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5561 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5562 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5563 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5564 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5565 | if (T.isNull()) |
| 5566 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | if (!getDerived().AlwaysRebuild() && |
| 5569 | T == E->getQueriedType()) |
| 5570 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5572 | // FIXME: Bad location information |
| 5573 | SourceLocation FakeLParenLoc |
| 5574 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5575 | |
| 5576 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5577 | E->getLocStart(), |
| 5578 | /*FIXME:*/FakeLParenLoc, |
| 5579 | T, |
| 5580 | E->getLocEnd()); |
| 5581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5583 | template<typename Derived> |
| 5584 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5585 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5586 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5587 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5588 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5589 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5590 | if (!NNS) |
| 5591 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5592 | |
| 5593 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5594 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5595 | if (!Name) |
| 5596 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5597 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5598 | if (!E->hasExplicitTemplateArgs()) { |
| 5599 | if (!getDerived().AlwaysRebuild() && |
| 5600 | NNS == E->getQualifier() && |
| 5601 | Name == E->getDeclName()) |
| 5602 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5604 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5605 | E->getQualifierRange(), |
| 5606 | Name, E->getLocation(), |
| 5607 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5608 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5609 | |
| 5610 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5611 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5612 | TemplateArgumentLoc Loc; |
| 5613 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5614 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5615 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5616 | } |
| 5617 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5618 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5619 | E->getQualifierRange(), |
| 5620 | Name, E->getLocation(), |
| 5621 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | template<typename Derived> |
| 5625 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5626 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5627 | // CXXConstructExprs are always implicit, so when we have a |
| 5628 | // 1-argument construction we just transform that argument. |
| 5629 | if (E->getNumArgs() == 1 || |
| 5630 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5631 | return getDerived().TransformExpr(E->getArg(0)); |
| 5632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5633 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5634 | |
| 5635 | QualType T = getDerived().TransformType(E->getType()); |
| 5636 | if (T.isNull()) |
| 5637 | return SemaRef.ExprError(); |
| 5638 | |
| 5639 | CXXConstructorDecl *Constructor |
| 5640 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5641 | getDerived().TransformDecl(E->getLocStart(), |
| 5642 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5643 | if (!Constructor) |
| 5644 | return SemaRef.ExprError(); |
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 | bool ArgumentChanged = false; |
| 5647 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5648 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5649 | ArgEnd = E->arg_end(); |
| 5650 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5651 | if (getDerived().DropCallArgument(*Arg)) { |
| 5652 | ArgumentChanged = true; |
| 5653 | break; |
| 5654 | } |
| 5655 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5657 | if (TransArg.isInvalid()) |
| 5658 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5660 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5661 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5662 | } |
| 5663 | |
| 5664 | if (!getDerived().AlwaysRebuild() && |
| 5665 | T == E->getType() && |
| 5666 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5667 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5668 | // Mark the constructor as referenced. |
| 5669 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5670 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5671 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5672 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5673 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5674 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5675 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5676 | move_arg(Args)); |
| 5677 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5679 | /// \brief Transform a C++ temporary-binding expression. |
| 5680 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5681 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5682 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5683 | template<typename Derived> |
| 5684 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5685 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5686 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5687 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5688 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5689 | /// \brief Transform a C++ reference-binding expression. |
| 5690 | /// |
| 5691 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5692 | /// transform the subexpression and return that. |
| 5693 | template<typename Derived> |
| 5694 | Sema::OwningExprResult |
| 5695 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5696 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5697 | } |
| 5698 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5699 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5700 | /// be destroyed after the expression is evaluated. |
| 5701 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5702 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5703 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5704 | template<typename Derived> |
| 5705 | Sema::OwningExprResult |
| 5706 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5707 | CXXExprWithTemporaries *E) { |
| 5708 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5710 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5711 | template<typename Derived> |
| 5712 | Sema::OwningExprResult |
| 5713 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5714 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5715 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5716 | QualType T = getDerived().TransformType(E->getType()); |
| 5717 | if (T.isNull()) |
| 5718 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5719 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5720 | CXXConstructorDecl *Constructor |
| 5721 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5722 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5723 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5724 | if (!Constructor) |
| 5725 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5726 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5727 | bool ArgumentChanged = false; |
| 5728 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5729 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5730 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5731 | ArgEnd = E->arg_end(); |
| 5732 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5733 | if (getDerived().DropCallArgument(*Arg)) { |
| 5734 | ArgumentChanged = true; |
| 5735 | break; |
| 5736 | } |
| 5737 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5738 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5739 | if (TransArg.isInvalid()) |
| 5740 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5742 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5743 | Args.push_back((Expr *)TransArg.release()); |
| 5744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5745 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5746 | if (!getDerived().AlwaysRebuild() && |
| 5747 | T == E->getType() && |
| 5748 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5749 | !ArgumentChanged) { |
| 5750 | // FIXME: Instantiation-specific |
| 5751 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5752 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5753 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5755 | // FIXME: Bogus location information |
| 5756 | SourceLocation CommaLoc; |
| 5757 | if (Args.size() > 1) { |
| 5758 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5759 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5760 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5761 | } |
| 5762 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5763 | T, |
| 5764 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5765 | move_arg(Args), |
| 5766 | &CommaLoc, |
| 5767 | E->getLocEnd()); |
| 5768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5769 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5770 | template<typename Derived> |
| 5771 | Sema::OwningExprResult |
| 5772 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5773 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5774 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5775 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5776 | if (T.isNull()) |
| 5777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5779 | bool ArgumentChanged = false; |
| 5780 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5781 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5782 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5783 | ArgEnd = E->arg_end(); |
| 5784 | Arg != ArgEnd; ++Arg) { |
| 5785 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5786 | if (TransArg.isInvalid()) |
| 5787 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5788 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5789 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5790 | FakeCommaLocs.push_back( |
| 5791 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5792 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5794 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5795 | if (!getDerived().AlwaysRebuild() && |
| 5796 | T == E->getTypeAsWritten() && |
| 5797 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5798 | return SemaRef.Owned(E->Retain()); |
| 5799 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5800 | // FIXME: we're faking the locations of the commas |
| 5801 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5802 | T, |
| 5803 | E->getLParenLoc(), |
| 5804 | move_arg(Args), |
| 5805 | FakeCommaLocs.data(), |
| 5806 | E->getRParenLoc()); |
| 5807 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5808 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5809 | template<typename Derived> |
| 5810 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5811 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5812 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5813 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5814 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5815 | Expr *OldBase; |
| 5816 | QualType BaseType; |
| 5817 | QualType ObjectType; |
| 5818 | if (!E->isImplicitAccess()) { |
| 5819 | OldBase = E->getBase(); |
| 5820 | Base = getDerived().TransformExpr(OldBase); |
| 5821 | if (Base.isInvalid()) |
| 5822 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5823 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5824 | // Start the member reference and compute the object's type. |
| 5825 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5826 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5827 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5828 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5829 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5830 | ObjectTy, |
| 5831 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5832 | if (Base.isInvalid()) |
| 5833 | return SemaRef.ExprError(); |
| 5834 | |
| 5835 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5836 | BaseType = ((Expr*) Base.get())->getType(); |
| 5837 | } else { |
| 5838 | OldBase = 0; |
| 5839 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5840 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5841 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5842 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5843 | // Transform the first part of the nested-name-specifier that qualifies |
| 5844 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5845 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5846 | = getDerived().TransformFirstQualifierInScope( |
| 5847 | E->getFirstQualifierFoundInScope(), |
| 5848 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5849 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5850 | NestedNameSpecifier *Qualifier = 0; |
| 5851 | if (E->getQualifier()) { |
| 5852 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5853 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5854 | ObjectType, |
| 5855 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5856 | if (!Qualifier) |
| 5857 | return SemaRef.ExprError(); |
| 5858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5859 | |
| 5860 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5861 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5862 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5863 | if (!Name) |
| 5864 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5865 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5866 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5867 | // This is a reference to a member without an explicitly-specified |
| 5868 | // template argument list. Optimize for this common case. |
| 5869 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5870 | Base.get() == OldBase && |
| 5871 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5872 | Qualifier == E->getQualifier() && |
| 5873 | Name == E->getMember() && |
| 5874 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5875 | return SemaRef.Owned(E->Retain()); |
| 5876 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5877 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5878 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5879 | E->isArrow(), |
| 5880 | E->getOperatorLoc(), |
| 5881 | Qualifier, |
| 5882 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5883 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5884 | Name, |
| 5885 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5886 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5889 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5890 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5891 | TemplateArgumentLoc Loc; |
| 5892 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5893 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5894 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5896 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5897 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5898 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5899 | E->isArrow(), |
| 5900 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5901 | Qualifier, |
| 5902 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5903 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5904 | Name, |
| 5905 | E->getMemberLoc(), |
| 5906 | &TransArgs); |
| 5907 | } |
| 5908 | |
| 5909 | template<typename Derived> |
| 5910 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5911 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5912 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5913 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5914 | QualType BaseType; |
| 5915 | if (!Old->isImplicitAccess()) { |
| 5916 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5917 | if (Base.isInvalid()) |
| 5918 | return SemaRef.ExprError(); |
| 5919 | BaseType = ((Expr*) Base.get())->getType(); |
| 5920 | } else { |
| 5921 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5922 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5923 | |
| 5924 | NestedNameSpecifier *Qualifier = 0; |
| 5925 | if (Old->getQualifier()) { |
| 5926 | Qualifier |
| 5927 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5928 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5929 | if (Qualifier == 0) |
| 5930 | return SemaRef.ExprError(); |
| 5931 | } |
| 5932 | |
| 5933 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5934 | Sema::LookupOrdinaryName); |
| 5935 | |
| 5936 | // Transform all the decls. |
| 5937 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5938 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5939 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5940 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5941 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5942 | if (!InstD) { |
| 5943 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5944 | // This can happen because of dependent hiding. |
| 5945 | if (isa<UsingShadowDecl>(*I)) |
| 5946 | continue; |
| 5947 | else |
| 5948 | return SemaRef.ExprError(); |
| 5949 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5950 | |
| 5951 | // Expand using declarations. |
| 5952 | if (isa<UsingDecl>(InstD)) { |
| 5953 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5954 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5955 | E = UD->shadow_end(); I != E; ++I) |
| 5956 | R.addDecl(*I); |
| 5957 | continue; |
| 5958 | } |
| 5959 | |
| 5960 | R.addDecl(InstD); |
| 5961 | } |
| 5962 | |
| 5963 | R.resolveKind(); |
| 5964 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5965 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 5966 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5967 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5968 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5969 | Old->getMemberLoc(), |
| 5970 | Old->getNamingClass())); |
| 5971 | if (!NamingClass) |
| 5972 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5973 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5974 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5975 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5976 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5977 | TemplateArgumentListInfo TransArgs; |
| 5978 | if (Old->hasExplicitTemplateArgs()) { |
| 5979 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5980 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5981 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5982 | TemplateArgumentLoc Loc; |
| 5983 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5984 | Loc)) |
| 5985 | return SemaRef.ExprError(); |
| 5986 | TransArgs.addArgument(Loc); |
| 5987 | } |
| 5988 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5989 | |
| 5990 | // FIXME: to do this check properly, we will need to preserve the |
| 5991 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5992 | // base (and therefore couldn't do the check) and a |
| 5993 | // nested-name-qualifier (and therefore could do the lookup). |
| 5994 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5995 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5996 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5997 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5998 | Old->getOperatorLoc(), |
| 5999 | Old->isArrow(), |
| 6000 | Qualifier, |
| 6001 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6002 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6003 | R, |
| 6004 | (Old->hasExplicitTemplateArgs() |
| 6005 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | template<typename Derived> |
| 6009 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6010 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6011 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6012 | } |
| 6013 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6014 | template<typename Derived> |
| 6015 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6016 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6017 | TypeSourceInfo *EncodedTypeInfo |
| 6018 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 6019 | if (!EncodedTypeInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6020 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6021 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6022 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6023 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6024 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6025 | |
| 6026 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6027 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6028 | E->getRParenLoc()); |
| 6029 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6030 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | template<typename Derived> |
| 6032 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6033 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6034 | // Transform arguments. |
| 6035 | bool ArgChanged = false; |
| 6036 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 6037 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 6038 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 6039 | if (Arg.isInvalid()) |
| 6040 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6041 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6042 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 6043 | Args.push_back(Arg.takeAs<Expr>()); |
| 6044 | } |
| 6045 | |
| 6046 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 6047 | // Class message: transform the receiver type. |
| 6048 | TypeSourceInfo *ReceiverTypeInfo |
| 6049 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 6050 | if (!ReceiverTypeInfo) |
| 6051 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6052 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6053 | // If nothing changed, just retain the existing message send. |
| 6054 | if (!getDerived().AlwaysRebuild() && |
| 6055 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 6056 | return SemaRef.Owned(E->Retain()); |
| 6057 | |
| 6058 | // Build a new class message send. |
| 6059 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 6060 | E->getSelector(), |
| 6061 | E->getMethodDecl(), |
| 6062 | E->getLeftLoc(), |
| 6063 | move_arg(Args), |
| 6064 | E->getRightLoc()); |
| 6065 | } |
| 6066 | |
| 6067 | // Instance message: transform the receiver |
| 6068 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 6069 | "Only class and instance messages may be instantiated"); |
| 6070 | OwningExprResult Receiver |
| 6071 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 6072 | if (Receiver.isInvalid()) |
| 6073 | return SemaRef.ExprError(); |
| 6074 | |
| 6075 | // If nothing changed, just retain the existing message send. |
| 6076 | if (!getDerived().AlwaysRebuild() && |
| 6077 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 6078 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6079 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6080 | // Build a new instance message send. |
| 6081 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 6082 | E->getSelector(), |
| 6083 | E->getMethodDecl(), |
| 6084 | E->getLeftLoc(), |
| 6085 | move_arg(Args), |
| 6086 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6089 | template<typename Derived> |
| 6090 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6091 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6092 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6093 | } |
| 6094 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6095 | template<typename Derived> |
| 6096 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6097 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6098 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6101 | template<typename Derived> |
| 6102 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6103 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6104 | // Transform the base expression. |
| 6105 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6106 | if (Base.isInvalid()) |
| 6107 | return SemaRef.ExprError(); |
| 6108 | |
| 6109 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6110 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6111 | // If nothing changed, just retain the existing expression. |
| 6112 | if (!getDerived().AlwaysRebuild() && |
| 6113 | Base.get() == E->getBase()) |
| 6114 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6115 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6116 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6117 | E->getLocation(), |
| 6118 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6119 | } |
| 6120 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6121 | template<typename Derived> |
| 6122 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6123 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6124 | // Transform the base expression. |
| 6125 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6126 | if (Base.isInvalid()) |
| 6127 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6128 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6129 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6130 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6131 | // If nothing changed, just retain the existing expression. |
| 6132 | if (!getDerived().AlwaysRebuild() && |
| 6133 | Base.get() == E->getBase()) |
| 6134 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6135 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6136 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6137 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6138 | } |
| 6139 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6140 | template<typename Derived> |
| 6141 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6142 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6143 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6144 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6145 | // dependent parts. Just retain the existing declaration. |
| 6146 | if (E->getInterfaceDecl()) |
| 6147 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6148 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6149 | // Transform the base expression. |
| 6150 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6151 | if (Base.isInvalid()) |
| 6152 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6153 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6154 | // 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] | 6155 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6156 | // If nothing changed, just retain the existing expression. |
| 6157 | if (!getDerived().AlwaysRebuild() && |
| 6158 | Base.get() == E->getBase()) |
| 6159 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6160 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6161 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6162 | E->getGetterMethod(), |
| 6163 | E->getType(), |
| 6164 | E->getSetterMethod(), |
| 6165 | E->getLocation(), |
| 6166 | move(Base)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6168 | } |
| 6169 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6170 | template<typename Derived> |
| 6171 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6172 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6173 | // Can never occur in a dependent context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6174 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6177 | template<typename Derived> |
| 6178 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6179 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6180 | // Transform the base expression. |
| 6181 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6182 | if (Base.isInvalid()) |
| 6183 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6184 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6185 | // If nothing changed, just retain the existing expression. |
| 6186 | if (!getDerived().AlwaysRebuild() && |
| 6187 | Base.get() == E->getBase()) |
| 6188 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6189 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6190 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6191 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6192 | } |
| 6193 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6194 | template<typename Derived> |
| 6195 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6196 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6197 | bool ArgumentChanged = false; |
| 6198 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6199 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6200 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6201 | if (SubExpr.isInvalid()) |
| 6202 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6204 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6205 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6206 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6207 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6208 | if (!getDerived().AlwaysRebuild() && |
| 6209 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6210 | return SemaRef.Owned(E->Retain()); |
| 6211 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6212 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6213 | move_arg(SubExprs), |
| 6214 | E->getRParenLoc()); |
| 6215 | } |
| 6216 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6217 | template<typename Derived> |
| 6218 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6219 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6220 | // FIXME: Implement this! |
| 6221 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6222 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6225 | template<typename Derived> |
| 6226 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6227 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6228 | // FIXME: Implement this! |
| 6229 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6230 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6231 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6232 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6233 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6234 | // Type reconstruction |
| 6235 | //===----------------------------------------------------------------------===// |
| 6236 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6238 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6239 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6240 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6241 | getDerived().getBaseEntity()); |
| 6242 | } |
| 6243 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6244 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6245 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6246 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6247 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6248 | getDerived().getBaseEntity()); |
| 6249 | } |
| 6250 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6251 | template<typename Derived> |
| 6252 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6253 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6254 | bool WrittenAsLValue, |
| 6255 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6256 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6257 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6261 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6262 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6263 | QualType ClassType, |
| 6264 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6265 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6266 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6270 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6271 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6272 | ArrayType::ArraySizeModifier SizeMod, |
| 6273 | const llvm::APInt *Size, |
| 6274 | Expr *SizeExpr, |
| 6275 | unsigned IndexTypeQuals, |
| 6276 | SourceRange BracketsRange) { |
| 6277 | if (SizeExpr || !Size) |
| 6278 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6279 | IndexTypeQuals, BracketsRange, |
| 6280 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | |
| 6282 | QualType Types[] = { |
| 6283 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6284 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6285 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6286 | }; |
| 6287 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6288 | QualType SizeType; |
| 6289 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6290 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6291 | SizeType = Types[I]; |
| 6292 | break; |
| 6293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6295 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6296 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6297 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6298 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6299 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6300 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6301 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6302 | QualType |
| 6303 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6304 | ArrayType::ArraySizeModifier SizeMod, |
| 6305 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6306 | unsigned IndexTypeQuals, |
| 6307 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6308 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6309 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6313 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6314 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6315 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6316 | unsigned IndexTypeQuals, |
| 6317 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6318 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6319 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6320 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6321 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6322 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6323 | QualType |
| 6324 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6325 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6326 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6327 | unsigned IndexTypeQuals, |
| 6328 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6329 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6330 | SizeExpr.takeAs<Expr>(), |
| 6331 | IndexTypeQuals, BracketsRange); |
| 6332 | } |
| 6333 | |
| 6334 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6335 | QualType |
| 6336 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6337 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6338 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6339 | unsigned IndexTypeQuals, |
| 6340 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6341 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6342 | SizeExpr.takeAs<Expr>(), |
| 6343 | IndexTypeQuals, BracketsRange); |
| 6344 | } |
| 6345 | |
| 6346 | template<typename Derived> |
| 6347 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6348 | unsigned NumElements, |
| 6349 | VectorType::AltiVecSpecific AltiVecSpec) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6350 | // FIXME: semantic checking! |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6351 | return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6352 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6353 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6354 | template<typename Derived> |
| 6355 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6356 | unsigned NumElements, |
| 6357 | SourceLocation AttributeLoc) { |
| 6358 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6359 | NumElements, true); |
| 6360 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6361 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6362 | AttributeLoc); |
| 6363 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6364 | AttributeLoc); |
| 6365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6366 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6367 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6368 | QualType |
| 6369 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6370 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6371 | SourceLocation AttributeLoc) { |
| 6372 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6374 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6375 | template<typename Derived> |
| 6376 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6377 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6378 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6379 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6380 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6381 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6382 | Quals, |
| 6383 | getDerived().getBaseLocation(), |
| 6384 | getDerived().getBaseEntity()); |
| 6385 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6386 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6387 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6388 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6389 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6390 | } |
| 6391 | |
| 6392 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6393 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6394 | assert(D && "no decl found"); |
| 6395 | if (D->isInvalidDecl()) return QualType(); |
| 6396 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6397 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6398 | TypeDecl *Ty; |
| 6399 | if (isa<UsingDecl>(D)) { |
| 6400 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6401 | assert(Using->isTypeName() && |
| 6402 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6403 | |
| 6404 | // A valid resolved using typename decl points to exactly one type decl. |
| 6405 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6406 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6407 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6408 | } else { |
| 6409 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6410 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6411 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6412 | } |
| 6413 | |
| 6414 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6415 | } |
| 6416 | |
| 6417 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6418 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6419 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6420 | } |
| 6421 | |
| 6422 | template<typename Derived> |
| 6423 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6424 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6425 | } |
| 6426 | |
| 6427 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6428 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6429 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6430 | } |
| 6431 | |
| 6432 | template<typename Derived> |
| 6433 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6434 | TemplateName Template, |
| 6435 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6436 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6437 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6438 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6439 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6440 | template<typename Derived> |
| 6441 | NestedNameSpecifier * |
| 6442 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6443 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6444 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6445 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6446 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6447 | CXXScopeSpec SS; |
| 6448 | // FIXME: The source location information is all wrong. |
| 6449 | SS.setRange(Range); |
| 6450 | SS.setScopeRep(Prefix); |
| 6451 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6452 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6453 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6454 | ObjectType, |
| 6455 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6456 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6457 | } |
| 6458 | |
| 6459 | template<typename Derived> |
| 6460 | NestedNameSpecifier * |
| 6461 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6462 | SourceRange Range, |
| 6463 | NamespaceDecl *NS) { |
| 6464 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6465 | } |
| 6466 | |
| 6467 | template<typename Derived> |
| 6468 | NestedNameSpecifier * |
| 6469 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6470 | SourceRange Range, |
| 6471 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6472 | QualType T) { |
| 6473 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6474 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6475 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6476 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6477 | T.getTypePtr()); |
| 6478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6479 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6480 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6481 | return 0; |
| 6482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6483 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6484 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6485 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6486 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6487 | bool TemplateKW, |
| 6488 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6489 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6490 | Template); |
| 6491 | } |
| 6492 | |
| 6493 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6494 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6495 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6496 | const IdentifierInfo &II, |
| 6497 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6498 | CXXScopeSpec SS; |
| 6499 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6500 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6501 | UnqualifiedId Name; |
| 6502 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6503 | Sema::TemplateTy Template; |
| 6504 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 6505 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6506 | SS, |
| 6507 | Name, |
| 6508 | ObjectType.getAsOpaquePtr(), |
| 6509 | /*EnteringContext=*/false, |
| 6510 | Template); |
| 6511 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6514 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6515 | TemplateName |
| 6516 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6517 | OverloadedOperatorKind Operator, |
| 6518 | QualType ObjectType) { |
| 6519 | CXXScopeSpec SS; |
| 6520 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6521 | SS.setScopeRep(Qualifier); |
| 6522 | UnqualifiedId Name; |
| 6523 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6524 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6525 | Operator, SymbolLocations); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6526 | Sema::TemplateTy Template; |
| 6527 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6528 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6529 | SS, |
| 6530 | Name, |
| 6531 | ObjectType.getAsOpaquePtr(), |
| 6532 | /*EnteringContext=*/false, |
| 6533 | Template); |
| 6534 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6535 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6536 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6537 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6538 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6539 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6540 | SourceLocation OpLoc, |
| 6541 | ExprArg Callee, |
| 6542 | ExprArg First, |
| 6543 | ExprArg Second) { |
| 6544 | Expr *FirstExpr = (Expr *)First.get(); |
| 6545 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6546 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6547 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6548 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6549 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6550 | if (Op == OO_Subscript) { |
| 6551 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6552 | !SecondExpr->getType()->isOverloadableType()) |
| 6553 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6554 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6555 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6556 | } else if (Op == OO_Arrow) { |
| 6557 | // -> is never a builtin operation. |
| 6558 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6559 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6560 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6561 | // The argument is not of overloadable type, so try to create a |
| 6562 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6563 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6564 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6565 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6566 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6567 | } |
| 6568 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6569 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6570 | !SecondExpr->getType()->isOverloadableType()) { |
| 6571 | // Neither of the arguments is an overloadable type, so try to |
| 6572 | // create a built-in binary operation. |
| 6573 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6574 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6575 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6576 | if (Result.isInvalid()) |
| 6577 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6578 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6579 | First.release(); |
| 6580 | Second.release(); |
| 6581 | return move(Result); |
| 6582 | } |
| 6583 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6584 | |
| 6585 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6586 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6587 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6588 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6589 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6590 | assert(ULE->requiresADL()); |
| 6591 | |
| 6592 | // FIXME: Do we have to check |
| 6593 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6594 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6595 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6596 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6598 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6599 | // Add any functions found via argument-dependent lookup. |
| 6600 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6601 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6602 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6603 | // Create the overloaded operator invocation for unary operators. |
| 6604 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6605 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6606 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6607 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6608 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6609 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6610 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6611 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6612 | OpLoc, |
| 6613 | move(First), |
| 6614 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6615 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6616 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6617 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6618 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6619 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6620 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6621 | if (Result.isInvalid()) |
| 6622 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6624 | First.release(); |
| 6625 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6626 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6628 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6629 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6630 | Sema::OwningExprResult |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6631 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6632 | SourceLocation OperatorLoc, |
| 6633 | bool isArrow, |
| 6634 | NestedNameSpecifier *Qualifier, |
| 6635 | SourceRange QualifierRange, |
| 6636 | TypeSourceInfo *ScopeType, |
| 6637 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6638 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6639 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6640 | CXXScopeSpec SS; |
| 6641 | if (Qualifier) { |
| 6642 | SS.setRange(QualifierRange); |
| 6643 | SS.setScopeRep(Qualifier); |
| 6644 | } |
| 6645 | |
| 6646 | Expr *BaseE = (Expr *)Base.get(); |
| 6647 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6648 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6649 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6650 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6651 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6652 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6653 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6654 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6655 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6656 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6657 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6658 | /*FIXME?*/true); |
| 6659 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6660 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6661 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6662 | DeclarationName Name |
| 6663 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6664 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6665 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6666 | // FIXME: the ScopeType should be tacked onto SS. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6667 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6668 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6669 | OperatorLoc, isArrow, |
| 6670 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6671 | Name, Destroyed.getLocation(), |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6672 | /*TemplateArgs*/ 0); |
| 6673 | } |
| 6674 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6675 | } // end namespace clang |
| 6676 | |
| 6677 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |